From: John Mulligan Date: Fri, 4 Oct 2024 18:09:53 +0000 (-0400) Subject: cephadm: apply black formatting to the list_daemons function X-Git-Tag: v20.3.0~256^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=63a1dacbcd4da2d095ce00609346096752c2671a;p=ceph.git cephadm: apply black formatting to the list_daemons function Run the `black` formatting tool over the body of the list_daemons function. Black formatting is more standard and often easier to read. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 91d4c9a4cad..de0da4d9021 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -3415,7 +3415,7 @@ def list_daemons( seen_versions = {} # type: Dict[str, Optional[str]] # keep track of image digests - seen_digests = {} # type: Dict[str, List[str]] + seen_digests = {} # type: Dict[str, List[str]] # keep track of memory and cpu usage we've seen seen_memusage_cid_len, seen_memusage = parsed_container_mem_usage(ctx) @@ -3435,9 +3435,13 @@ def list_daemons( if '-' not in j: continue (cluster, daemon_id) = j.split('-', 1) - fsid = get_legacy_daemon_fsid(ctx, - cluster, daemon_type, daemon_id, - legacy_dir=legacy_dir) + fsid = get_legacy_daemon_fsid( + ctx, + cluster, + daemon_type, + daemon_id, + legacy_dir=legacy_dir, + ) legacy_unit_name = 'ceph-%s@%s' % (daemon_type, daemon_id) val: Dict[str, Any] = { 'style': 'legacy', @@ -3446,12 +3450,16 @@ def list_daemons( 'systemd_unit': legacy_unit_name, } if detail: - (val['enabled'], val['state'], _) = check_unit(ctx, legacy_unit_name) + (val['enabled'], val['state'], _) = check_unit( + ctx, legacy_unit_name + ) if not host_version: try: - out, err, code = call(ctx, - ['ceph', '-v'], - verbosity=CallVerbosity.QUIET) + out, err, code = call( + ctx, + ['ceph', '-v'], + verbosity=CallVerbosity.QUIET, + ) if not code and out.startswith('ceph version '): host_version = out.split(' ')[2] except Exception: @@ -3461,16 +3469,16 @@ def list_daemons( elif is_fsid(i): fsid = str(i) # convince mypy that fsid is a str here for j in os.listdir(os.path.join(data_dir, i)): - if '.' in j and os.path.isdir(os.path.join(data_dir, fsid, j)): + if '.' in j and os.path.isdir( + os.path.join(data_dir, fsid, j) + ): name = j if daemon_name and name != daemon_name: continue (daemon_type, daemon_id) = j.split('.', 1) if type_of_daemon and type_of_daemon != daemon_type: continue - unit_name = get_unit_name(fsid, - daemon_type, - daemon_id) + unit_name = get_unit_name(fsid, daemon_type, daemon_id) else: continue val = { @@ -3481,7 +3489,9 @@ def list_daemons( } if detail: # get container id - (val['enabled'], val['state'], _) = check_unit(ctx, unit_name) + (val['enabled'], val['state'], _) = check_unit( + ctx, unit_name + ) container_id = None image_name = None image_id = None @@ -3492,7 +3502,7 @@ def list_daemons( cinfo = get_container_stats( ctx, DaemonIdentity(fsid, daemon_type, daemon_id), - container_path=container_path + container_path=container_path, ) if cinfo: container_id = cinfo.container_id @@ -3510,70 +3520,118 @@ def list_daemons( out, err, code = call( ctx, [ - container_path, 'image', 'inspect', image_id, - '--format', '{{.RepoDigests}}', + container_path, + 'image', + 'inspect', + image_id, + '--format', + '{{.RepoDigests}}', ], - verbosity=CallVerbosity.QUIET) + verbosity=CallVerbosity.QUIET, + ) if not code: - image_digests = list(set(map( - normalize_image_digest, - out.strip()[1:-1].split(' ')))) + image_digests = list( + set( + map( + normalize_image_digest, + out.strip()[1:-1].split(' '), + ) + ) + ) seen_digests[image_id] = image_digests # identify software version inside the container (if we can) if not version or '.' not in version: version = seen_versions.get(image_id, None) if daemon_type == NFSGanesha.daemon_type: - version = NFSGanesha.get_version(ctx, container_id) + version = NFSGanesha.get_version( + ctx, container_id + ) if daemon_type == CephIscsi.daemon_type: version = CephIscsi.get_version(ctx, container_id) if daemon_type == CephNvmeof.daemon_type: - version = CephNvmeof.get_version(ctx, container_id) + version = CephNvmeof.get_version( + ctx, container_id + ) if daemon_type == SMB.daemon_type: version = SMB.get_version(ctx, container_id) elif not version: if daemon_type in ceph_daemons(): - out, err, code = call(ctx, - [container_path, 'exec', container_id, - 'ceph', '-v'], - verbosity=CallVerbosity.QUIET) - if not code and \ - out.startswith('ceph version '): + out, err, code = call( + ctx, + [ + container_path, + 'exec', + container_id, + 'ceph', + '-v', + ], + verbosity=CallVerbosity.QUIET, + ) + if not code and out.startswith( + 'ceph version ' + ): version = out.split(' ')[2] seen_versions[image_id] = version elif daemon_type == 'grafana': - out, err, code = call(ctx, - [container_path, 'exec', container_id, - 'grafana', 'server', '-v'], - verbosity=CallVerbosity.QUIET) - if not code and \ - out.startswith('Version '): + out, err, code = call( + ctx, + [ + container_path, + 'exec', + container_id, + 'grafana', + 'server', + '-v', + ], + verbosity=CallVerbosity.QUIET, + ) + if not code and out.startswith('Version '): version = out.split(' ')[1] seen_versions[image_id] = version - elif daemon_type in ['prometheus', - 'alertmanager', - 'node-exporter', - 'loki', - 'promtail']: - version = Monitoring.get_version(ctx, container_id, daemon_type) + elif daemon_type in [ + 'prometheus', + 'alertmanager', + 'node-exporter', + 'loki', + 'promtail', + ]: + version = Monitoring.get_version( + ctx, container_id, daemon_type + ) seen_versions[image_id] = version elif daemon_type == 'haproxy': - out, err, code = call(ctx, - [container_path, 'exec', container_id, - 'haproxy', '-v'], - verbosity=CallVerbosity.QUIET) - if not code and \ - out.startswith('HA-Proxy version ') or \ - out.startswith('HAProxy version '): + out, err, code = call( + ctx, + [ + container_path, + 'exec', + container_id, + 'haproxy', + '-v', + ], + verbosity=CallVerbosity.QUIET, + ) + if ( + not code + and out.startswith('HA-Proxy version ') + or out.startswith('HAProxy version ') + ): version = out.split(' ')[2] seen_versions[image_id] = version elif daemon_type == 'keepalived': - out, err, code = call(ctx, - [container_path, 'exec', container_id, - 'keepalived', '--version'], - verbosity=CallVerbosity.QUIET) - if not code and \ - err.startswith('Keepalived '): + out, err, code = call( + ctx, + [ + container_path, + 'exec', + container_id, + 'keepalived', + '--version', + ], + verbosity=CallVerbosity.QUIET, + ) + if not code and err.startswith('Keepalived '): version = err.split(' ')[1] if version[0] == 'v': version = version[1:] @@ -3584,16 +3642,25 @@ def list_daemons( # to execute to get the version. pass elif daemon_type == SNMPGateway.daemon_type: - version = SNMPGateway.get_version(ctx, fsid, daemon_id) + version = SNMPGateway.get_version( + ctx, fsid, daemon_id + ) seen_versions[image_id] = version elif daemon_type == MgmtGateway.daemon_type: - version = MgmtGateway.get_version(ctx, container_id) + version = MgmtGateway.get_version( + ctx, container_id + ) seen_versions[image_id] = version elif daemon_type == OAuth2Proxy.daemon_type: - version = OAuth2Proxy.get_version(ctx, container_id) + version = OAuth2Proxy.get_version( + ctx, container_id + ) seen_versions[image_id] = version else: - logger.warning('version for unknown daemon type %s' % daemon_type) + logger.warning( + 'version for unknown daemon type %s' + % daemon_type + ) else: vfile = os.path.join(data_dir, fsid, j, 'unit.image') # type: ignore try: @@ -3616,17 +3683,23 @@ def list_daemons( val['container_image_id'] = image_id val['container_image_digests'] = image_digests if container_id: - val['memory_usage'] = seen_memusage.get(container_id[0:seen_memusage_cid_len]) - val['cpu_percentage'] = seen_cpuperc.get(container_id[0:seen_cpuperc_cid_len]) + val['memory_usage'] = seen_memusage.get( + container_id[0:seen_memusage_cid_len] + ) + val['cpu_percentage'] = seen_cpuperc.get( + container_id[0:seen_cpuperc_cid_len] + ) val['version'] = version val['started'] = start_stamp val['created'] = get_file_timestamp( os.path.join(data_dir, fsid, j, 'unit.created') ) val['deployed'] = get_file_timestamp( - os.path.join(data_dir, fsid, j, 'unit.image')) + os.path.join(data_dir, fsid, j, 'unit.image') + ) val['configured'] = get_file_timestamp( - os.path.join(data_dir, fsid, j, 'unit.configured')) + os.path.join(data_dir, fsid, j, 'unit.configured') + ) ls.append(val) return ls