From: Paul Cuzner Date: Wed, 19 Aug 2020 23:12:09 +0000 (+1200) Subject: cephadm: make devices lists more granular in gather-facts X-Git-Tag: v15.2.9~122^2~117^2~35 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cd215be5c8b3b36f74975517dfcdc5bafaf0a976;p=ceph.git cephadm: make devices lists more granular in gather-facts 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 (cherry picked from commit 9b43b5c555d7e4160bc704a9702edc17797de50d) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 6b1f7db882ca6..02cd4770b0424 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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)