diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2021-03-30 17:54:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2021-03-30 17:54:21 +0000 |
commit | 6366b1776bc51c29d4ba4c256f51d16acc52d871 (patch) | |
tree | b6b54789bce01dd26638bd84b5f42c8acfa40c4a /src/dashboard/admin_utils.py | |
parent | a35c01bccec1137ccd8a0f07f832daecb4ee2da3 (diff) | |
parent | 0573f51f18c1e55fe162dbd5a3f9acbd5394e065 (diff) |
Merge "Update actions to free hosts and vlans"
Diffstat (limited to 'src/dashboard/admin_utils.py')
-rw-r--r-- | src/dashboard/admin_utils.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py index ad276d9..186a64f 100644 --- a/src/dashboard/admin_utils.py +++ b/src/dashboard/admin_utils.py @@ -32,7 +32,10 @@ import pydoc from django.contrib.auth.models import User -from account.models import Lab +from account.models import ( + Lab, + PublicNetwork +) from resource_inventory.resource_manager import ResourceManager from resource_inventory.pdf_templater import PDFTemplater @@ -306,6 +309,21 @@ def force_release_booking(booking_id: int): task.save() +def free_leaked_public_vlans(safety_buffer_days=2): + for lab in Lab.objects.all(): + current_booking_set = Booking.objects.filter(end__gte=timezone.now() + timedelta(days=safety_buffer_days)) + + marked_nets = set() + + for booking in current_booking_set: + for network in get_network_metadata(booking.id): + marked_nets.add(network["vlan_id"]) + + for net in PublicNetwork.objects.filter(lab=lab).filter(in_use=True): + if net.vlan not in marked_nets: + lab.vlan_manager.release_public_vlan(net.vlan) + + def get_network_metadata(booking_id: int): """ Takes a booking id and prints all (known) networks that are owned by it. |