-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A one-time command is added which will set the Swift quota of every allocation from GB to GiB. The Swift quota attribute name has been appropriately renamed
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/coldfront_plugin_cloud/management/commands/convert_swift_quota_to_gib.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
import re | ||
|
||
from coldfront_plugin_cloud import attributes | ||
from coldfront_plugin_cloud import openstack | ||
from coldfront_plugin_cloud import openshift | ||
from coldfront_plugin_cloud import utils | ||
from coldfront_plugin_cloud import tasks | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
from django.db.models import Q | ||
from coldfront.core.resource.models import (Resource, | ||
ResourceType) | ||
from coldfront.core.allocation.models import (Allocation, | ||
AllocationStatusChoice, | ||
AllocationUser) | ||
from keystoneauth1.exceptions import http | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """One time command to convert all Swift quotas on all Openstack allocations from | ||
Gb to Gib. I.e a Swift quota of 1000^2 bytes will now be 1024^2 bytes""" | ||
|
||
def handle(self, *args, **options): | ||
openstack_resources = Resource.objects.filter( | ||
resource_type=ResourceType.objects.get( | ||
name='OpenStack' | ||
) | ||
) | ||
openstack_allocations = Allocation.objects.filter( | ||
Q(status=AllocationStatusChoice.objects.get(name='Active')) | | ||
Q(status=AllocationStatusChoice.objects.get(name='Expired')), | ||
resources__in=openstack_resources, | ||
) | ||
for allocation in openstack_allocations: | ||
if not (swift_quota := allocation.get_attribute(attributes.QUOTA_OBJECT_GB)): | ||
continue | ||
|
||
allocation_str = f'{allocation.pk} of project "{allocation.project.title}"' | ||
obj_key = openstack.QUOTA_KEY_MAPPING['object']['keys'][attributes.QUOTA_OBJECT_GB] | ||
allocator = openstack.OpenStackResourceAllocator( | ||
allocation.resources.first(), | ||
allocation | ||
) | ||
|
||
project_id = allocation.get_attribute(attributes.ALLOCATION_PROJECT_ID) | ||
if not project_id: | ||
logger.error(f'{allocation_str} is active but has no Project ID set.') | ||
continue | ||
payload = { | ||
obj_key : swift_quota | ||
} | ||
|
||
allocator._set_object_quota(project_id, payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters