mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fixes solaris (sunos) uptime in ansible facts module (#54626)
* correct uptime on solaris by using system boot_time instead of snaptime * add unit test
This commit is contained in:
parent
91a664a93e
commit
b28c73af62
3 changed files with 24 additions and 8 deletions
|
@ -17,6 +17,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
import time
|
||||
|
||||
from ansible.module_utils.six.moves import reduce
|
||||
|
||||
|
@ -266,18 +267,15 @@ class SunOSHardware(Hardware):
|
|||
|
||||
def get_uptime_facts(self):
|
||||
uptime_facts = {}
|
||||
# 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')
|
||||
# sample kstat output:
|
||||
# unix:0:system_misc:boot_time 1548249689
|
||||
rc, out, err = self.module.run_command('/usr/bin/kstat -p unix:0:system_misc:boot_time')
|
||||
|
||||
if rc != 0:
|
||||
return
|
||||
|
||||
uptime_facts['uptime_seconds'] = int(float(out.split('\t')[1]))
|
||||
# uptime = $current_time - $boot_time
|
||||
uptime_facts['uptime_seconds'] = int(time.time() - int(out.split('\t')[1]))
|
||||
|
||||
return uptime_facts
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue