- The number of cpus and the total physical memory information
displayed in the host section can change, so them cannot be
static. This commit updates those values whenever a GET request
hits the backend looking for host information.
Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
---
src/kimchi/model/host.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 4419bb3..293c4ce 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -87,8 +87,8 @@ class HostModel(object):
res['cpu_model'] = line.split(':')[1].strip()
break
- res['cpus'] = psutil.NUM_CPUS
- res['memory'] = psutil.TOTAL_PHYMEM
+ res['cpus'] = 0
+ res['memory'] = 0L
# Include IBM PowerKVM name to supported distro names
_sup_distros = platform._supported_dists + ('ibm_powerkvm',)
@@ -102,6 +102,18 @@ class HostModel(object):
return res
def lookup(self, *name):
+ cpus = 0
+
+ # Only newer psutil versions have a portable method to get
+ # the number of cpus
+ try:
+ cpus = psutil.cpu_count()
+
+ except AttributeError:
+ cpus = psutil._psplatform.get_num_cpus()
+
+ self.host_info['cpus'] = cpus
+ self.host_info['memory'] = psutil.phymem_usage().total
return self.host_info
def swupdate(self, *name):
--
1.9.1