Skip to content

Commit 964b95f

Browse files
authored
Merge pull request #9 from deNBI/development
consider disabled and/or down hypervisor
2 parents a038fe5 + f6b4fda commit 964b95f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

openapi_server/denbi/resources.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def __update_aggregates__(self):
5656
"gpus_used": int(used),
5757
"vcpus": int(hypervisor["vcpus"]),
5858
"vcpus_used": int(hypervisor["vcpus_used"]),
59-
"memory": int(int(hypervisor["memory_size"]) / 1024), # in GB
60-
"memory_free": int(int(hypervisor["memory_free"]) / 1024), # in GB
61-
"disk": int(hypervisor["local_disk_size"]), # in GB
62-
"disk_available": int(hypervisor["disk_available"]), # in GB
59+
"memory": int(hypervisor["memory_size"]), # in MB
60+
"memory_free": int(hypervisor["memory_free"]), # in MB
61+
"disk": int(hypervisor["local_disk_size"]), # in GB
62+
"disk_available": int(hypervisor["disk_available"]), # in GB
6363
})
6464

6565
# add necessary aggregate information to datastructure
@@ -95,20 +95,22 @@ def __update_gpu_flavors__(self):
9595
if aggegrate["gpu_type"] == gpu_type:
9696
# iterate over all hypervisor of current aggregate
9797
for hypervisor in aggegrate["hypervisors"]:
98+
if hypervisor["status"] == "disabled" or hypervisor["state"] == "down":
99+
continue
98100
# total number of flavors possible on an empty hypervisor
99101
# calculate availability of each resource type
100102
t_gpu = int(hypervisor["gpus"] / int(gpu_count))
101103
t_vcpu = int(
102104
int(hypervisor["vcpus"]) * self.cpu_overprovisioning / int(flavor["vcpus"]))
103-
t_mem = int(int(hypervisor["memory"]) / int(flavor["ram"] / 1024))
105+
t_mem = int(int(hypervisor["memory"]) / int(flavor["ram"]))
104106
t_disk = int(int(hypervisor["disk"] / local_disk))
105107
# add minimum of all resources needed to total number
106108
total += min(t_gpu, t_vcpu, t_mem, t_disk)
107109
# number of flavors possible with current available resources
108110
c_gpu = int((hypervisor["gpus"] - hypervisor["gpus_used"]) / int(gpu_count))
109111
c_vcpu = int((int(hypervisor["vcpus"]) * self.cpu_overprovisioning - int(
110112
hypervisor["vcpus_used"])) / int(flavor["vcpus"]))
111-
c_mem = int(int(hypervisor["memory_free"]) / int(flavor["ram"] / 1024))
113+
c_mem = int(int(hypervisor["memory_free"]) / int(flavor["ram"]))
112114
c_disk = int(int(hypervisor["disk_available"] / local_disk))
113115
if min(c_gpu, c_vcpu, c_mem, c_disk) < 0:
114116
print(f"{c_gpu} {c_vcpu} {c_mem} {c_disk} {min(c_gpu, c_vcpu, c_mem, c_disk)}")

0 commit comments

Comments
 (0)