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)
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',
'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:
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 = {
}
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
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
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:]
# 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:
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