]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
orchestrator: Add summary line to orch device ls 56098/head
authorPaul Cuzner <pcuzner@ibm.com>
Thu, 21 Dec 2023 01:12:45 +0000 (20:12 -0500)
committerAdam King <adking@redhat.com>
Sun, 10 Mar 2024 20:13:47 +0000 (16:13 -0400)
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 <pcuzner@ibm.com>
(cherry picked from commit 50a4cd3a18ce510f25908531d6228e7447f5e72c)

src/pybind/mgr/orchestrator/module.py

index 054cd58f8b0d86a743bc0ff7f7aa00d789aec53c..83f1ef8aeec759d35bf5a82adaa995f0335e923c 100644 (file)
@@ -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')