+class QuerySingleVnfLcmOpOcc(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: VNFLCMOpOccSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ""
+ }
+ )
+ def get(self, request, vnfmtype, vnfmid, lcmopoccid):
+ logger.debug("[%s]LCMOpOccId = %s", fun_name(), lcmopoccid)
+ try:
+ vnfm_info = get_vnfminfo_from_nslcm(vnfmid)
+ logger.debug("[get lcm op occ] vnfm_info=[%s]", vnfm_info)
+ ret = call_vnfm("api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid, "GET", vnfm_info)
+ if ret[0] != 0:
+ logger.error("Status code is %s. detail is %s.", ret[2], ret[1])
+ raise GvnfmDriverException("Failed to query vnf lcm op occ %s" % lcmopoccid)
+ resp_data = json.JSONDecoder().decode(ret[1])
+ vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data)
+ if vnf_lcm_op_occ_serializer.is_valid():
+ logger.debug("[%s]resp_data=%s" % (fun_name(), resp_data))
+ return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK)
+ else:
+ raise GvnfmDriverException(vnf_lcm_op_occ_serializer.errors)
+ except GvnfmDriverException as e:
+ logger.error("Query vnflcmopocc failed, detail message: %s" % e.message)
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': traceback.format_exc()}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+class Subscription(APIView):
+ @swagger_auto_schema(
+ request_body=LccnSubscriptionRequestSerializer(),
+ responses={
+ status.HTTP_201_CREATED: LccnSubscriptionSerializer(),
+ status.HTTP_303_SEE_OTHER: None,
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR"
+ }
+ )
+ def post(self, request, vnfmtype):
+ logger.debug("Subscription--post::> %s" % request.data)
+ logger.debug("Subscription begin!")
+ try:
+ lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)
+ if not lccn_subscription_request_serializer.is_valid():
+ raise GvnfmDriverException(lccn_subscription_request_serializer.error_messages)
+ resp_data = do_subscription(request.data)
+ lccn_subscription_serializer = LccnSubscriptionSerializer(data=resp_data)
+ if not lccn_subscription_serializer.is_valid():
+ logger.debug("[%s]resp_data=%s" % (fun_name(), resp_data))
+ raise GvnfmDriverException(lccn_subscription_serializer.errors)
+ logger.debug("Subscription end!")
+ return Response(data=lccn_subscription_serializer.data, status=status.HTTP_201_CREATED)
+ except GvnfmDriverException as e:
+ logger.error(e.message)
+ return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+