aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard/tasks.py
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-06-08 12:46:53 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-07-21 13:17:51 -0400
commita09db9f287a02873c0226759f8ea444bb304cd59 (patch)
tree59e744e4b998973a808abbae2d21fbdd6201d829 /src/dashboard/tasks.py
parent8ddc7e820e120f1dde4e901d3cb6f1dd3f281e65 (diff)
LaaS 3.0 Almost MVP
Change-Id: Ided9a43cf3088bb58a233dc459711c03f43e11b8 Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/dashboard/tasks.py')
-rw-r--r--src/dashboard/tasks.py93
1 files changed, 13 insertions, 80 deletions
diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py
index 93e6a22..ac4b006 100644
--- a/src/dashboard/tasks.py
+++ b/src/dashboard/tasks.py
@@ -9,90 +9,23 @@
##############################################################################
+from booking.models import Booking
from celery import shared_task
from django.utils import timezone
-from booking.models import Booking
-from notifier.manager import NotificationHandler
-from api.models import (
- Job,
- JobStatus,
- SoftwareRelation,
- HostHardwareRelation,
- HostNetworkRelation,
- AccessRelation,
- JobFactory
-)
-
-from resource_inventory.resource_manager import ResourceManager
-from resource_inventory.models import ConfigState
-
+from api.views import liblaas_end_booking
+# todo - make a task to check for expired bookings
@shared_task
-def booking_poll():
- def cleanup_resource_task(qs):
- for hostrelation in qs:
- hostrelation.config.state = ConfigState.CLEAN
- hostrelation.config.save()
- hostrelation.status = JobStatus.NEW
- hostrelation.save()
-
- def cleanup_software(qs):
- if qs.exists():
- relation = qs.first()
- software = relation.config.opnfv
- software.clear_delta()
- software.save()
- relation.status = JobStatus.NEW
- relation.save()
-
- def cleanup_access(qs):
- for relation in qs:
- if "vpn" in relation.config.access_type.lower():
- relation.config.set_revoke(True)
- relation.config.save()
- relation.status = JobStatus.NEW
- relation.save()
-
- cleanup_set = Booking.objects.filter(end__lte=timezone.now()).filter(job__complete=False)
-
+def end_expired_bookings():
+ print("Celery task for end_expired_bookings() has been triggered")
+ cleanup_set = Booking.objects.filter(end__lte=timezone.now(), ).filter(complete=False)
+ print("Newly expired bookings: ", cleanup_set)
for booking in cleanup_set:
- if not booking.job.complete:
- job = booking.job
- cleanup_software(SoftwareRelation.objects.filter(job=job))
- cleanup_resource_task(HostHardwareRelation.objects.filter(job=job))
- cleanup_resource_task(HostNetworkRelation.objects.filter(job=job))
- cleanup_access(AccessRelation.objects.filter(job=job))
- job.complete = True
- job.save()
- NotificationHandler.notify_booking_end(booking)
-
-
-@shared_task
-def free_hosts():
- """Free all hosts that should be freed."""
- undone_statuses = [JobStatus.NEW, JobStatus.CURRENT, JobStatus.ERROR]
- undone_jobs = Job.objects.filter(
- hostnetworkrelation__status__in=undone_statuses,
- hosthardwarerelation__status__in=undone_statuses
- )
-
- bookings = Booking.objects.exclude(
- job__in=undone_jobs
- ).filter(
- end__lt=timezone.now(),
- job__complete=True,
- complete=False,
- resource__isnull=False,
- )
-
- for booking in bookings:
- ResourceManager.getInstance().releaseResourceBundle(booking.resource)
booking.complete = True
- print("Booking", booking.id, "is now completed")
+ if (booking.aggregateId):
+ print("ending booking " + str(booking.id) + " with agg id: ", booking.aggregateId)
+ liblaas_end_booking(booking.aggregateId)
+ else:
+ print("booking " + str(booking.id) + " has no agg id")
booking.save()
-
-
-@shared_task
-def query_vpn_users():
- """ get active vpn users """
- JobFactory.makeActiveUsersTask()
+ print("Finished end_expired_bookings()")