Skip to content

Commit

Permalink
track resources for providers separately to make quota checking precise
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Feb 5, 2024
1 parent 989f9c4 commit 01764d0
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions bibigrid/core/utility/validate_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ def __init__(self, configurations, providers, log):
self.log = log
self.configurations = configurations
self.providers = providers
self.required_resources_dict = {'total_cores': 0, 'floating_ips': 0, 'instances': 0, 'total_ram': 0,
'Volumes': 0, 'VolumeGigabytes': 0, 'Snapshots': 0, 'Backups': 0,
'BackupGigabytes': 0}

self.required_resources_dict = {
provider.cloud_specification['identifier']: {'total_cores': 0, 'floating_ips': 0, 'instances': 0,
'total_ram': 0, 'Volumes': 0, 'VolumeGigabytes': 0,
'Snapshots': 0, 'Backups': 0, 'BackupGigabytes': 0} for
provider in providers}

def validate(self):
"""
Expand Down Expand Up @@ -260,7 +263,7 @@ def check_instances(self):
success = True
for configuration, provider in zip(self.configurations, self.providers):
try:
self.required_resources_dict["floating_ips"] += 1
self.required_resources_dict[provider.cloud_specification['identifier']]["floating_ips"] += 1
if configuration.get("masterInstance"):
success = self.check_instance("masterInstance", configuration["masterInstance"],
provider) and success
Expand All @@ -282,13 +285,13 @@ def check_instance(self, instance_name, instance, provider):
:param provider: provider
:return: true if type and image compatible and existing
"""
self.required_resources_dict["instances"] += instance.get("count") or 1
self.required_resources_dict[provider.cloud_specification['identifier']]["instances"] += instance.get(
"count") or 1
instance_image_id_or_name = instance["image"]
try:
instance_image = image_selection.select_image(provider, instance_image_id_or_name, self.log)
self.log.info(
f"Instance {instance_name} image: {instance_image_id_or_name} found on "
f"{provider.cloud_specification['identifier']}")
self.log.info(f"Instance {instance_name} image: {instance_image_id_or_name} found on "
f"{provider.cloud_specification['identifier']}")
instance_type = instance["type"]
except ImageNotActiveException:
active_images = '\n'.join(provider.get_active_images())
Expand Down Expand Up @@ -322,8 +325,8 @@ def check_instance_type_image_combination(self, instance_type, instance_image, p
(type_max_ram, image_min_ram, "ram")]:
success = has_enough(maximum, needed, f"Type {instance_type}", thing, self.log) and success
# prepare check quotas
self.required_resources_dict["total_ram"] += type_max_ram
self.required_resources_dict["total_cores"] += flavor["vcpus"]
self.required_resources_dict[provider.cloud_specification['identifier']]["total_ram"] += type_max_ram
self.required_resources_dict[provider.cloud_specification['identifier']]["total_cores"] += flavor["vcpus"]
return success

def check_volumes(self):
Expand Down Expand Up @@ -352,8 +355,9 @@ def check_volumes(self):
else:
self.log.info(f"Snapshot '{volume_name_or_id}' found on "
f"{provider.cloud_specification['identifier']}.")
self.required_resources_dict["Volumes"] += 1
self.required_resources_dict["VolumeGigabytes"] += snapshot["size"]
self.required_resources_dict[provider.cloud_specification['identifier']]["Volumes"] += 1
self.required_resources_dict[provider.cloud_specification['identifier']][
"VolumeGigabytes"] += snapshot["size"]
else:
self.log.info(f"Volume '{volume_name_or_id}' found on "
f"{provider.cloud_specification['identifier']}.")
Expand Down Expand Up @@ -424,10 +428,9 @@ def check_quotas(self):
self.log.info("required/available")
for provider in self.providers:
free_resources_dict = provider.get_free_resources()
for key, value in self.required_resources_dict.items():
for key, value in self.required_resources_dict[provider.cloud_specification['identifier']].items():
success = has_enough(free_resources_dict[key], value,
f"Project {self.providers[0].cloud_specification['identifier']}", key,
self.log) and success
f"Project {provider.cloud_specification['identifier']}", key, self.log) and success
return success

def check_ssh_public_key_files(self):
Expand Down

0 comments on commit 01764d0

Please sign in to comment.