Add storage device WWN to facts for Linux (#16640)

World Wide Name (WWN) is unique identifier of device.
This patch adds this identifier to facts for Linux.
This commit is contained in:
yuriy-z 2017-03-21 22:51:18 +02:00 committed by Adrian Likins
parent 897201c4be
commit 40a1f20bea

View file

@ -1435,6 +1435,20 @@ class LinuxHardware(Hardware):
except OSError:
return
devs_wwn = {}
try:
devs_by_id = os.listdir("/dev/disk/by-id")
except OSError:
pass
else:
for link_name in devs_by_id:
if link_name.startswith("wwn-"):
try:
wwn_link = os.readlink(os.path.join("/dev/disk/by-id", link_name))
except OSError:
continue
devs_wwn[os.path.basename(wwn_link)] = link_name[4:]
for block in block_devs:
virtual = 1
sysfs_no_links = 0
@ -1467,6 +1481,9 @@ class LinuxHardware(Hardware):
]:
d[key] = get_file_content(sysdir + test)
if diskname in devs_wwn:
d['wwn'] = devs_wwn[diskname]
d['partitions'] = {}
for folder in os.listdir(sysdir):
m = re.search("(" + diskname + "\d+)", folder)