Skip to content
Snippets Groups Projects
Commit 66e53277 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #8887: fix in resource_usages

parent 7c4bc6ca
No related branches found
No related tags found
No related merge requests found
......@@ -1334,30 +1334,27 @@ class RADatabase:
resources = self.getResources(resource_ids=resource_ids, include_availability=True)
for resource in resources:
try:
resource_id = resource['id']
resource_usages = all_usages[resource_id]
# copy resource capacities
resource_usages['total_capacity'] = 0
resource_usages['available_capacity'] = 0
resource_usages['used_capacity'] = 0
resource_usages['misc_used_capacity'] = 0
if 'total_capacity' in resource:
resource_usages['total_capacity'] = resource['total_capacity']
if 'available_capacity' in resource:
resource_usages['available_capacity'] = resource['available_capacity']
if 'used_capacity' in resource:
resource_usages['used_capacity'] = resource['used_capacity']
# and compute unaccounted-for usage,
# which is the actual used_capacity minus the currently allocated total claim size
utcnow = datetime.utcnow()
allocated_usages = resource_usages['usages'].get('allocated', [])
past_allocated_usages = sorted([au for au in allocated_usages if au['timestamp'] <= utcnow])
if past_allocated_usages:
currently_allocated_usage = past_allocated_usages[-1]
resource_usages['misc_used_capacity'] = resource['used_capacity'] - currently_allocated_usage['value']
except:
pass
resource_id = resource['id']
resource_usages = all_usages[resource_id]
# copy resource capacities
for item in ['total_capacity', 'available_capacity', 'used_capacity']:
try:
resource_usages[item] = 0
if item in resource:
resource_usages[item] = resource[item]
if item == 'used_capacity':
# and compute unaccounted-for usage,
# which is the actual used_capacity minus the currently allocated total claim size
# defaults to used_capacity if no currently allocated total claim size
resource_usages['misc_used_capacity'] = resource['used_capacity']
utcnow = datetime.utcnow()
allocated_usages = resource_usages['usages'].get('allocated', [])
past_allocated_usages = sorted([au for au in allocated_usages if au['timestamp'] <= utcnow])
if past_allocated_usages:
currently_allocated_usage = past_allocated_usages[-1]
resource_usages['misc_used_capacity'] = resource['used_capacity'] - currently_allocated_usage['value']
except Exception as e:
logger.error(e)
all_usages_list = all_usages.values()
return all_usages_list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment