diff options
author | Sawyer Bergeron <sawyerbergeron@gmail.com> | 2020-11-16 16:28:18 -0500 |
---|---|---|
committer | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2020-11-16 16:29:01 -0500 |
commit | 68c01b558820e8da5946a31a6b57b2137046091f (patch) | |
tree | 0f5832ec6e5f6ce399d7fe0086e8f88a6bf48a76 /src/dashboard/admin_utils.py | |
parent | 6e7d8af810619e7ea3d14a612c735892c5ff1a84 (diff) |
Improve admin utils
Change-Id: I03e80a026191e96c63c3c47d2d20b93dc944ad98
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/dashboard/admin_utils.py')
-rw-r--r-- | src/dashboard/admin_utils.py | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py index 38e8955..fd427f5 100644 --- a/src/dashboard/admin_utils.py +++ b/src/dashboard/admin_utils.py @@ -24,13 +24,17 @@ from booking.models import Booking from notifier.manager import NotificationHandler from api.models import JobFactory +from api.models import JobStatus -""" -creates a quick booking using the given host -""" + +def print_div(): + print("====================================================================") def book_host(owner_username, host_labid, lab_username, hostname, image_id, template_name, length_days=21, collaborator_usernames=[], purpose="internal", project="LaaS"): + """ + creates a quick booking using the given host + """ lab = Lab.objects.get(lab_user__username=lab_username) host = Server.objects.filter(lab=lab).get(labid=host_labid) if host.booked: @@ -157,3 +161,49 @@ def map_cntt_interfaces(labid: str): iface.profile = new_ifprofile iface.save() + + +def detect_leaked_hosts(labid="unh_iol"): + """ + Use this to try to detect leaked hosts. + These hosts may still be in the process of unprovisioning, + but if they are not (or unprovisioning is frozen) then + these hosts are instead leaked + """ + working_servers = Server.objects.filter(working=True, lab__lab_user__username=labid) + booked = working_servers.filter(booked=True) + filtered = booked + print_div() + print("In use now:") + for booking in Booking.objects.filter(end__gte=timezone.now()): + res_for_booking = booking.resource.get_resources() + print(res_for_booking) + for resource in res_for_booking: + filtered = filtered.exclude(id=resource.id) + print_div() + print("Possibly leaked:") + for host in filtered: + print(host) + print_div() + return filtered + + +def booking_for_host(host_labid: str, labid="unh_iol"): + server = Server.objects.get(lab__lab_user__username=labid, labid=host_labid) + booking = server.bundle.booking_set.first() + print_div() + print(booking) + print("id:", booking.id) + print("owner:", booking.owner) + print("job (id):", booking.job, "(" + str(booking.job.id) + ")") + print_div() + return booking + + +def force_release_booking(booking_id): + booking = Booking.objects.get(id=booking_id) + job = booking.job + tasks = job.get_tasklist() + for task in tasks: + task.status = JobStatus.DONE + task.save() |