From f9c280ce593fdde2914a93262fb3d9bc525f7947 Mon Sep 17 00:00:00 2001 From: Adam King Date: Mon, 11 Mar 2024 14:44:17 -0400 Subject: [PATCH] cephadm: allow list_daemons for only a specific daemon At the moment, my thoughts are to use this internally in the binary for when we need infor from list_daemons but only for a specific daemon. I could also see wanting this just on the command line to get info on a certain daemon, so I've added it as a flag for `cephadm ls` as well Signed-off-by: Adam King --- src/cephadm/cephadm.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 21523cd09ea..b3ff564ec2f 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -3378,12 +3378,17 @@ def command_list_networks(ctx): def command_ls(ctx): # type: (CephadmContext) -> None ls = list_daemons(ctx, detail=not ctx.no_detail, - legacy_dir=ctx.legacy_dir) + legacy_dir=ctx.legacy_dir, + daemon_name=ctx.name) print(json.dumps(ls, indent=4)) -def list_daemons(ctx, detail=True, legacy_dir=None): - # type: (CephadmContext, bool, Optional[str]) -> List[Dict[str, str]] +def list_daemons( + ctx: CephadmContext, + detail: bool = True, + legacy_dir: Optional[str] = None, + daemon_name: Optional[str] = None, +) -> List[Dict[str, str]]: host_version: Optional[str] = None ls = [] container_path = ctx.container_engine.path @@ -3452,6 +3457,8 @@ def list_daemons(ctx, detail=True, legacy_dir=None): 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)): name = j + if daemon_name and name != daemon_name: + continue (daemon_type, daemon_id) = j.split('.', 1) unit_name = get_unit_name(fsid, daemon_type, @@ -4880,6 +4887,9 @@ def _get_parser(): '--legacy-dir', default='/', help='base directory for legacy daemon data') + parser_ls.add_argument( + '--name', '-n', + help='Only get data for specific daemon. Format of daemon name: (type.id)') parser_list_networks = subparsers.add_parser( 'list-networks', help='list IP networks') -- 2.39.5