+
+
+def prepare_notification_data(nfinstid, jobid, changetype, operation):
+ logger.info('Send notify request to nfvo')
+ affected_vnfcs = []
+ vnfcs = VNFCInstModel.objects.filter(instid=nfinstid)
+ for vnfc in vnfcs:
+ vm_resource = {}
+ if vnfc.vmid:
+ vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
+ if vm:
+ vm_resource = {
+ 'vimConnectionId': vm[0].vimid,
+ 'resourceId': vm[0].resourceid,
+ 'resourceProviderId': vm[0].vmname, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'vm'
+ }
+ affected_vnfcs.append({
+ 'id': vnfc.vnfcinstanceid,
+ 'vduId': vnfc.vduid,
+ 'changeType': changetype,
+ 'computeResource': vm_resource
+ })
+ affected_vls = []
+ networks = NetworkInstModel.objects.filter(instid=nfinstid)
+ for network in networks:
+ network_resource = {
+ 'vimConnectionId': network.vimid,
+ 'resourceId': network.resourceid,
+ 'resourceProviderId': network.name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'network'
+ }
+ affected_vls.append({
+ 'id': network.networkid,
+ 'virtualLinkDescId': network.nodeId,
+ 'changeType': changetype,
+ 'networkResource': network_resource
+ })
+ ext_connectivity = []
+ ext_connectivity_map = {}
+ ports = PortInstModel.objects.filter(instid=nfinstid)
+ for port in ports:
+ if port.networkid not in ext_connectivity_map:
+ ext_connectivity_map[port.networkid] = []
+ ext_connectivity_map[port.networkid].append({
+ 'id': port.portid, # TODO: port.portid or port.nodeid?
+ 'resourceHandle': {
+ 'vimConnectionId': port.vimid,
+ 'resourceId': port.resourceid,
+ 'resourceProviderId': port.name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'port'
+ },
+ 'cpInstanceId': port.portid # TODO: port.cpinstanceid is not initiated when create port resource.
+ })
+ for network_id, ext_link_ports in list(ext_connectivity_map.items()):
+ networks = NetworkInstModel.objects.filter(networkid=network_id)
+ net_name = networks[0].name if networks else network_id
+ network_resource = {
+ 'vimConnectionId': ext_link_ports[0]['resourceHandle']['vimConnectionId'],
+ 'resourceId': network_id,
+ 'resourceProviderId': net_name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'network'
+ }
+ ext_connectivity.append({
+ 'id': network_id,
+ 'resourceHandle': network_resource,
+ 'extLinkPorts': ext_link_ports
+ })
+ logger.debug("ext_connectivity=%s", ext_connectivity)
+ affected_vss = []
+ vss = StorageInstModel.objects.filter(instid=nfinstid)
+ for vs in vss:
+ affected_vss.append({
+ 'id': vs.storageid,
+ 'virtualStorageDescId': vs.nodeId,
+ 'changeType': changetype,
+ 'storageResource': {
+ 'vimConnectionId': vs.vimid,
+ 'resourceId': vs.resourceid,
+ 'resourceProviderId': vs.name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'volume'
+ }
+ })
+ notification_content = {
+ 'id': str(uuid.uuid4()), # shall be the same if sent multiple times due to multiple subscriptions.
+ 'notificationType': 'VnfLcmOperationOccurrenceNotification',
+ # set 'subscriptionId' after filtering for subscribers
+ 'timeStamp': now_time(),
+ 'notificationStatus': 'RESULT',
+ 'operationState': 'COMPLETED',
+ 'vnfInstanceId': nfinstid,
+ 'operation': operation,
+ 'isAutomaticInvocation': False,
+ 'vnfLcmOpOccId': jobid,
+ 'affectedVnfcs': affected_vnfcs,
+ 'affectedVirtualLinks': affected_vls,
+ 'affectedVirtualStorages': affected_vss,
+ 'changedExtConnectivity': [], # TODO: will add in R4
+ '_links': {
+ 'vnfInstance': {'href': '/api/vnflcm/v1/vnf_instances/%s' % nfinstid},
+ # set 'subscription' link after filtering for subscribers
+ 'vnfLcmOpOcc': {'href': '/api/vnflcm/v1/vnf_lcm_op_occs/%s' % jobid}
+ }
+ }
+ nfInsts = NfInstModel.objects.filter(nfinstid=nfinstid)
+ notification_content['vnfmInstId'] = nfInsts[0].vnfminstid if nfInsts[0].vnfminstid else '1'
+ logger.info('Notify request data = %s' % notification_content)
+ return notification_content