From 91ec098aa05d210e51128a35263e8c8b11934a2d Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 18 May 2023 14:35:19 +0300 Subject: [PATCH] fix cpu_usage waiting for instance creation. --- computes/models.py | 2 +- vrtManager/hostdetails.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/computes/models.py b/computes/models.py index 86df52a..3f17254 100644 --- a/computes/models.py +++ b/computes/models.py @@ -51,7 +51,7 @@ class Compute(Model): @cached_property def cpu_usage(self): - return round(self.proxy.get_cpu_usage().get('usage')) + return round(self.proxy.get_cpu_usage(diff=False).get('usage')) @cached_property def ram_size(self): diff --git a/vrtManager/hostdetails.py b/vrtManager/hostdetails.py index 0b7c313..31aca86 100644 --- a/vrtManager/hostdetails.py +++ b/vrtManager/hostdetails.py @@ -27,7 +27,7 @@ class wvmHostDetails(wvmConnect): else: return {"total": None, "usage": None, "percent": None} - def get_cpu_usage(self): + def get_cpu_usage(self, diff=True): """ Function return cpu usage on node. """ @@ -43,6 +43,8 @@ class wvmHostDetails(wvmConnect): diff_idle = idle - prev_idle diff_total = total - prev_total diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10 + if not diff: + return {"usage": diff_usage} prev_total = total prev_idle = idle if num == 0: