mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
don't double the count of i for LinuxHardware cpuinfo keys on
'vendor_id' and 'model name' keys Check for Xen paravirt and handle processor facts accordingly
This commit is contained in:
parent
fe53d86a83
commit
3729259b68
1 changed files with 32 additions and 7 deletions
|
@ -603,23 +603,38 @@ class LinuxHardware(Hardware):
|
||||||
|
|
||||||
def get_cpu_facts(self):
|
def get_cpu_facts(self):
|
||||||
i = 0
|
i = 0
|
||||||
|
vendor_id_occurrence = 0
|
||||||
|
model_name_occurrence = 0
|
||||||
physid = 0
|
physid = 0
|
||||||
coreid = 0
|
coreid = 0
|
||||||
sockets = {}
|
sockets = {}
|
||||||
cores = {}
|
cores = {}
|
||||||
|
xen_paravirt = False
|
||||||
if not os.access("/proc/cpuinfo", os.R_OK):
|
if not os.access("/proc/cpuinfo", os.R_OK):
|
||||||
return
|
return
|
||||||
self.facts['processor'] = []
|
self.facts['processor'] = []
|
||||||
for line in open("/proc/cpuinfo").readlines():
|
for line in open("/proc/cpuinfo").readlines():
|
||||||
data = line.split(":", 1)
|
data = line.split(":", 1)
|
||||||
key = data[0].strip()
|
key = data[0].strip()
|
||||||
|
|
||||||
# model name is for Intel arch, Processor (mind the uppercase P)
|
# model name is for Intel arch, Processor (mind the uppercase P)
|
||||||
# works for some ARM devices, like the Sheevaplug.
|
# works for some ARM devices, like the Sheevaplug.
|
||||||
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
|
if key == 'model name' or key == 'Processor' or key == 'vendor_id':
|
||||||
if 'processor' not in self.facts:
|
if 'processor' not in self.facts:
|
||||||
self.facts['processor'] = []
|
self.facts['processor'] = []
|
||||||
self.facts['processor'].append(data[1].strip())
|
self.facts['processor'].append(data[1].strip())
|
||||||
|
if key == 'vendor_id':
|
||||||
|
vendor_id_occurrence += 1
|
||||||
|
if key == 'model name':
|
||||||
|
model_name_occurrence += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
elif key == 'flags':
|
||||||
|
# Check for vme cpu flag, Xen paravirt does not expose this.
|
||||||
|
# Need to detect Xen paravirt because it exposes cpuinfo
|
||||||
|
# differently than Xen HVM or KVM and causes reporting of
|
||||||
|
# only a single cpu core.
|
||||||
|
if 'vme' not in data:
|
||||||
|
xen_paravirt = True
|
||||||
elif key == 'physical id':
|
elif key == 'physical id':
|
||||||
physid = data[1].strip()
|
physid = data[1].strip()
|
||||||
if physid not in sockets:
|
if physid not in sockets:
|
||||||
|
@ -634,7 +649,17 @@ class LinuxHardware(Hardware):
|
||||||
cores[coreid] = int(data[1].strip())
|
cores[coreid] = int(data[1].strip())
|
||||||
elif key == '# processors':
|
elif key == '# processors':
|
||||||
self.facts['processor_cores'] = int(data[1].strip())
|
self.facts['processor_cores'] = int(data[1].strip())
|
||||||
|
|
||||||
|
if vendor_id_occurrence == model_name_occurrence:
|
||||||
|
i = vendor_id_occurrence
|
||||||
|
|
||||||
if self.facts['architecture'] != 's390x':
|
if self.facts['architecture'] != 's390x':
|
||||||
|
if xen_paravirt:
|
||||||
|
self.facts['processor_count'] = i
|
||||||
|
self.facts['processor_cores'] = i
|
||||||
|
self.facts['processor_threads_per_core'] = 1
|
||||||
|
self.facts['processor_vcpus'] = i
|
||||||
|
else:
|
||||||
self.facts['processor_count'] = sockets and len(sockets) or i
|
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_cores'] = sockets.values() and sockets.values()[0] or 1
|
||||||
self.facts['processor_threads_per_core'] = ((cores.values() and
|
self.facts['processor_threads_per_core'] = ((cores.values() and
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue