1 # Copyright (c) 2018 Amdocs
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 from rest_framework import status
17 from rest_framework.response import Response
18 from rest_framework.views import APIView
20 from multicloud_azure.pub.aria.service import AriaServiceImpl
22 logger = logging.getLogger(__name__)
25 class InfraWorkload(APIView):
27 def post(self, request, cloud_owner, cloud_region_id):
29 template_data = data["infra-template"]
30 payload = data["infra-payload"]
31 inputs = json.loads(payload)
32 template_name = inputs['template_data']['stack_name']
33 service_op = AriaServiceImpl()
35 stack = service_op.deploy_service(template_name, template_data,
38 return Response(data=stack[0], status=stack[1])
39 except Exception as e:
41 if hasattr(e, "http_status"):
42 return Response(data={'error': str(e)}, status=e.http_status)
44 return Response(data={'error': str(e)},
45 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
47 "template_type": "heat",
48 "workload_id": stack[0]
50 return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
53 class GetStackView(APIView):
55 def get(self, request, cloud_owner, cloud_region_id, workload_id):
56 service_op = AriaServiceImpl()
58 stack = service_op.show_execution(workload_id)
60 return Response(data=stack[0], status=stack[1])
61 body = json.loads(stack[0])
62 stack_status = body["status"]
64 if stack_status == "pending" or stack_status == "started":
65 response = "CREATE_IN_PROGRESS"
66 elif stack_status == "succeeded":
67 response = "CREATE_COMPLETE"
68 elif stack_status == "failed" or stack_status == "cancelled":
69 response = "CREATE_FAILED"
71 "template_type": "heat",
72 "workload_id": workload_id,
73 "workload_status": response
75 return Response(data=rsp, status=stack[1])
76 except Exception as e:
78 if hasattr(e, "http_status"):
79 return Response(data={'error': str(e)}, status=e.http_status)
81 return Response(data={'error': str(e)},
82 status=status.HTTP_500_INTERNAL_SERVER_ERROR)