Merge pull request #10461 from cblument/fact_ansible_uptime

Adding uptime_seconds fact for linux and darwin platforms
This commit is contained in:
Brian Coca 2015-03-16 09:11:23 -04:00
commit 3312a76987

View file

@ -652,6 +652,7 @@ class LinuxHardware(Hardware):
self.get_memory_facts() self.get_memory_facts()
self.get_dmi_facts() self.get_dmi_facts()
self.get_device_facts() self.get_device_facts()
self.get_uptime_facts()
try: try:
self.get_mount_facts() self.get_mount_facts()
except TimeoutError: except TimeoutError:
@ -990,6 +991,9 @@ class LinuxHardware(Hardware):
self.facts['devices'][diskname] = d self.facts['devices'][diskname] = d
def get_uptime_facts(self):
uptime_seconds_string = get_file_content('/proc/uptime').split(' ')[0]
self.facts['uptime_seconds'] = int(float(uptime_seconds_string))
class SunOSHardware(Hardware): class SunOSHardware(Hardware):
""" """
@ -1588,6 +1592,7 @@ class Darwin(Hardware):
self.get_mac_facts() self.get_mac_facts()
self.get_cpu_facts() self.get_cpu_facts()
self.get_memory_facts() self.get_memory_facts()
self.get_uptime_facts()
return self.facts return self.facts
def get_sysctl(self): def get_sysctl(self):
@ -1635,6 +1640,12 @@ class Darwin(Hardware):
if rc == 0: if rc == 0:
self.facts['memfree_mb'] = long(out.splitlines()[-1].split()[1]) / 1024 / 1024 self.facts['memfree_mb'] = long(out.splitlines()[-1].split()[1]) / 1024 / 1024
def get_uptime_facts(self):
kern_boottime = self.sysctl['kern.boottime']
boottime = datetime.datetime.strptime(kern_boottime, "%a %b %d %H:%M:%S %Y")
delta = datetime.datetime.now() - boottime
self.facts['uptime_seconds'] = int(delta.total_seconds())
class Network(Facts): class Network(Facts):
""" """
This is a generic Network subclass of Facts. This should be further This is a generic Network subclass of Facts. This should be further