diff options
Diffstat (limited to 'src/dashboard')
-rw-r--r-- | src/dashboard/admin_utils.py | 29 | ||||
-rw-r--r-- | src/dashboard/tasks.py | 6 | ||||
-rw-r--r-- | src/dashboard/templatetags/jira_filters.py | 17 | ||||
-rw-r--r-- | src/dashboard/urls.py | 2 | ||||
-rw-r--r-- | src/dashboard/utils.py | 10 |
5 files changed, 42 insertions, 22 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py index b105e96..045caeb 100644 --- a/src/dashboard/admin_utils.py +++ b/src/dashboard/admin_utils.py @@ -22,7 +22,8 @@ from resource_inventory.models import ( DiskProfile, CpuProfile, RamProfile, - Interface + Interface, + CloudInitFile, ) import json @@ -50,7 +51,7 @@ from booking.models import Booking from notifier.manager import NotificationHandler from api.models import JobFactory -from api.models import JobStatus +from api.models import JobStatus, Job, GeneratedCloudConfig def print_div(): @@ -528,6 +529,30 @@ def extend_booking(booking_id, days=0, hours=0, minutes=0, weeks=0): booking.save() +def regenerate_cloud_configs(booking_id): + b = Booking.objects.get(id=booking_id) + for res in b.resource.get_resources(): + res.config.cloud_init_files.set(res.config.cloud_init_files.filter(generated=False)) # careful! + res.config.save() + cif = GeneratedCloudConfig.objects.create(resource_id=res.labid, booking=b, rconfig=res.config) + cif.save() + cif = CloudInitFile.create(priority=0, text=cif.serialize()) + cif.save() + res.config.cloud_init_files.add(cif) + res.config.save() + + +def set_job_new(job_id): + j = Job.objects.get(id=job_id) + b = j.booking + regenerate_cloud_configs(b.id) + for task in j.get_tasklist(): + task.status = JobStatus.NEW + task.save() + j.status = JobStatus.NEW + j.save() + + def docs(function=None, fulltext=False): """ Print documentation for a given function in admin_utils. diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py index 3f88449..93e6a22 100644 --- a/src/dashboard/tasks.py +++ b/src/dashboard/tasks.py @@ -81,11 +81,15 @@ def free_hosts(): ).filter( end__lt=timezone.now(), job__complete=True, - resource__isnull=False + complete=False, + resource__isnull=False, ) for booking in bookings: ResourceManager.getInstance().releaseResourceBundle(booking.resource) + booking.complete = True + print("Booking", booking.id, "is now completed") + booking.save() @shared_task diff --git a/src/dashboard/templatetags/jira_filters.py b/src/dashboard/templatetags/jira_filters.py deleted file mode 100644 index 9a97c1d..0000000 --- a/src/dashboard/templatetags/jira_filters.py +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Max Breitenfeldt and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -from django.conf import settings -from django.template.defaultfilters import register - - -@register.filter -def jira_issue_url(issue): - return settings.JIRA_URL + '/browse/' + str(issue) diff --git a/src/dashboard/urls.py b/src/dashboard/urls.py index d5dad57..c87dacc 100644 --- a/src/dashboard/urls.py +++ b/src/dashboard/urls.py @@ -33,7 +33,7 @@ from dashboard.views import ( host_profile_detail_view ) -app_name = "dashboard" +app_name = 'dashboard' urlpatterns = [ url(r'^$', landing_view, name='index'), url(r'^lab/$', lab_list_view, name='all_labs'), diff --git a/src/dashboard/utils.py b/src/dashboard/utils.py index d6b697a..97c9ac7 100644 --- a/src/dashboard/utils.py +++ b/src/dashboard/utils.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import (ObjectDoesNotExist, MultipleObjectsReturned) class AbstractModelQuery(): @@ -38,7 +38,15 @@ class AbstractModelQuery(): @classmethod def get(cls, *args, **kwargs): + """ + Gets a single matching resource + Throws ObjectDoesNotExist if none found matching, or MultipleObjectsReturned if + the query does not narrow to a single object + """ try: + ls = cls.filter(*args, **kwargs) + if len(ls) > 1: + raise MultipleObjectsReturned() return cls.filter(*args, **kwargs)[0] except IndexError: raise ObjectDoesNotExist() |