1 # Copyright 2018 ZTE Corporation.
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.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from rest_framework.response import Response
18 from rest_framework.views import APIView
19 from rest_framework import status
20 from drf_yasg.utils import swagger_auto_schema
22 from lcm.v2.serializers import GrantRequestSerializer
23 from lcm.v2.serializers import GrantSerializer
24 from lcm.v2.grant_vnf import GrantVnf
26 logger = logging.getLogger(__name__)
29 class VnfGrantView(APIView):
31 request_body=GrantRequestSerializer(),
33 status.HTTP_201_CREATED: GrantSerializer(
34 help_text="The grant was created successfully (synchronous mode)."
36 status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
39 def post(self, request):
40 logger.debug("VnfGrantView Post: %s" % request.data)
42 req_serializer = GrantRequestSerializer(data=request.data)
43 if not req_serializer.is_valid():
44 raise Exception(req_serializer.errors)
46 grant_resp = GrantVnf(request.data).exec_grant()
48 resp_serializer = GrantSerializer(data=grant_resp)
49 if not resp_serializer.is_valid():
50 raise Exception(resp_serializer.errors)
52 return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
53 except Exception as e:
54 logger.error(traceback.format_exc())
55 logger.error("Exception in VnfGrant: %s", e.message)
56 return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
59 class VnfNotifyView(APIView):
60 def post(self, request):
61 logger.debug("VnfNotifyView post: %s" % request.data)
62 return Response(data={}, status=status.HTTP_204_NO_CONTENT)
64 def get(self, request):
65 logger.debug("VnfNotifyView get")
66 return Response(data={}, status=status.HTTP_204_NO_CONTENT)