From b9613665ddb01dfc01cd721799a83f703c1b1056 Mon Sep 17 00:00:00 2001 From: GuiGui2 Date: Mon, 31 Mar 2014 15:30:12 +0200 Subject: [PATCH] Setup module: Additional facts when using ansible with Linux on System z - Improved parsing of /proc/cpuinfo to take the specifics of Linux on System z. ansible_processor and ansible_processor_cores are now completed. - Also improved virtualization facts in the same environment, parsing the output of /usr/bin/lscpu to populate virtualization_type and virtualization_role more precisely. If lscpu is not available, then stick to the previous behavior. --- lib/ansible/module_utils/facts.py | 35 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c6e64fc4e60..411d709ee15 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -524,7 +524,7 @@ class LinuxHardware(Hardware): key = data[0].strip() # model name is for Intel arch, Processor (mind the uppercase P) # works for some ARM devices, like the Sheevaplug. - if key == 'model name' or key == 'Processor': + if key == 'model name' or key == 'Processor' or key == 'vendor_id': if 'processor' not in self.facts: self.facts['processor'] = [] self.facts['processor'].append(data[1].strip()) @@ -541,12 +541,15 @@ class LinuxHardware(Hardware): sockets[physid] = int(data[1].strip()) elif key == 'siblings': cores[coreid] = int(data[1].strip()) - self.facts['processor_count'] = sockets and len(sockets) or i - self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1 - self.facts['processor_threads_per_core'] = ((cores.values() and - cores.values()[0] or 1) / self.facts['processor_cores']) - self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] * - self.facts['processor_count'] * self.facts['processor_cores']) + elif key == '# processors': + self.facts['processor_cores'] = int(data[1].strip()) + if self.facts['architecture'] != 's390x': + self.facts['processor_count'] = sockets and len(sockets) or i + self.facts['processor_cores'] = sockets.values() and sockets.values()[0] or 1 + self.facts['processor_threads_per_core'] = ((cores.values() and + cores.values()[0] or 1) / self.facts['processor_cores']) + self.facts['processor_vcpus'] = (self.facts['processor_threads_per_core'] * + self.facts['processor_count'] * self.facts['processor_cores']) def get_dmi_facts(self): ''' learn dmi facts from system @@ -2110,10 +2113,24 @@ class LinuxVirtual(Virtual): elif re.match('^vendor_id.*PowerVM Lx86', line): self.facts['virtualization_type'] = 'powervm_lx86' elif re.match('^vendor_id.*IBM/S390', line): - self.facts['virtualization_type'] = 'ibm_systemz' + self.facts['virtualization_type'] = 'PR/SM' + lscpu = module.get_bin_path('lscpu') + if lscpu: + rc, out, err = module.run_command(["lscpu"]) + if rc == 0: + for line in out.split("\n"): + data = line.split(":", 1) + key = data[0].strip() + if key == 'Hypervisor': + self.facts['virtualization_type'] = data[1].strip() + else: + self.facts['virtualization_type'] = 'ibm_systemz' else: continue - self.facts['virtualization_role'] = 'guest' + if self.facts['virtualization_type'] == 'PR/SM': + self.facts['virtualization_role'] = 'LPAR' + else: + self.facts['virtualization_role'] = 'guest' return # Beware that we can have both kvm and virtualbox running on a single system