aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard/admin_utils.py
diff options
context:
space:
mode:
authorSean Smith <ssmith@iol.unh.edu>2021-02-23 15:41:59 -0500
committerSean Smith <ssmith@iol.unh.edu>2021-03-23 18:03:13 -0400
commit0573f51f18c1e55fe162dbd5a3f9acbd5394e065 (patch)
treed410f6561b599aa2368fe297247ba9a2e7625bab /src/dashboard/admin_utils.py
parentdb4c2dc4c4f0d86e0a00e8409eed74a0bcffb20b (diff)
Update actions to free hosts and vlans
Signed-off-by: Sean Smith <ssmith@iol.unh.edu> Change-Id: I94425ca5a48cccdf0b5382ef2bb16a989ee6b32d Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/dashboard/admin_utils.py')
-rw-r--r--src/dashboard/admin_utils.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py
index 222ccd3..b69981c 100644
--- a/src/dashboard/admin_utils.py
+++ b/src/dashboard/admin_utils.py
@@ -20,7 +20,10 @@ import json
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
@@ -220,6 +223,21 @@ def force_release_booking(booking_id):
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):
booking = Booking.objects.get(id=booking_id)
bundle = booking.resource