aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2021-10-29 15:27:32 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2021-11-01 18:20:57 -0400
commit3049353a78d9de97be514fde8d753e311737f9d3 (patch)
tree9b4700158af79a6b1ada3be617dfa1cc5ffa1f15 /src
parent23d35dc2c56b8c2b5496b6f0a5fc62066b22bbc7 (diff)
Start adding cloud config support to booking api
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu> Change-Id: Idbad76db40b08e41cdc41789b487c9d476852c57 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src')
-rw-r--r--src/api/urls.py17
-rw-r--r--src/api/views.py19
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
"""