[Kimchi-devel] [PATCH] Host info: Add support to Power (ppc).
Paulo Vital
pvital at linux.vnet.ibm.com
Mon Jun 16 19:53:41 UTC 2014
Add support to get the correct information of Power's CPU hardware,
due to differences between the content of Power's /proc/cpuinfo and x86's
/proc/cpuinfo.
Also, add IBM PowerKVM information as supported distro.
Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
src/kimchi/model/host.py | 49 ++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 43 insertions(+), 6 deletions(-)
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 5844f4b..5716487 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -50,17 +50,54 @@ class HostModel(object):
self.task = TaskModel(**kargs)
self.host_info = self._get_host_info()
- def _get_host_info(self):
- res = {}
+ def _get_ppc_cpu_info(self):
+ i = 0
with open('/proc/cpuinfo') as f:
for line in f.xreadlines():
- if "model name" in line:
- res['cpu'] = line.split(':')[1].strip()
- break
+ if 'cpu' in line:
+ # Parse CPU information
+ cpu_info = line.split(':')[1].strip()
+ cpu_info = cpu_info.split('(')[0].strip()
+ i = i + 1
+ if 'revision' in line:
+ # Parse CPU's revision information
+ rev_info = line.split(':')[1].strip()
+ rev_info = rev_info.split('(')[0].strip()
+ i = i + 1
+ if 'clock' in line:
+ # Parse CPU's clock information
+ clock_info = line.split(':')[1].strip()
+ clock_info = clock_info.split('MHz')[0].strip()
+ clock_info = float(clock_info) / 1000
+ i = i + 1
+
+ # Power machines show, for each cpu/core, a block with all
+ # cpu information. Here we control the scan of the necessary
+ # information (1st block provides everything), skipping the
+ # with/for loop when find all information.
+ if i == 3:
+ return "%s (%s) @ %s GHz" % (cpu_info, rev_info, clock_info)
+
+ return ""
+
+ def _get_host_info(self):
+ res = {}
+ if platform.machine().startswith('ppc'):
+ res['cpu'] = self._get_ppc_cpu_info()
+ else:
+ with open('/proc/cpuinfo') as f:
+ for line in f.xreadlines():
+ if "model name" in line:
+ res['cpu'] = line.split(':')[1].strip()
+ break
res['memory'] = psutil.TOTAL_PHYMEM
+
+ # Include IBM PowerKVM name to supported distro names
+ _sup_distros = platform._supported_dists + ('ibm_powerkvm',)
# 'fedora' '17' 'Beefy Miracle'
- distro, version, codename = platform.linux_distribution()
+ distro, version, codename = platform.linux_distribution(
+ supported_dists=_sup_distros)
res['os_distro'] = distro
res['os_version'] = version
res['os_codename'] = unicode(codename, "utf-8")
--
1.8.3.1
More information about the Kimchi-devel
mailing list