Skip to content

Commit

Permalink
Merge pull request #9 from deNBI/development
Browse files Browse the repository at this point in the history
consider disabled and/or down hypervisor
  • Loading branch information
maitai authored Feb 22, 2023
2 parents a038fe5 + f6b4fda commit 964b95f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions openapi_server/denbi/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __update_aggregates__(self):
"gpus_used": int(used),
"vcpus": int(hypervisor["vcpus"]),
"vcpus_used": int(hypervisor["vcpus_used"]),
"memory": int(int(hypervisor["memory_size"]) / 1024), # in GB
"memory_free": int(int(hypervisor["memory_free"]) / 1024), # in GB
"disk": int(hypervisor["local_disk_size"]), # in GB
"disk_available": int(hypervisor["disk_available"]), # in GB
"memory": int(hypervisor["memory_size"]), # in MB
"memory_free": int(hypervisor["memory_free"]), # in MB
"disk": int(hypervisor["local_disk_size"]), # in GB
"disk_available": int(hypervisor["disk_available"]), # in GB
})

# add necessary aggregate information to datastructure
Expand Down Expand Up @@ -95,20 +95,22 @@ def __update_gpu_flavors__(self):
if aggegrate["gpu_type"] == gpu_type:
# iterate over all hypervisor of current aggregate
for hypervisor in aggegrate["hypervisors"]:
if hypervisor["status"] == "disabled" or hypervisor["state"] == "down":
continue
# total number of flavors possible on an empty hypervisor
# calculate availability of each resource type
t_gpu = int(hypervisor["gpus"] / int(gpu_count))
t_vcpu = int(
int(hypervisor["vcpus"]) * self.cpu_overprovisioning / int(flavor["vcpus"]))
t_mem = int(int(hypervisor["memory"]) / int(flavor["ram"] / 1024))
t_mem = int(int(hypervisor["memory"]) / int(flavor["ram"]))
t_disk = int(int(hypervisor["disk"] / local_disk))
# add minimum of all resources needed to total number
total += min(t_gpu, t_vcpu, t_mem, t_disk)
# number of flavors possible with current available resources
c_gpu = int((hypervisor["gpus"] - hypervisor["gpus_used"]) / int(gpu_count))
c_vcpu = int((int(hypervisor["vcpus"]) * self.cpu_overprovisioning - int(
hypervisor["vcpus_used"])) / int(flavor["vcpus"]))
c_mem = int(int(hypervisor["memory_free"]) / int(flavor["ram"] / 1024))
c_mem = int(int(hypervisor["memory_free"]) / int(flavor["ram"]))
c_disk = int(int(hypervisor["disk_available"] / local_disk))
if min(c_gpu, c_vcpu, c_mem, c_disk) < 0:
print(f"{c_gpu} {c_vcpu} {c_mem} {c_disk} {min(c_gpu, c_vcpu, c_mem, c_disk)}")
Expand Down

0 comments on commit 964b95f

Please sign in to comment.