1 # Copyright 2016-2017 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.
16 from rest_framework import status
17 from rest_framework.response import Response
18 from rest_framework.views import APIView
19 from drf_yasg.utils import swagger_auto_schema
21 from lcm.ns.biz.ns_instant import InstantNSService
22 from lcm.ns.serializers.ns_serializers import InstantNsReqSerializer
23 from lcm.ns.serializers.ns_serializers import NsOperateJobSerializer
25 logger = logging.getLogger(__name__)
28 class NSInstView(APIView):
30 request_body=InstantNsReqSerializer(),
32 status.HTTP_200_OK: NsOperateJobSerializer(),
33 status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
36 def post(self, request, ns_instance_id):
37 logger.debug("Enter NSInstView::post::ns_instance_id=%s", ns_instance_id)
38 logger.debug("request.data=%s", request.data)
39 req_serializer = InstantNsReqSerializer(data=request.data)
40 if not req_serializer.is_valid():
41 logger.debug("request.data is not valid,error: %s" % req_serializer.errors)
42 return Response({'error': req_serializer.errors},
43 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
44 ack = InstantNSService(ns_instance_id, request.data).do_biz()
45 resp_serializer = NsOperateJobSerializer(data=ack['data'])
46 if not resp_serializer.is_valid():
47 return Response({'error': resp_serializer.errors},
48 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
49 logger.debug("Leave NSInstView::post::ack=%s", ack)
50 return Response(data=resp_serializer.data, status=ack['status'])