1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adding uptime_seconds fact for linux and darwin platforms

Adds ansible_uptime_seconds facts for linux and darwin platforms.  BSD
platforms may also work.
This commit is contained in:
Chris Blumentritt 2015-03-13 15:35:31 -05:00
parent 70f56c135c
commit 7813ffd719

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