Merge pull request #2407 from jcftang/setup-osx-facts

Added osrelease and osversion as well as changed the way sysctl is calle...
pull/2406/merge
Michael DeHaan 12 years ago
commit ff4f9f217b

@ -855,36 +855,49 @@ class AIX(Hardware):
class Darwin(Hardware):
"""
Darwin-specific subclass of Hardware. Defines memory and CPU facts:
- processor
- processor_cores
- memtotal_mb
- memfree_mb
- model
- osversion
- osrevision
"""
platform = 'Darwin'
def __init__(self):
Hardware.__init__(self)
Hardware.__init__(self)
def populate(self):
self.sysctl = self.get_sysctl()
self.get_mac_facts()
self.get_cpu_facts()
self.get_memory_facts()
return self.facts
def get_sysctl(self):
rc, out, err = module.run_command(["/usr/sbin/sysctl", "hw", "machdep", "kern"])
if rc != 0:
return dict()
sysctl = dict()
for line in out.splitlines():
if line.rstrip("\n"):
(key, value) = re.split(' = |: ', line, maxsplit=1)
sysctl[key] = value.strip()
return sysctl
def get_mac_facts(self):
self.facts['model'] = self.sysctl['hw.model']
self.facts['osversion'] = self.sysctl['kern.osversion']
self.facts['osrevision'] = self.sysctl['kern.osrevision']
def get_cpu_facts(self):
self.facts['processor'] = []
rc, out, err = module.run_command("/usr/sbin/sysctl machdep.cpu.brand_string")
data = out[:-1].split(': ')
self.facts['processor'] = data[1]
rc, out, err = module.run_command("/usr/sbin/sysctl machdep.cpu.core_count")
data = out[:-1].split(': ')
self.facts['processor_cores'] = data[1]
self.facts['processor'] = self.sysctl['machdep.cpu.brand_string']
self.facts['processor_cores'] = self.sysctl['machdep.cpu.core_count']
def get_memory_facts(self):
rc, out, err = module.run_command("/usr/sbin/sysctl hw.memsize")
data = out[:-1].split(': ')
self.facts['memtotal_mb'] = int(data[1]) / 1024 / 1024
rc, out, err = module.run_command("/usr/sbin/sysctl hw.usermem")
data = out[:-1].split(': ')
self.facts['memfree_mb'] = int(data[1]) / 1024 / 1024
self.facts['memtotal_mb'] = long(self.sysctl['hw.memsize']) / 1024 / 1024
self.facts['memfree_mb'] = long(self.sysctl['hw.usermem']) / 1024 / 1024
class Network(Facts):
"""

Loading…
Cancel
Save