On 20/03/2015 16:45, Jose Ricardo Ziviani wrote:
- 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 | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 4419bb3..db14a28 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -87,8 +87,9 @@ 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
+ self._update_host_info(res)
# Include IBM PowerKVM name to supported distro names
_sup_distros = platform._supported_dists + ('ibm_powerkvm',)
@@ -101,7 +102,15 @@ class HostModel(object):
return res
+ def _update_host_info(self, host_info):
+ if not isinstance(host_info, dict):
+ return
+
+ host_info['cpus'] = psutil._psplatform.get_num_cpus()
+ host_info['memory'] = psutil.phymem_usage().total
+
_get_host_info() runs once on __init__() and then set the self.host_info
value
So I don't think we need the above function as we can update the
self.host_info directly on lookup()
def lookup(self, *name):
+ self._update_host_info(self.host_info)
return self.host_info
def swupdate(self, *name):