From: Adam King Date: Thu, 18 Nov 2021 18:44:02 +0000 (-0500) Subject: python-common: add string representation for Device and DeviceSelection classes X-Git-Tag: v16.2.8~273^2~9 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1c25756b22d64abbe1f07a26676d3b0609b7649d;p=ceph.git python-common: add string representation for Device and DeviceSelection classes Signed-off-by: Adam King (cherry picked from commit 5b60b8e75889208a0c43e6cf7e9a6abcd849bd9f) --- diff --git a/src/python-common/ceph/deployment/drive_selection/selector.py b/src/python-common/ceph/deployment/drive_selection/selector.py index a54df3268a823..70ff651447893 100644 --- a/src/python-common/ceph/deployment/drive_selection/selector.py +++ b/src/python-common/ceph/deployment/drive_selection/selector.py @@ -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()) + ) diff --git a/src/python-common/ceph/deployment/inventory.py b/src/python-common/ceph/deployment/inventory.py index cfa20189400ef..d0a885668c090 100644 --- a/src/python-common/ceph/deployment/inventory.py +++ b/src/python-common/ceph/deployment/inventory.py @@ -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()) + )