From 3049353a78d9de97be514fde8d753e311737f9d3 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Fri, 29 Oct 2021 15:27:32 -0400 Subject: [PATCH] Start adding cloud config support to booking api Signed-off-by: Sawyer Bergeron Change-Id: Idbad76db40b08e41cdc41789b487c9d476852c57 Signed-off-by: Sawyer Bergeron --- src/api/urls.py | 17 ++++++++++------- src/api/views.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/api/urls.py b/src/api/urls.py index 3693979..acef947 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -46,13 +46,6 @@ from api.views import ( lab_user, GenerateTokenView, analytics_job, - resource_ci_metadata, - resource_ci_userdata, - resource_ci_userdata_directory, - all_images, - all_opsyss, - single_image, - single_opsys, user_bookings, specific_booking, extend_booking, @@ -61,6 +54,14 @@ from api.views import ( all_users, images_for_template, available_templates, + resource_ci_metadata, + resource_ci_userdata, + resource_ci_userdata_directory, + all_images, + all_opsyss, + single_image, + single_opsys, + create_ci_file, ) urlpatterns = [ @@ -96,6 +97,8 @@ urlpatterns = [ path('resource_inventory/availableTemplates', available_templates), path('resource_inventory//images', images_for_template), + path('resource_inventory/cloud/create', create_ci_file), + path('users', all_users), path('labs', list_labs), diff --git a/src/api/views.py b/src/api/views.py index 84d19cc..a10b3ec 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -606,6 +606,25 @@ def all_users(request): return JsonResponse(users, safe=False) +def create_ci_file(request): + token = auth_and_log(request, 'booking/makeCloudConfig') + + if isinstance(token, HttpResponse): + return token + + try: + cconf = request.body + d = yaml.load(cconf) + if not (type(d) is dict): + raise Exception() + + cconf = CloudInitFile.create(text=cconf, priority=CloudInitFile.objects.count()) + + return JsonResponse({"id": cconf.id}) + except Exception: + return JsonResponse({"error": "Provided config file was not valid yaml or was not a dict at the top level"}) + + """ Lab API Views """ -- 2.16.6