You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to have a management command that reports the total quota values across all allocations
This command could also do the same on a per-project basis.
Some proof-of-concept code:
import yaml
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from coldfront_plugin_cloud import attributes
from coldfront_plugin_cloud import openstack
from coldfront.core.resource.models import (Resource, ResourceType)
from coldfront.core.allocation.models import (Allocation, AllocationStatusChoice)
class Command(BaseCommand):
help = 'Show cloud quotas (OpenShift and OpenStack)'
def add_arguments(self, parser):
parser.add_argument('type', choices=['all', 'OpenStack', 'OpenShift'], help='cloud type')
parser.add_argument('--project-id', help='limit scope to project id')
def get_quota_totals(self, cloud_type):
try:
resources = Resource.objects.filter(
resource_type=ResourceType.objects.get(
name=cloud_type,
)
)
except ObjectDoesNotExist as e:
print(f'Skpping {cloud_type} - resource type does not exist')
return 1
allocations = Allocation.objects.filter(
resources__in=resources,
status=AllocationStatusChoice.objects.get(name='Active')
)
totals = {}
for attr in attributes.ALLOCATION_QUOTA_ATTRIBUTES:
if cloud_type in attr:
total = 0
for allocation in allocations:
try:
val = float(allocation.get_attribute(attr))
total += val
except TypeError:
continue
totals[attr] = total
print(yaml.dump(totals).strip())
def handle(self, *args, **options):
if (t := options['type']) != 'all':
self.get_quota_totals(t)
else:
self.get_quota_totals('OpenStack')
self.get_quota_totals('OpenShift')
The text was updated successfully, but these errors were encountered:
It would be useful to have a management command that reports the total quota values across all allocations
This command could also do the same on a per-project basis.
Some proof-of-concept code:
The text was updated successfully, but these errors were encountered: