fix swagger error
[vfc/nfvo/lcm.git] / lcm / ns / views / sol / ns_instances_views.py
index cc83243..6fcae3f 100644 (file)
@@ -27,6 +27,7 @@ from lcm.pub.utils.values import ignore_case_get
 from lcm.ns.biz.ns_create import CreateNSService
 from lcm.ns.biz.ns_get import GetNSInfoService
 from lcm.ns.biz.ns_delete import DeleteNsService
+from lcm.ns.const import NS_INSTANCE_BASE_URI
 
 logger = logging.getLogger(__name__)
 
@@ -68,27 +69,32 @@ class NSInstancesView(APIView):
             globalCustomerId = request.META.get("HTTP_GLOBALCUSTOMERID", None)
             if not globalCustomerId:
                 raise BadRequestException("Not found globalCustomerId in header")
+            serviceType = request.META.get("HTTP_SERVICETYPE", None)
+            if not serviceType:
+                serviceType = "NetworkService"
             req_serializer = CreateNsRequestSerializer(data=request.data)
             if not req_serializer.is_valid():
                 raise BadRequestException(req_serializer.errors)
-
             if ignore_case_get(request.data, 'test') == "test":
                 return Response(data={'nsInstanceId': "test"}, status=status.HTTP_201_CREATED)
             csar_id = ignore_case_get(request.data, 'nsdId')
             ns_name = ignore_case_get(request.data, 'nsName')
-            description = ignore_case_get(request.data, 'description')
+            description = ignore_case_get(request.data, 'nsDescription')
             context = {
                 "globalCustomerId": globalCustomerId,
-                "serviceType": "NetworkService"
+                "serviceType": serviceType
             }
             ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz()
             logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id)
             ns_filter = {"ns_inst_id": ns_inst_id}
-            nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0]  # todo
+            nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0]
+            logger.debug("nsInstance: %s" % nsInstance)
             resp_serializer = NsInstanceSerializer(data=nsInstance)
             if not resp_serializer.is_valid():
                 raise NSLCMException(resp_serializer.errors)
-            return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
+            response = Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
+            response["Location"] = NS_INSTANCE_BASE_URI % nsInstance['id']
+            return response
         except BadRequestException as e:
             logger.error("Exception in CreateNS: %s", e.message)
             data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message}
@@ -129,7 +135,7 @@ class IndividualNsInstanceView(APIView):
     @swagger_auto_schema(
         request_body=None,
         responses={
-            status.HTTP_204_NO_CONTENT: None
+            status.HTTP_204_NO_CONTENT: "HTTP_204_NO_CONTENT"
         }
     )
     def delete(self, request, ns_instance_id):