Create/delete vfc extern network to aai 25/18125/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 11 Oct 2017 03:20:30 +0000 (11:20 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Wed, 11 Oct 2017 03:20:30 +0000 (11:20 +0800)
Change-Id: Ib4007338b95f147ce723f59a92dfcdca84547308
Issue-ID: VFC-522
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/vls/create_vls.py
lcm/ns/vls/delete_vls.py

index 1d89c3d..9d33838 100644 (file)
@@ -18,9 +18,11 @@ import traceback
 import uuid
 
 from lcm.ns.const import OWNER_TYPE
+from lcm.pub.config.config import REPORT_TO_AAI
 from lcm.pub.database.models import VLInstModel, NSInstModel, VNFFGInstModel
 from lcm.pub.exceptions import NSLCMException
 from lcm.pub.msapi import extsys, resmgr
+from lcm.pub.msapi.aai import create_network_aai
 from lcm.pub.nfvi.vim import const
 from lcm.pub.nfvi.vim import vimadaptor
 from lcm.pub.utils.values import ignore_case_get
@@ -54,6 +56,8 @@ class CreateVls(object):
             self.create_vl_to_vim()
             self.create_vl_to_resmgr()
             self.save_vl_to_db()
+            if REPORT_TO_AAI:
+                self.create_network_in_aai()
             return {"result": 0, "detail": "instantiation vl success", "vlId": self.vl_inst_id}
         except NSLCMException as e:
             return self.exception_handle(e)
@@ -132,13 +136,6 @@ class CreateVls(object):
             raise NSLCMException("Send post vl request to vim failed.")
         return vl_ret[1]
 
-    def save_vl_to_db(self):
-        VLInstModel(vlinstanceid=self.vl_inst_id, vldid=self.vld_id, vlinstancename=self.vl_inst_name,
-                    ownertype=self.owner_type, ownerid=self.owner_id, relatednetworkid=self.related_network_id,
-                    relatedsubnetworkid=self.related_subnetwork_id, vimid=self.vim_id, tenant=self.tenant).save()
-        # do_biz_with_share_lock("create-vllist-in-vnffg-%s" % self.owner_id, self.create_vl_inst_id_in_vnffg)
-        self.create_vl_inst_id_in_vnffg()
-
     def create_vl_to_resmgr(self):
         req_param = {
             "vlInstanceId": self.vl_inst_id,
@@ -189,3 +186,39 @@ class CreateVls(object):
                     vl_inst_id_str = vl_inst_id_str[:-1]
                     VNFFGInstModel.objects.filter(vnffgdid=vnffg_info["vnffg_id"], nsinstid=self.owner_id).update(
                         vllist=vl_inst_id_str)
+
+    def save_vl_to_db(self):
+        VLInstModel(vlinstanceid=self.vl_inst_id, vldid=self.vld_id, vlinstancename=self.vl_inst_name,
+                    ownertype=self.owner_type, ownerid=self.owner_id, relatednetworkid=self.related_network_id,
+                    relatedsubnetworkid=self.related_subnetwork_id, vimid=self.vim_id, tenant=self.tenant).save()
+        # do_biz_with_share_lock("create-vllist-in-vnffg-%s" % self.owner_id, self.create_vl_inst_id_in_vnffg)
+        self.create_vl_inst_id_in_vnffg()
+
+    def create_network_in_aai(self):
+        logger.debug("CreateVls::create_network_in_aai::report network[%s] to aai." % self.vl_inst_id)
+        data = {
+            "network-id": self.vl_inst_id,
+            "network-name": self.vl_inst_name,
+            "is-bound-to-vpn": "false",
+            "is-provider-network": "true",
+            "is-shared-network": "true",
+            "is-external-network": "true",
+            "relationship-list": {
+                "relationship": [
+                    {
+                        "related-to": "generic-vnf",
+                        "relationship-data": [
+                            {
+                                "relationship-key": "generic-vnf.vnf-id",
+                                "relationship-value": self.owner_id
+                            }
+                        ]
+                    }
+                ]
+            }
+        }
+        resp_data, resp_status = create_network_aai(self.vl_inst_id, data)
+        if resp_data:
+            logger.debug("Fail to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
+        else:
+            logger.debug("Success to create network[%s] to aai: [%s].", self.vl_inst_id, resp_status)
index d2d8640..4ed7bc8 100644 (file)
 import logging
 import traceback
 
+from lcm.pub.config.config import REPORT_TO_AAI
 from lcm.pub.database.models import VLInstModel, VNFFGInstModel
 from lcm.pub.exceptions import NSLCMException
 from lcm.pub.msapi import resmgr, extsys
+from lcm.pub.msapi.aai import query_network_aai, delete_network_aai
 from lcm.pub.nfvi.vim import vimadaptor
 
 logger = logging.getLogger(__name__)
@@ -40,6 +42,8 @@ class DeleteVls(object):
             network_id = vl_inst_info[0].relatednetworkid
             self.delete_vl_from_vim(vim_id, subnetwork_id_list, network_id)
             self.delete_vl_from_resmgr()
+            if REPORT_TO_AAI:
+                self.delete_network_in_aai()
             self.delete_vl_from_db(vl_inst_info)
             return {"result": 0, "detail": "delete vl success"}
         except NSLCMException as e:
@@ -67,11 +71,6 @@ class DeleteVls(object):
             vim_api.delete_subnet(subnet_id=subnetwork_id)
         vim_api.delete_network(network_id=network_id)
 
-    def delete_vl_from_db(self, vl_inst_info):
-        # do_biz_with_share_lock("delete-vllist-in-vnffg-%s" % self.ns_inst_id, self.delete_vl_inst_id_in_vnffg)
-        self.delete_vl_inst_id_in_vnffg()
-        vl_inst_info.delete()
-
     def delete_vl_from_resmgr(self):
         resmgr.delete_vl(self.vl_inst_id)
 
@@ -83,3 +82,22 @@ class DeleteVls(object):
                     new_vl_id_list += old_vl_id + ","
             new_vl_id_list = new_vl_id_list[:-1]
             VNFFGInstModel.objects.filter(vnffginstid=vnffg_info.vnffginstid).update(vllist=new_vl_id_list)
+
+    def delete_network_in_aai(self):
+        logger.debug("DeleteVls::delete_network_in_aai::delete network[%s] in aai." % self.vl_inst_id)
+
+        # query network in aai, get resource_version
+        customer_info = query_network_aai(self.vl_inst_id)
+        resource_version = customer_info["resource-version"]
+
+        # delete network from aai
+        resp_data, resp_status = delete_network_aai(self.vl_inst_id, resource_version)
+        if resp_data:
+            logger.debug("Fail to delete network[%s] from aai, resp_status: [%s]." % (self.vl_inst_id, resp_status))
+        else:
+            logger.debug("Success to delete network[%s] from aai, resp_status: [%s]." % (self.vl_inst_id, resp_status))
+
+    def delete_vl_from_db(self, vl_inst_info):
+        # do_biz_with_share_lock("delete-vllist-in-vnffg-%s" % self.ns_inst_id, self.delete_vl_inst_id_in_vnffg)
+        self.delete_vl_inst_id_in_vnffg()
+        vl_inst_info.delete()