]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: make devices lists more granular in gather-facts
authorPaul Cuzner <pcuzner@redhat.com>
Wed, 19 Aug 2020 23:12:09 +0000 (11:12 +1200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 7 Sep 2020 09:01:03 +0000 (11:01 +0200)
The gather-facts commands returns a list of hdd and flash
devices. This patch changes the list content from being
simple strings representing the disks to a dict, making it
easier to extend in the future.

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
(cherry picked from commit 9b43b5c555d7e4160bc704a9702edc17797de50d)

src/cephadm/cephadm

index 6b1f7db882ca6ae9d001a29f2a015d2066a9ef6b..02cd4770b042412c32ee2de261d6caee2be6fc81 100755 (executable)
@@ -4724,8 +4724,14 @@ def read_file(path_list, file_name=''):
             file_path = path
         if os.path.exists(file_path):
             with open(file_path, 'r') as f:
-                content = f.read().strip()
-            return content
+                try:
+                    content = f.read().strip()
+                except OSError:
+                    # sysfs may populate the file, but for devices like
+                    # virtio reads can fail
+                    return "Unknown"
+                else:
+                    return content
     return "Unknown"
 
 
@@ -4861,28 +4867,39 @@ class HostFacts():
         return capacity
 
     def _dev_list(self, dev_list):
-        # type: (List[str]) -> List[str]
+        # type: (List[str]) -> List[Dict[str, object]]
         """Return a 'pretty' name list for each device in the `dev_list`"""
         disk_list = list()
 
         for dev in dev_list:
             disk_model = read_file(['/sys/block/{}/device/model'.format(dev)]).strip()
+            disk_rev = read_file(['/sys/block/{}/device/rev'.format(dev)]).strip()
+            disk_wwid = read_file(['/sys/block/{}/device/wwid'.format(dev)]).strip()
             vendor = read_file(['/sys/block/{}/device/vendor'.format(dev)]).strip()
             disk_vendor = HostFacts._disk_vendor_workarounds.get(vendor, vendor)
             disk_size_bytes = self._get_capacity(dev)
-            disk_list.append("{} {} ({})".format(disk_vendor, disk_model, bytes_to_human(disk_size_bytes)))
+            disk_list.append({
+                "description": "{} {} ({})".format(disk_vendor, disk_model, bytes_to_human(disk_size_bytes)),
+                "vendor": disk_vendor,
+                "model": disk_model,
+                "rev": disk_rev,
+                "wwid": disk_wwid,
+                "dev_name": dev,
+                "disk_size_bytes": disk_size_bytes,
+                }
+            )
         return disk_list
 
     @property
     def hdd_list(self):
-        # type: () -> List[str]
+        # type: () -> List[Dict[str, object]]
         """Return a list of devices that are HDDs (spinners)"""
         devs = self._get_devs_by_type(rota='1')
         return self._dev_list(devs)
 
     @property
     def flash_list(self):
-        # type: () -> List[str]
+        # type: () -> List[Dict[str, object]]
         """Return a list of devices that are flash based (SSD, NVMe)"""
         devs = self._get_devs_by_type(rota='0')
         return self._dev_list(devs)