diff options
-rw-r--r-- | src/api/urls.py | 17 | ||||
-rw-r--r-- | 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/<int:template_id>/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 """ |