-# Notify LCM Events
-notify_url = 'api/nslcm/v1/ns/{vnfmid}/vnfs/{vnfInstanceId}/Notify'
-notify_param_map = {
- "NFVOID": "",
- "VNFMID": "VNFMID",
- "VIMID": "vimid",
- "VNFInstanceID": "vnfInstanceId",
- "TimeStamp": "",
- "EventType": "operation",
- "VMList": "",
- "VMFlavor": "",
- "VMNumber": "",
- "VMIDlist": "",
- "VMUUID": ""
-}
-
-
-@api_view(http_method_names=['POST'])
-def notify(request, *args, **kwargs):
- try:
- logger.info("[%s]req_data = %s", fun_name(), request.data)
- data = mapping_conv(notify_param_map, request.data)
- logger.info("[%s]data = %s", fun_name(), data)
-
- data["status"] = "result"
- data["jobId"] = "notMust"
- data["affectedVnfc"] = []
- data["affectedVl"] = []
- data["affectedVirtualStorage"] = []
- data["affectedCp"] = []
-
- extension = ignorcase_get(request.data, "extension")
- openo_notification = ignorcase_get(extension, "openo_notification")
- if openo_notification:
- affectedvnfcs = ignorcase_get(openo_notification, "affectedVnfc")
- else:
- affectedvnfcs = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedvnfc")
-
- affectedvls = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedvl")
- affectedcps = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedcp")
- vnfdmodule = ignorcase_get(ignorcase_get(request.data, "extension"), "vnfdmodule")
-
- data["vnfdmodule"] = vnfdmodule
-
- for affectedvnfc in affectedvnfcs:
- data["affectedVnfc"].append({
- "vnfcInstanceId": ignorcase_get(affectedvnfc, "vnfcInstanceId"),
- "vduId": ignorcase_get(affectedvnfc, "vduId"),
- "changeType": ignorcase_get(affectedvnfc, "changeType"),
- "vimid": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "vimId"),
- "vmId": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "resourceId"),
- "vmName": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "resourceName")
- })
-
- for affectedvl in affectedvls:
- data["affectedVl"].append({
- "vlInstanceId": ignorcase_get(affectedvl, "virtuallinkinstanceid"),
- "vimid": ignorcase_get(ignorcase_get(affectedvl, "networkresource"), "vimid"),
- "vldid": ignorcase_get(affectedvl, "virtuallinkdescid"),
- "vllid": ignorcase_get(ignorcase_get(affectedvl, "networkresource"), "resourceid"),
- "vlName": ignorcase_get(ignorcase_get(affectedvl, "networkresource"), "resourcename")
- })
-
- for affectedcp in affectedcps:
- data["affectedCp"].append(affectedcp)
- # {
- # "virtualLinkInstanceId": ignorcase_get(affectedcp, "virtuallinkinstanceid"),
- # "ownerId": ignorcase_get(affectedcp, "ownerId"),
- # "ownerType": ignorcase_get(affectedcp, "ownerType")
- # }
- ret = req_by_msb(notify_url.format(vnfmid=ignorcase_get(data, 'VNFMID'),
- vnfInstanceId=ignorcase_get(data, 'vnfinstanceid')),
- "POST", content=json.JSONEncoder().encode(data))
-
- logger.info("[%s]data = %s", fun_name(), ret)
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- except Exception as e:
- logger.error("Error occurred in LCM notification.")
- logger.error(traceback.format_exc())
- raise e
- return Response(data=None, status=ret[2])
-
-
-nf_scaling_url = '/v1/vnfs/{vnfInstanceID}/scale'
-
-
-@api_view(http_method_names=['POST'])
-def scale(request, *args, **kwargs):
- logger.info("====scale_vnf===")
- try:
- logger.info("request.data = %s", request.data)
- logger.info("requested_url = %s", request.get_full_path())
- vnfm_id = ignorcase_get(kwargs, "vnfmid")
- nf_instance_id = ignorcase_get(kwargs, "vnfInstanceId")
- ret = get_vnfminfo_from_nslcm(vnfm_id)
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- vnfm_info = json.JSONDecoder().decode(ret[1])
- scale_type = ignorcase_get(request.data, "type")
- aspect_id = ignorcase_get(request.data, "aspectId")
- number_of_steps = ignorcase_get(request.data, "numberOfSteps")
- # extension = ignorcase_get(request.data, "additionalParam")
- # vnfd_model = ignorcase_get(extension, "vnfdModel")
- data = {
- 'vnfmid': vnfm_id,
- 'nfvoid': 1,
- 'scaletype': '0' if scale_type == 'SCALE_OUT' else '1',
- 'vmlist': [{'VMNumber': number_of_steps, 'VMFlavor': aspect_id}],
- 'extension': ''
+class Notify(APIView):
+ @swagger_auto_schema(
+ request_body=NotifyReqSerializer()
+ )
+ def post(self, request):
+ try:
+ logger.info("[%s]req_data = %s", fun_name(), request.data)
+ notify_param_map = {
+ "NFVOID": "",
+ "VNFMID": "VNFMID",
+ "VIMID": "vimid",
+ "VNFInstanceID": "vnfInstanceId",
+ "TimeStamp": "",
+ "EventType": "operation",
+ "VMList": "",
+ "VMFlavor": "",
+ "VMNumber": "",
+ "VMIDlist": "",
+ "VMUUID": ""
+ }
+ data = mapping_conv(notify_param_map, request.data)
+ logger.info("[%s]data = %s", fun_name(), data)
+
+ data["status"] = "result"
+ data["jobId"] = "notMust"
+ data["affectedVnfc"] = []
+ data["affectedVl"] = []
+ data["affectedVirtualStorage"] = []
+ data["affectedCp"] = []
+
+ extension = ignorcase_get(request.data, "extension")
+ openo_notification = ignorcase_get(extension, "openo_notification")
+ if openo_notification:
+ affectedvnfcs = ignorcase_get(openo_notification, "affectedVnfc")
+ affectedvls = ignorcase_get(openo_notification, "affectedvirtuallink")
+ affectedcps = ignorcase_get(openo_notification, "affectedCp")
+ vnfdmodule = ignorcase_get(openo_notification, "vnfdmodule")
+ else:
+ affectedvnfcs = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedvnfc")
+ affectedvls = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedvl")
+ affectedcps = ignorcase_get(ignorcase_get(request.data, "extension"), "affectedcp")
+ vnfdmodule = ignorcase_get(ignorcase_get(request.data, "extension"), "vnfdmodule")
+
+ data["vnfdmodule"] = vnfdmodule
+
+ for affectedvnfc in affectedvnfcs:
+ data["affectedVnfc"].append({
+ "vnfcInstanceId": ignorcase_get(affectedvnfc, "vnfcInstanceId"),
+ "vduId": ignorcase_get(affectedvnfc, "vduId"),
+ "changeType": ignorcase_get(affectedvnfc, "changeType"),
+ "vimId": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "vimId"),
+ "vmId": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "resourceId"),
+ "vmName": ignorcase_get(ignorcase_get(affectedvnfc, "computeResource"), "resourceName")
+ })
+
+ for affectedvl in affectedvls:
+ data["affectedVl"].append({
+ "vlInstanceId": ignorcase_get(affectedvl, "virtualLinkInstanceId"),
+ "changeType": ignorcase_get(affectedvl, "changeType"),
+ "vimId": ignorcase_get(ignorcase_get(affectedvl, "networkResource"), "vimId"),
+ "vldId": ignorcase_get(affectedvl, "virtuallinkdescid"),
+ "networkResource": {
+ "resourceType": "network",
+ "resourceId": ignorcase_get(ignorcase_get(affectedvl, "networkresource"), "resourceid"),
+ "resourceName": ignorcase_get(ignorcase_get(affectedvl, "networkresource"), "resourcename")
+ }
+ })
+
+ for affectedcp in affectedcps:
+ data["affectedCp"].append(affectedcp)
+
+ notify_url = 'api/nslcm/v1/ns/{vnfmid}/vnfs/{vnfInstanceId}/Notify'
+ ret = req_by_msb(notify_url.format(vnfmid=ignorcase_get(data, 'VNFMID'),
+ vnfInstanceId=ignorcase_get(data, 'vnfinstanceid')),
+ "POST", content=json.JSONEncoder().encode(data))
+
+ logger.info("[%s]data = %s", fun_name(), ret)
+ if ret[0] != 0:
+ return Response(data={'error': ret[1]}, status=ret[2])
+ return Response(data=None, status=ret[2])
+ except Exception as e:
+ logger.error("Error occurred in LCM notification.")
+ logger.error(traceback.format_exc())
+ raise e
+
+
+class Scale(APIView):
+ @swagger_auto_schema(
+ request_body=ScaleReqSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: InstScaleHealRespSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"