diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index ae245e7..f95ee3a 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -16,6 +16,7 @@ import abc import binascii import functools import os +import os.path import shlex import time @@ -110,12 +111,23 @@ def list_all_block_devices(block_type='disk'): """ _udev_settle() + disk_by_path_dir = '/dev/disk/by-path' columns = ['KNAME', 'MODEL', 'SIZE', 'ROTA', 'TYPE'] report = utils.execute('lsblk', '-Pbdi', '-o{}'.format(','.join(columns)), check_exit_code=[0])[0] lines = report.split('\n') context = pyudev.Context() + # construct dictionary mapping device name to /dev/disk/by-path softlink + # that points to it + + by_path_mapping = {} + paths = os.listdir(disk_by_path_dir) + for p in paths: + devname = os.path.basename(os.readlink( + os.path.join(disk_by_path_dir, p))) + by_path_mapping[devname] = p + devices = [] for line in lines: device = {} @@ -164,12 +176,14 @@ def list_all_block_devices(block_type='disk'): LOG.warning('Could not find the SCSI address (HCTL) for ' 'device %s. Skipping', name) + by_path_name = by_path_mapping[os.path.basename(name)] devices.append(BlockDevice(name=name, model=device['MODEL'], size=int(device['SIZE']), rotational=bool(int(device['ROTA'])), vendor=_get_device_info(device['KNAME'], 'block', 'vendor'), + by_path=by_path_name, **extra)) return devices @@ -202,7 +216,7 @@ class BlockDevice(encoding.SerializableComparable): def __init__(self, name, model, size, rotational, wwn=None, serial=None, vendor=None, wwn_with_extension=None, - wwn_vendor_extension=None, hctl=None): + wwn_vendor_extension=None, hctl=None, by_path=None): self.name = name self.model = model self.size = size @@ -213,6 +227,7 @@ class BlockDevice(encoding.SerializableComparable): self.wwn_with_extension = wwn_with_extension self.wwn_vendor_extension = wwn_vendor_extension self.hctl = hctl + self.by_path = by_path class NetworkInterface(encoding.SerializableComparable):