From c1346f90753ae663e4a00c1f67b9a14e25a44778 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Wed, 20 Dec 2023 20:12:45 -0500 Subject: [PATCH] orchestrator: Add summary line to orch device ls This patch just adds a summary line to the plain text output of orch device ls when the --summary switch is given. This helps to quickly understand your device countswhen managing hosts with many devices. Fixes: https://tracker.ceph.com/issues/63864 Signed-off-by: Paul Cuzner (cherry picked from commit 50a4cd3a18ce510f25908531d6228e7447f5e72c) --- src/pybind/mgr/orchestrator/module.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 054cd58f8b0d8..83f1ef8aeec75 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -793,7 +793,8 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, hostname: Optional[List[str]] = None, format: Format = Format.plain, refresh: bool = False, - wide: bool = False) -> HandleCommandResult: + wide: bool = False, + summary: bool = False) -> HandleCommandResult: """ List devices on a host """ @@ -840,9 +841,23 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, table.left_padding_width = 0 table.right_padding_width = 2 now = datetime_now() + host_count = 0 + available_count = 0 + device_count = { + "hdd": 0, + "ssd": 0} + for host_ in natsorted(inv_hosts, key=lambda h: h.name): # type: InventoryHost + host_count += 1 for d in sorted(host_.devices.devices, key=lambda d: d.path): # type: Device + if d.available: + available_count += 1 + try: + device_count[d.human_readable_type] += 1 + except KeyError: + device_count[d.human_readable_type] = 1 + led_ident = 'N/A' led_fail = 'N/A' if d.lsm_data.get('ledSupport', None): @@ -881,6 +896,11 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, ) ) out.append(table.get_string()) + + if summary: + device_summary = [f"{device_count[devtype]} {devtype.upper()}" for devtype in sorted(device_count.keys())] + out.append(f"{host_count} host(s), {', '.join(device_summary)}, {available_count} available") + return HandleCommandResult(stdout='\n'.join(out)) @_cli_write_command('orch device zap') -- 2.39.5