]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: add string representation for Device and DeviceSelection classes
authorAdam King <adking@redhat.com>
Thu, 18 Nov 2021 18:44:02 +0000 (13:44 -0500)
committerSebastian Wagner <sewagner@redhat.com>
Mon, 3 Jan 2022 14:00:09 +0000 (15:00 +0100)
Signed-off-by: Adam King <adking@redhat.com>
(cherry picked from commit 5b60b8e75889208a0c43e6cf7e9a6abcd849bd9f)

src/python-common/ceph/deployment/drive_selection/selector.py
src/python-common/ceph/deployment/inventory.py

index a54df3268a823cbd0076a0390028427d2d0acdee..70ff65144789315d7905a8abdb366aa18996a249 100644 (file)
@@ -1,7 +1,7 @@
 import logging
 
 try:
-    from typing import List, Optional
+    from typing import List, Optional, Dict
 except ImportError:
     pass
 
@@ -149,3 +149,14 @@ class DriveSelection(object):
                 self.disks.remove(taken_device)
 
         return sorted([x for x in devices], key=lambda dev: dev.path)
+
+    def __repr__(self) -> str:
+        selection: Dict[str, List[str]] = {
+            'data devices': [d.path for d in self._data],
+            'wal_devices': [d.path for d in self._wal],
+            'db devices': [d.path for d in self._db],
+            'journal devices': [d.path for d in self._journal]
+        }
+        return "DeviceSelection({})".format(
+            ', '.join('{}={}'.format(key, selection[key]) for key in selection.keys())
+        )
index cfa20189400ef4e50a20f95746ffd92ad85559f4..d0a885668c090c15d94ae7fe30d7d88e3984cbd2 100644 (file)
@@ -1,5 +1,5 @@
 try:
-    from typing import List, Optional, Dict, Any
+    from typing import List, Optional, Dict, Any, Union
 except ImportError:
     pass  # for type checking
 
@@ -89,3 +89,15 @@ class Device(object):
         if self.sys_api is None or 'rotational' not in self.sys_api:
             return "unknown"
         return 'hdd' if self.sys_api["rotational"] == "1" else 'ssd'
+
+    def __repr__(self) -> str:
+        device_desc: Dict[str, Union[str, List[str]]] = {
+            'path': self.path if self.path is not None else 'unknown',
+            'lvs': self.lvs if self.lvs else 'None',
+            'available': str(self.available),
+        }
+        if not self.available and self.rejected_reasons:
+            device_desc['rejection reasons'] = self.rejected_reasons
+        return "Device({})".format(
+            ', '.join('{}={}'.format(key, device_desc[key]) for key in device_desc.keys())
+        )