summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/lcm/nf/biz/instantiate_vnf.py96
-rw-r--r--lcm/lcm/nf/biz/terminate_vnf.py95
-rw-r--r--lcm/lcm/pub/msapi/gvnfmdriver.py88
3 files changed, 103 insertions, 176 deletions
diff --git a/lcm/lcm/nf/biz/instantiate_vnf.py b/lcm/lcm/nf/biz/instantiate_vnf.py
index 753b9551..161cd7d1 100644
--- a/lcm/lcm/nf/biz/instantiate_vnf.py
+++ b/lcm/lcm/nf/biz/instantiate_vnf.py
@@ -21,7 +21,7 @@ from threading import Thread
from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, \
SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo
+from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo, prepare_notification_data
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
@@ -127,97 +127,9 @@ class InstantiateVnf(Thread):
logger.info("Create resource finish")
def lcm_notify(self):
- logger.info('Send notify request to nfvo')
- affected_vnfcs = []
- vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id)
- for vnfc in vnfcs:
- vm_resource = {}
- if vnfc.vmid:
- vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
- if vm:
- vm_resource = {
- 'vimId': vm[0].vimConnectionId,
- 'resourceId': vm[0].resouceid,
- 'resourceProviderId': vm[0].vmname,
- 'vimLevelResourceType': 'vm'
- }
- # TODO: is resourceName mapped to resourceProviderId?
- affected_vnfcs.append({
- 'id': vnfc.vnfcinstanceid,
- 'vduId': vnfc.vduid,
- 'changeType': 'ADDED',
- 'computeResource': vm_resource
- })
- affected_vls = []
- networks = NetworkInstModel.objects.filter(instid=self.nf_inst_id)
- for network in networks:
- network_resource = {
- 'vimConnectionId': network.vimid,
- 'resourceId': network.resouceid,
- 'resourceProviderId': network.name,
- 'vimLevelResourceType': 'network'
- }
- # TODO: is resourceName mapped to resourceProviderId?
- affected_vls.append({
- 'id': network.networkid,
- 'virtualLinkDescId': network.nodeId,
- 'changeType': 'ADDED',
- 'networkResource': network_resource
- })
- ext_link_ports = []
- ports = PortInstModel.objects.filter(instid=self.nf_inst_id)
- for port in ports:
- ext_link_ports.append({
- 'id': port.portid, # TODO: port.portid or port.nodeid?
- 'resourceHandle': {
- 'vimConnectionId': port.vimid,
- 'resourceId': port.resouceid,
- 'resourceProviderId': port.name,
- 'vimLevelResourceType': 'port'
- },
- # TODO: is resourceName mapped to resourceProviderId?
- 'cpInstanceId': port.cpinstanceid
- }),
- affected_vss = []
- vss = StorageInstModel.objects.filter(instid=self.nf_inst_id)
- for vs in vss:
- affected_vss.append({
- 'id': vs.storageid,
- 'virtualStorageDescId': vs.nodeId,
- 'changeType': 'ADDED',
- 'storageResource': {
- 'vimConnectionId': vs.vimid,
- 'resourceId': vs.resouceid,
- 'resourceProviderId': vs.name,
- 'vimLevelResourceType': 'volume'
- }
- })
- # TODO: is resourceName mapped to resourceProviderId?
- content_args = {
- "notificationType": 'VnfLcmOperationOccurrenceNotification',
- "notificationStatus": 'RESULT',
- "vnfInstanceId": self.nf_inst_id,
- "operation": 'INSTANTIATE',
- "vnfLcmOpOccId": self.job_id,
- 'affectedVnfcs': affected_vnfcs,
- 'affectedVirtualLinks': affected_vls,
- 'affectedVirtualStorages': affected_vss,
- 'chengedExtConnectivity': [{
- 'id': None, # TODO
- 'resourceHandle': None, # TODO
- 'extLinkPorts': ext_link_ports
- }]
- }
-
- '''
- vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
- if len(vnfmInfo) == 0:
- raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id)
- '''
- nfInsts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
- content_args['vnfmInstId'] = nfInsts[0].vnfminstid
- logger.info('Notify request data = %s' % content_args)
- resp = notify_lcm_to_nfvo(json.dumps(content_args))
+ notification_content = prepare_notification_data(self.nf_inst_id, self.job_id, "ADDED")
+ logger.info('Notify request data = %s' % notification_content)
+ resp = notify_lcm_to_nfvo(json.dumps(notification_content))
logger.info('Lcm notify end, response %s' % resp)
def vnf_inst_failed_handle(self, error_msg):
diff --git a/lcm/lcm/nf/biz/terminate_vnf.py b/lcm/lcm/nf/biz/terminate_vnf.py
index 5081422f..d63cdfa9 100644
--- a/lcm/lcm/nf/biz/terminate_vnf.py
+++ b/lcm/lcm/nf/biz/terminate_vnf.py
@@ -18,10 +18,13 @@ import traceback
from threading import Thread
from lcm.nf.const import VNF_STATUS, RESOURCE_MAP
-from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, StorageInstModel, \
- PortInstModel, VNFCInstModel, FlavourInstModel, SubNetworkInstModel
+from lcm.pub.database.models import (
+ NfInstModel, VmInstModel, NetworkInstModel,
+ StorageInstModel, PortInstModel, VNFCInstModel,
+ FlavourInstModel, SubNetworkInstModel
+)
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo
+from lcm.pub.msapi.gvnfmdriver import prepare_notification_data, notify_lcm_to_nfvo
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
@@ -94,89 +97,13 @@ class TerminateVnf(Thread):
}
def query_notify_data(self):
- logger.info('Send notify request to nfvo')
- affected_vnfcs = []
- vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id)
- for vnfc in vnfcs:
- vm_resource = {}
- if vnfc.vmid:
- vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
- if vm:
- vm_resource = {
- 'vimId': vm[0].vimid,
- 'resourceId': vm[0].resouceid,
- 'resourceProviderId': vm[0].vmname,
- 'vimLevelResourceType': 'vm'
- }
- affected_vnfcs.append({
- 'id': vnfc.vnfcinstanceid,
- 'vduId': vnfc.vduid,
- 'changeType': 'REMOVED',
- 'computeResource': vm_resource
- })
- affected_vls = []
- networks = NetworkInstModel.objects.filter(instid=self.nf_inst_id)
- for network in networks:
- network_resource = {
- 'vimConnectionId': network.vimid,
- 'resourceId': network.resouceid,
- 'resourceProviderId': network.name,
- 'vimLevelResourceType': 'network'
- }
- affected_vls.append({
- 'id': network.networkid,
- 'virtualLinkDescId': network.nodeId,
- 'changeType': 'REMOVED',
- 'networkResource': network_resource
- })
- ext_link_ports = []
- ports = PortInstModel.objects.filter(instid=self.nf_inst_id)
- for port in ports:
- ext_link_ports.append({
- 'id': port.portid,
- 'resourceHandle': {
- 'vimConnectionId': port.vimid,
- 'resourceId': port.resouceid,
- 'resourceProviderId': port.name,
- 'vimLevelResourceType': 'port'
- },
- 'cpInstanceId': port.cpinstanceid
- })
- affected_vss = []
- vss = StorageInstModel.objects.filter(instid=self.nf_inst_id)
- for vs in vss:
- affected_vss.append({
- 'id': vs.storageid,
- 'virtualStorageDescId': vs.nodeId,
- 'changeType': 'REMOVED',
- 'storageResource': {
- 'vimConnectionId': vs.vimid,
- 'resourceId': vs.resouceid,
- 'resourceProviderId': vs.name,
- 'vimLevelResourceType': 'volume'
- }
- })
+ self.notify_data = prepare_notification_data(self.nf_inst_id, self.job_id, "RMOVED")
+ NetworkInstModel.objects.filter(instid=self.nf_inst_id)
+ StorageInstModel.objects.filter(instid=self.nf_inst_id)
+ PortInstModel.objects.filter(instid=self.nf_inst_id)
+ VNFCInstModel.objects.filter(instid=self.nf_inst_id)
FlavourInstModel.objects.filter(instid=self.nf_inst_id)
SubNetworkInstModel.objects.filter(instid=self.nf_inst_id)
- self.notify_data = {
- "notificationType": 'VnfLcmOperationOccurrenceNotification',
- "notificationStatus": 'RESULT',
- "vnfInstanceId": self.nf_inst_id,
- "operation": 'TERMINATE',
- "vnfLcmOpOccId": self.job_id,
- 'affectedVnfcs': affected_vnfcs,
- 'affectedVirtualLinks': affected_vls,
- 'affectedVirtualStorages': affected_vss,
- 'chengedExtConnectivity': [{
- 'id': None, # TODO
- 'resourceHandle': None, # TODO
- 'extLinkPorts': ext_link_ports
- }]
- }
-
- vnfInsts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
- self.notify_data['vnfmInstId'] = vnfInsts[0].vnfminstid
- logger.info('Notify request data=%s' % self.notify_data)
def delete_resource(self):
logger.info('Rollback resource begin')
diff --git a/lcm/lcm/pub/msapi/gvnfmdriver.py b/lcm/lcm/pub/msapi/gvnfmdriver.py
index 5244da67..5446fa3d 100644
--- a/lcm/lcm/pub/msapi/gvnfmdriver.py
+++ b/lcm/lcm/pub/msapi/gvnfmdriver.py
@@ -17,6 +17,10 @@ import logging
from lcm.pub.exceptions import NFLCMException
from lcm.pub.utils.restcall import req_by_msb
+from lcm.pub.database.models import (
+ NfInstModel, VmInstModel, NetworkInstModel,
+ PortInstModel, StorageInstModel, VNFCInstModel
+)
logger = logging.getLogger(__name__)
@@ -43,3 +47,87 @@ def notify_lcm_to_nfvo(data):
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NFLCMException("Nf lcm notify exception")
return ret[1]
+
+
+def prepare_notification_data(nfinstid, jobid, changetype):
+ 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 = {
+ 'vimId': vm[0].vimConnectionId,
+ 'resourceId': vm[0].resouceid,
+ '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.resouceid,
+ '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_link_ports = []
+ ports = PortInstModel.objects.filter(instid=nfinstid)
+ for port in ports:
+ ext_link_ports.append({
+ 'id': port.portid, # TODO: port.portid or port.nodeid?
+ 'resourceHandle': {
+ 'vimConnectionId': port.vimid,
+ 'resourceId': port.resouceid,
+ 'resourceProviderId': port.name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'port'
+ },
+ 'cpInstanceId': port.cpinstanceid
+ }),
+ 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.resouceid,
+ 'resourceProviderId': vs.name, # TODO: is resourceName mapped to resourceProviderId?
+ 'vimLevelResourceType': 'volume'
+ }
+ })
+ notification_content = {
+ "notificationType": 'VnfLcmOperationOccurrenceNotification',
+ "notificationStatus": 'RESULT',
+ "vnfInstanceId": nfinstid,
+ "operation": 'INSTANTIATE',
+ "vnfLcmOpOccId": jobid,
+ 'affectedVnfcs': affected_vnfcs,
+ 'affectedVirtualLinks': affected_vls,
+ 'affectedVirtualStorages': affected_vss,
+ 'chengedExtConnectivity': [{
+ 'id': None, # TODO
+ 'resourceHandle': None, # TODO
+ 'extLinkPorts': ext_link_ports
+ }]
+ }
+ nfInsts = NfInstModel.objects.filter(nfinstid=nfinstid)
+ notification_content['vnfmInstId'] = nfInsts[0].vnfminstid
+ logger.info('Notify request data = %s' % notification_content)
+ return notification_content