[PATCH] Update host number of cpus and total physical memory information

- 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@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 + def lookup(self, *name): + self._update_host_info(self.host_info) return self.host_info def swupdate(self, *name): -- 1.9.1

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@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):

On 20-03-2015 16:45, Jose Ricardo Ziviani wrote:
+ res['cpus'] = 0 + res['memory'] = 0L
Those two lines above seem to be useless, as those dict entries will definitely be updated in the following line (self._update_host_info).

+ 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()
You prefer these codes: host_info['cpus'] = psutil._psplatform.get_num_cpus() host_info['memory'] = psutil.phymem_usage().total placed in lookup() only? So, in_get_host_info() I'd have those fields (cpus, memory) initialized like: res['cpus'] = 0 res['memory'] = 0L What do you think? Thank you

On 23/03/2015 10:31, Jose Ricardo Ziviani wrote:
+ 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()
You prefer these codes: host_info['cpus'] = psutil._psplatform.get_num_cpus() host_info['memory'] = psutil.phymem_usage().total
placed in lookup() only? So, in_get_host_info() I'd have those fields (cpus, memory) initialized like: res['cpus'] = 0 res['memory'] = 0L
What do you think?
+1
Thank you
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
participants (3)
-
Aline Manera
-
Crístian Viana
-
Jose Ricardo Ziviani