Add HDD serial numbers. (rebase/fixes of #9454) (#22852)

Add HDD serial numbers to linux hardware facts via 'sg_inq' tool
This commit is contained in:
Adrian Likins 2017-03-24 12:06:42 -04:00 committed by GitHub
parent e084e8809e
commit 25be6aebc3

View file

@ -1476,6 +1476,19 @@ class LinuxHardware(Hardware):
for key in ['vendor', 'model', 'sas_address', 'sas_device_handle']:
d[key] = get_file_content(sysdir + "/device/" + key)
sg_inq = self.module.get_bin_path('sg_inq')
if sg_inq:
device = "/dev/%s" % (block)
rc, drivedata, err = self.module.run_command([sg_inq, device])
if rc == 0:
serial = re.search("Unit serial number:\s+(\w+)", drivedata)
if serial:
d['serial'] = serial.group(1)
for key in ['vendor', 'model']:
d[key] = get_file_content(sysdir + "/device/" + key)
for key,test in [ ('removable','/removable'), \
('support_discard','/queue/discard_granularity'),
]: