+ logger.debug("Enter NSInstancesView::POST ns_instances: Header:%s, Body: %s" % (request.META, request.data))
+ try:
+ 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, 'nsDescription')
+ context = {
+ "globalCustomerId": globalCustomerId,
+ "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]
+ logger.debug("nsInstance: %s" % nsInstance)
+ resp_serializer = NsInstanceSerializer(data=nsInstance)
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+ 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}
+ return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
+ except Exception as e:
+ logger.error("Exception in CreateNS: %s", e.message)
+ data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message}
+ return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)