From c3967801bcd333d91e97411c68fe8b921df213c1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 11 Nov 2019 11:04:22 -0600 Subject: [PATCH] ceph-daemon: ls: add --no-detail Signed-off-by: Sage Weil --- src/ceph-daemon/ceph-daemon | 91 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/src/ceph-daemon/ceph-daemon b/src/ceph-daemon/ceph-daemon index 290bb9a19b9..f07f84e82d5 100755 --- a/src/ceph-daemon/ceph-daemon +++ b/src/ceph-daemon/ceph-daemon @@ -1301,10 +1301,10 @@ def command_unit(): ################################## def command_ls(): - ls = list_daemons() + ls = list_daemons(detail=not args.no_detail) print(json.dumps(ls, indent=4)) -def list_daemons(): +def list_daemons(detail=True): host_version = None ls = [] @@ -1319,65 +1319,64 @@ def list_daemons(): (cluster, daemon_id) = j.split('-', 1) fsid = get_legacy_daemon_fsid(cluster, daemon_type, daemon_id) or 'unknown' - (enabled, state) = check_unit('ceph-%s@%s' % (daemon_type, - daemon_id)) - if not host_version: - try: - out, err, code = call(['ceph', '-v']) - if not code and out.startswith('ceph version '): - host_version = out.split(' ')[2] - except Exception: - pass - - ls.append({ + i = { 'style': 'legacy', 'name': '%s.%s' % (daemon_type, daemon_id), 'fsid': fsid, - 'enabled': enabled, - 'state': state, - 'version': host_version, - }) + } + if detail: + (i['enabled'], i['state']) = check_unit( + 'ceph-%s@%s' % (daemon_type, daemon_id)) + if not host_version: + try: + out, err, code = call(['ceph', '-v']) + if not code and out.startswith('ceph version '): + host_version = out.split(' ')[2] + except Exception: + pass + i['host_version'] = host_version + ls.append(i) elif is_fsid(i): fsid = i for j in os.listdir(os.path.join(args.data_dir, i)): if j == 'crash': name = 'crash' unit_name = 'ceph-%s-crash.service' % fsid - (enabled, state) = check_unit(unit_name) elif '.' in j: name = j (daemon_type, daemon_id) = j.split('.', 1) - (enabled, state) = check_unit(get_unit_name(fsid, - daemon_type, - daemon_id)) + unit_name = get_unit_name(fsid, + daemon_type, + daemon_id) else: continue - - # get container id - container_id = None - version = None - out, err, code = call( - [ - podman_path, 'inspect', - '--format', '{{.Id}}', - 'ceph-%s-%s' % (fsid, j) - ], - verbose_on_failure=False) - if not code: - container_id = out.strip()[0:12] - out, err, code = call( - [podman_path, 'exec', container_id, 'ceph', '-v']) - if not code and out.startswith('ceph version '): - version = out.split(' ')[2] - ls.append({ + i = { 'style': 'ceph-daemon:v1', 'name': name, 'fsid': fsid, - 'enabled': enabled, - 'state': state, - 'container_id': container_id, - 'version': version, - }) + } + if detail: + # get container id + (i['enabled'], i['state']) = check_unit(unit_name) + container_id = None + version = None + out, err, code = call( + [ + podman_path, 'inspect', + '--format', '{{.Id}}', + 'ceph-%s-%s' % (fsid, j) + ], + verbose_on_failure=False) + if not code: + container_id = out.strip()[0:12] + out, err, code = call( + [podman_path, 'exec', container_id, + 'ceph', '-v']) + if not code and out.startswith('ceph version '): + version = out.split(' ')[2] + i['container_id'] = container_id + i['version'] = version + ls.append(i) # /var/lib/rook # WRITE ME @@ -1557,6 +1556,10 @@ def _get_parser(): parser_ls = subparsers.add_parser( 'ls', help='list daemon instances on this host') + parser_ls.add_argument( + '--no-detail', + action='store_true', + help='Do not include daemon status') parser_ls.set_defaults(func=command_ls) parser_adopt = subparsers.add_parser( -- 2.39.5