summaryrefslogtreecommitdiffstats
path: root/azure/multicloud_azure/swagger
diff options
context:
space:
mode:
Diffstat (limited to 'azure/multicloud_azure/swagger')
-rw-r--r--azure/multicloud_azure/swagger/urls.py14
-rw-r--r--azure/multicloud_azure/swagger/views/infra_workload/__init__.py11
-rw-r--r--azure/multicloud_azure/swagger/views/infra_workload/views.py82
3 files changed, 105 insertions, 2 deletions
diff --git a/azure/multicloud_azure/swagger/urls.py b/azure/multicloud_azure/swagger/urls.py
index a3de04a..dde553a 100644
--- a/azure/multicloud_azure/swagger/urls.py
+++ b/azure/multicloud_azure/swagger/urls.py
@@ -1,5 +1,4 @@
# Copyright (c) 2018 Amdocs
-# Copyright (c) 2018 Amdocs
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,13 +15,15 @@ from rest_framework.urlpatterns import format_suffix_patterns
from multicloud_azure.swagger.views.swagger_json import SwaggerJsonView
-
# Registry
from multicloud_azure.swagger.views.registry.views import Registry
from multicloud_azure.swagger.views.registry.views import UnRegistry
from multicloud_azure.swagger.views.registry.views import APIv1Registry
from multicloud_azure.swagger.views.registry.views import APIv1UnRegistry
+from multicloud_azure.swagger.views.infra_workload.views import InfraWorkload
+from multicloud_azure.swagger.views.infra_workload.views import GetStackView
+
urlpatterns = [
# swagger
url(r'^api/multicloud-azure/v0/swagger.json$', SwaggerJsonView.as_view()),
@@ -42,6 +43,15 @@ urlpatterns = [
r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)$',
APIv1UnRegistry.as_view()),
+ url(r'^api/multicloud-azure/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)'
+ r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload$',
+ InfraWorkload.as_view()),
+
+ url(r'^api/multicloud-azure/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/'
+ r'(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload/'
+ r'(?P<workload_id>[0-9a-zA-Z\-\_]+)$',
+ GetStackView.as_view()),
+
]
urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/azure/multicloud_azure/swagger/views/infra_workload/__init__.py b/azure/multicloud_azure/swagger/views/infra_workload/__init__.py
new file mode 100644
index 0000000..a952e9e
--- /dev/null
+++ b/azure/multicloud_azure/swagger/views/infra_workload/__init__.py
@@ -0,0 +1,11 @@
+# Copyright (c) 2018 Amdocs
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/azure/multicloud_azure/swagger/views/infra_workload/views.py b/azure/multicloud_azure/swagger/views/infra_workload/views.py
new file mode 100644
index 0000000..c44eba2
--- /dev/null
+++ b/azure/multicloud_azure/swagger/views/infra_workload/views.py
@@ -0,0 +1,82 @@
+# Copyright (c) 2018 Amdocs
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+import logging
+import json
+
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from multicloud_azure.pub.aria.service import AriaServiceImpl
+
+logger = logging.getLogger(__name__)
+
+
+class InfraWorkload(APIView):
+
+ def post(self, request, cloud_owner, cloud_region_id):
+ data = request.data
+ template_data = data["infra-template"]
+ payload = data["infra-payload"]
+ inputs = json.loads(payload)
+ template_name = inputs['template_data']['stack_name']
+ service_op = AriaServiceImpl()
+ try:
+ stack = service_op.deploy_service(template_name, template_data,
+ inputs, logger)
+ if stack[1] != 200:
+ return Response(data=stack[0], status=stack[1])
+ except Exception as e:
+
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ rsp = {
+ "template_type": "heat",
+ "workload_id": stack[0]
+ }
+ return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
+
+
+class GetStackView(APIView):
+
+ def get(self, request, cloud_owner, cloud_region_id, workload_id):
+ service_op = AriaServiceImpl()
+ try:
+ stack = service_op.show_execution(workload_id)
+ if stack[1] != 200:
+ return Response(data=stack[0], status=stack[1])
+ body = json.loads(stack[0])
+ stack_status = body["status"]
+ response = "unknown"
+ if stack_status == "pending" or stack_status == "started":
+ response = "CREATE_IN_PROGRESS"
+ elif stack_status == "succeeded":
+ response = "CREATE_COMPLETE"
+ elif stack_status == "failed" or stack_status == "cancelled":
+ response = "CREATE_FAILED"
+ rsp = {
+ "template_type": "heat",
+ "workload_id": workload_id,
+ "workload_status": response
+ }
+ return Response(data=rsp, status=stack[1])
+ except Exception as e:
+
+ if hasattr(e, "http_status"):
+ return Response(data={'error': str(e)}, status=e.http_status)
+ else:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)