Fix vfc-lcm vserver report bug. 57/22957/3
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 9 Nov 2017 12:58:51 +0000 (20:58 +0800)
committerFu Jinhua <fu.jinhua@zte.com.cn>
Thu, 9 Nov 2017 13:41:32 +0000 (13:41 +0000)
Change-Id: I95b4afa2482c9ab145dcd5cfc266145f40b97851
Issue-ID: VFC-589
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/vnfs/create_vnfs.py
lcm/ns/vnfs/heal_vnfs.py
lcm/ns/vnfs/notify_lcm.py
lcm/pub/msapi/extsys.py

index a2f01b3..5dba4e9 100644 (file)
@@ -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)
index 5436f51..439daa6 100644 (file)
@@ -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')
index 504be55..ee4c5ee 100644 (file)
@@ -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())
index 51673d3..d01a5b8 100644 (file)
@@ -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",