From fdeccd2d7bc393cbe771b36100bf318509c400d5 Mon Sep 17 00:00:00 2001 From: Jimmy Tang Date: Fri, 15 Mar 2013 15:58:45 +0000 Subject: [PATCH] Added osrelease and osversion as well as changed the way sysctl is called on OSX --- setup | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/setup b/setup index 74799ebca91..14577992ab5 100644 --- a/setup +++ b/setup @@ -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): """