diff options
-rw-r--r-- | lcm/ns/vnfs/create_vnfs.py | 2 | ||||
-rw-r--r-- | lcm/ns/vnfs/heal_vnfs.py | 2 | ||||
-rw-r--r-- | lcm/ns/vnfs/notify_lcm.py | 45 | ||||
-rw-r--r-- | lcm/pub/msapi/extsys.py | 10 |
4 files changed, 56 insertions, 3 deletions
diff --git a/lcm/ns/vnfs/create_vnfs.py b/lcm/ns/vnfs/create_vnfs.py index a2f01b3a..5dba4e92 100644 --- a/lcm/ns/vnfs/create_vnfs.py +++ b/lcm/ns/vnfs/create_vnfs.py @@ -80,7 +80,7 @@ class CreateVnfs(Thread): self.save_info_to_db() if REPORT_TO_AAI: self.create_vnf_in_aai() - self.create_vserver_in_aai() + # self.create_vserver_in_aai() JobUtil.add_job_status(self.job_id, 100, 'vnf instantiation success', 0) except NSLCMException as e: self.vnf_inst_failed_handle(e.message) diff --git a/lcm/ns/vnfs/heal_vnfs.py b/lcm/ns/vnfs/heal_vnfs.py index 5436f510..439daa65 100644 --- a/lcm/ns/vnfs/heal_vnfs.py +++ b/lcm/ns/vnfs/heal_vnfs.py @@ -76,7 +76,7 @@ class NFHealService(threading.Thread): raise NSLCMException('additionalParams parameter does not exist or value incorrect') action = ignore_case_get(self.nf_additional_params, 'action') - if action is "restartvm": + if action == "restartvm": action = "vmReset" actionvminfo = ignore_case_get(self.nf_additional_params, 'actionvminfo') diff --git a/lcm/ns/vnfs/notify_lcm.py b/lcm/ns/vnfs/notify_lcm.py index 504be558..ee4c5ee2 100644 --- a/lcm/ns/vnfs/notify_lcm.py +++ b/lcm/ns/vnfs/notify_lcm.py @@ -23,6 +23,8 @@ from lcm.pub.exceptions import NSLCMException from lcm.pub.database.models import VNFCInstModel, VLInstModel, NfInstModel, PortInstModel, CPInstModel, VmInstModel from lcm.pub.msapi.aai import create_network_aai, query_network_aai, delete_network_aai from lcm.pub.utils.values import ignore_case_get +from lcm.pub.msapi.extsys import split_vim_to_owner_region, get_vim_by_id +from lcm.pub.msapi.aai import create_vserver_aai logger = logging.getLogger(__name__) @@ -84,6 +86,9 @@ class NotifyLcm(object): nfinstid=self.vnf_instid, vmid=vmId).save() VmInstModel(vmid=vmId, vimid=vimId, resouceid=vmId, insttype=INST_TYPE.VNF, instid=self.vnf_instid, vmname=vmName, hostid='1').save() + if REPORT_TO_AAI: + self.create_vserver_in_aai(vimId, vmId, vmName) + logger.debug("Success to create all vserver to aai.") elif changeType == 'removed': VNFCInstModel.objects.filter(vnfcinstanceid=vnfcInstanceId).delete() elif changeType == 'modified': @@ -241,3 +246,43 @@ class NotifyLcm(object): logger.debug("Fail to delete network[%s] to aai, detail message: %s" % (vlInstanceId, e.message)) except: logger.error(traceback.format_exc()) + + def create_vserver_in_aai(self, vim_id, vserver_id, vserver_name): + logger.debug("NotifyLcm::create_vserver_in_aai::report vserver instance to aai.") + try: + cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id) + + # query vim_info from aai + vim_info = get_vim_by_id(vim_id) + tenant_id = vim_info["tenantId"] + data = { + "vserver-id": vserver_id, + "vserver-name": vserver_name, + "prov-status": "ACTIVE", + "vserver-selflink": "", + "in-maint": True, + "is-closed-loop-disabled": False, + "relationship-list": { + "relationship": [ + { + "related-to": "generic-vnf", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": self.vnf_instid + } + ] + } + ] + } + } + + # create vserver instance in aai + resp_data, resp_status = create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data) + logger.debug("Success to create vserver[%s] to aai, vnf instance=[%s], resp_status: [%s]." + % (vserver_id, self.vnf_instid, resp_status)) + except NSLCMException as e: + logger.debug("Fail to create vserver to aai, vnf instance=[%s], detail message: %s" + % (self.vnf_instid, e.message)) + except: + logger.error(traceback.format_exc()) diff --git a/lcm/pub/msapi/extsys.py b/lcm/pub/msapi/extsys.py index 51673d31..d01a5b8b 100644 --- a/lcm/pub/msapi/extsys.py +++ b/lcm/pub/msapi/extsys.py @@ -61,6 +61,13 @@ def convert_vim_info(vim_info_aai): vim_id = vim_info_aai["cloud-owner"] + "_" + vim_info_aai["cloud-region-id"] esr_system_info = ignore_case_get(ignore_case_get(vim_info_aai, "esr-system-info-list"), "esr-system-info") # tenants = ignore_case_get(vim_info_aai, "tenants") + default_tenant = ignore_case_get(esr_system_info[0], "default-tenant") + tenants = ignore_case_get(ignore_case_get(vim_info_aai, "tenants"), "tenant") + tenant_id = "" + for tenant_info in tenants: + if tenant_info["tenant-name"] == default_tenant: + tenant_id = tenant_info["tenant-id"] + break vim_info = { "vimId": vim_id, "name": vim_id, @@ -68,7 +75,8 @@ def convert_vim_info(vim_info_aai): "userName": ignore_case_get(esr_system_info[0], "user-name"), "password": ignore_case_get(esr_system_info[0], "password"), # "tenant": ignore_case_get(tenants[0], "tenant-id"), - "tenant": ignore_case_get(esr_system_info[0], "default-tenant"), + "tenantId": tenant_id, + "tenant": default_tenant, "vendor": ignore_case_get(esr_system_info[0], "vendor"), "version": ignore_case_get(esr_system_info[0], "version"), "description": "vim", |