Gather uptime and device facts from Solarish systems (#18733)

* Gather device information on Solarish systems

* Gather uptime information on Solarish systems

* Fix typo in variable name

* Add comments and example output from kstat command
Use frozenset instead of set
Make parsing of line a little bit safer
This commit is contained in:
Adam Števko 2017-01-08 22:26:52 +01:00 committed by Toshio Kuratomi
parent 583136980d
commit 69559c184d

View file

@ -1533,6 +1533,8 @@ class SunOSHardware(Hardware):
self.get_cpu_facts()
self.get_memory_facts()
self.get_dmi_facts()
self.get_device_facts()
self.get_uptime_facts()
try:
self.get_mount_facts()
except TimeoutError:
@ -1621,6 +1623,79 @@ class SunOSHardware(Hardware):
if found:
self.facts['product_name'] = found.group(1)
def get_device_facts(self):
# Device facts are derived for sdderr kstats. This code does not use the
# full output, but rather queries for specific stats.
# Example output:
# sderr:0:sd0,err:Hard Errors 0
# sderr:0:sd0,err:Illegal Request 6
# sderr:0:sd0,err:Media Error 0
# sderr:0:sd0,err:Predictive Failure Analysis 0
# sderr:0:sd0,err:Product VBOX HARDDISK 9
# sderr:0:sd0,err:Revision 1.0
# sderr:0:sd0,err:Serial No VB0ad2ec4d-074a
# sderr:0:sd0,err:Size 53687091200
# sderr:0:sd0,err:Soft Errors 0
# sderr:0:sd0,err:Transport Errors 0
# sderr:0:sd0,err:Vendor ATA
self.facts['devices'] = {}
disk_stats = {
'Product': 'product',
'Revision': 'revision',
'Serial No': 'serial',
'Size': 'size',
'Vendor': 'vendor',
'Hard Errors': 'hard_errors',
'Soft Errors': 'soft_errors',
'Transport Errors': 'transport_errors',
'Media Error': 'media_errors',
'Predictive Failure Analysis': 'predictive_failure_analysis',
'Illegal Request': 'illegal_request',
}
cmd = ['/usr/bin/kstat', '-p']
for ds in disk_stats:
cmd.append('sderr:::%s' % ds)
d = {}
rc, out, err = self.module.run_command(cmd)
if rc != 0:
return dict()
sd_instances = frozenset(line.split(':')[1] for line in out.split('\n') if line.startswith('sderr'))
for instance in sd_instances:
lines = (line for line in out.split('\n') if ':' in line and line.split(':')[1] == instance)
for line in lines:
text, value = line.split('\t')
stat = text.split(':')[3]
if stat == 'Size':
d[disk_stats.get(stat)] = self.module.pretty_bytes(float(value))
else:
d[disk_stats.get(stat)] = value.rstrip()
diskname = 'sd' + instance
self.facts['devices'][diskname] = d
d = {}
def get_uptime_facts(self):
# On Solaris, unix:0:system_misc:snaptime is created shortly after machine boots up
# and displays tiem in seconds. This is much easier than using uptime as we would
# need to have a parsing procedure for translating from human-readable to machine-readable
# format.
# Example output:
# unix:0:system_misc:snaptime 1175.410463590
rc, out, err = self.module.run_command('/usr/bin/kstat -p unix:0:system_misc:snaptime')
if rc != 0:
return
self.facts['uptime_seconds'] = int(float(out.split('\t')[1]))
class OpenBSDHardware(Hardware):
"""
OpenBSD-specific subclass of Hardware. Defines memory, CPU and device facts: