diff options
author | Raven Hodgdon <jhodgdon@iol.unh.edu> | 2022-01-06 15:56:13 -0500 |
---|---|---|
committer | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2022-09-07 18:05:28 +0000 |
commit | 2f00cec033d0b20f5d4fda78281988da4ad18e9f (patch) | |
tree | d4cd1decc587134df0c82810ec087d03eeda19f1 /src | |
parent | 97a32dd51c6ac6bcbb5b5f129b635afbeea40270 (diff) |
added booking details api endpoint
Change-Id: I716ea72bcb57762b6fc9c684233deb42ee49f8af
Signed-off-by: jhodgdon <jhodgdon@iol.unh.edu>
Diffstat (limited to 'src')
-rw-r--r-- | src/api/urls.py | 2 | ||||
-rw-r--r-- | src/api/views.py | 102 |
2 files changed, 103 insertions, 1 deletions
diff --git a/src/api/urls.py b/src/api/urls.py index acef947..cbb453c 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -62,6 +62,7 @@ from api.views import ( single_image, single_opsys, create_ci_file, + booking_details, ) urlpatterns = [ @@ -93,6 +94,7 @@ urlpatterns = [ path('booking/<int:booking_id>', specific_booking), path('booking/<int:booking_id>/extendBooking/<int:days>', extend_booking), path('booking/makeBooking', make_booking), + path('booking/<int:booking_id>/details', booking_details), path('resource_inventory/availableTemplates', available_templates), path('resource_inventory/<int:template_id>/images', images_for_template), diff --git a/src/api/views.py b/src/api/views.py index ffa9b3f..d5966ed 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -33,7 +33,7 @@ from api.forms import DowntimeForm from account.models import UserProfile, Lab from booking.models import Booking from booking.quick_deployer import create_from_API -from api.models import LabManagerTracker, get_task, Job, AutomationAPIManager, APILog +from api.models import LabManagerTracker, get_task, Job, AutomationAPIManager, APILog, GeneratedCloudConfig from notifier.manager import NotificationHandler from analytics.models import ActiveVPNUser from resource_inventory.models import ( @@ -654,3 +654,103 @@ def list_labs(request): lab_list.append(lab_info) return JsonResponse(lab_list, safe=False) + + +""" +Booking Details API Views +""" + + +def booking_details(request, booking_id=""): + token = auth_and_log(request, 'booking/{}/details'.format(booking_id)) + + if isinstance(token, HttpResponse): + return token + + booking = get_object_or_404(Booking, pk=booking_id, owner=token.user) + + # overview + overview = { + 'username': GeneratedCloudConfig._normalize_username(None, str(token.user)), + 'purpose': booking.purpose, + 'project': booking.project, + 'start_time': booking.start, + 'end_time': booking.end, + 'pod_definitions': booking.resource.template, + 'lab': booking.lab + } + + # deployment progress + task_list = [] + for task in booking.job.get_tasklist(): + task_info = { + 'name': str(task), + 'status': 'DONE', + 'lab_response': 'No response provided (yet)' + } + if task.status < 100: + task_info['status'] = 'PENDING' + elif task.status < 200: + task_info['status'] = 'IN PROGRESS' + + if task.message: + if task.type_str == "Access Task" and request.user.id != task.config.user.id: + task_info['lab_response'] = '--secret--' + else: + task_info['lab_response'] = str(task.message) + task_list.append(task_info) + + # pods + pod_list = [] + for host in booking.resource.get_resources(): + pod_info = { + 'hostname': host.config.name, + 'machine': host.name, + 'role': '', + 'is_headnode': host.config.is_head_node, + 'image': host.config.image, + 'ram': {'amount': str(host.profile.ramprofile.first().amount) + 'G', 'channels': host.profile.ramprofile.first().channels}, + 'cpu': {'arch': host.profile.cpuprofile.first().architecture, 'cores': host.profile.cpuprofile.first().cores, 'sockets': host.profile.cpuprofile.first().cpus}, + 'disk': {'size': str(host.profile.storageprofile.first().size) + 'GiB', 'type': host.profile.storageprofile.first().media_type, 'mount_point': host.profile.storageprofile.first().name}, + 'interfaces': [], + } + try: + pod_info['role'] = host.template.opnfvRole + except Exception: + pass + for intprof in host.profile.interfaceprofile.all(): + int_info = { + 'name': intprof.name, + 'speed': intprof.speed + } + pod_info['interfaces'].append(int_info) + pod_list.append(pod_info) + + # diagnostic info + diagnostic_info = { + 'job_id': booking.job.id, + 'ci_files': '', + 'pods': [] + } + for host in booking.resource.get_resources(): + pod = { + 'host': host.name, + 'configs': [], + + } + for ci_file in host.config.cloud_init_files.all(): + ci_info = { + 'id': ci_file.id, + 'text': ci_file.text + } + pod['configs'].append(ci_info) + diagnostic_info['pods'].append(pod) + + details = { + 'overview': overview, + 'deployment_progress': task_list, + 'pods': pod_list, + 'diagnostic_info': diagnostic_info, + 'pdf': booking.pdf + } + return JsonResponse(str(details), safe=False) |