create NS
[vfc/nfvo/lcm.git] / lcm / ns / views / deprecated / inst_ns_view.py
1 # Copyright 2016-2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 import logging
15
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
20
21 from lcm.ns.biz.ns_instant import InstantNSService
22 from lcm.ns.serializers.inst_ns_serializers import InstantNsReqSerializer
23 from lcm.ns.serializers.pub_serializers import NsOperateJobSerializer
24
25 logger = logging.getLogger(__name__)
26
27
28 class NSInstView(APIView):
29     @swagger_auto_schema(
30         request_body=InstantNsReqSerializer(),
31         responses={
32             status.HTTP_200_OK: NsOperateJobSerializer(),
33             status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
34         }
35     )
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         logger.debug("Leave NSInstView::post::ack=%s", ack)
46         return Response(data=ack['data'], status=ack['status'])