Add creation and deletion of VNF instance 93/12693/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Fri, 15 Sep 2017 09:39:02 +0000 (17:39 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Fri, 15 Sep 2017 09:39:02 +0000 (17:39 +0800)
Change-Id: I804056d5c3b3f8a79c3932a4bf6887777b2e8b76
Issue-ID: VFC-365
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/vnfs/create_vnfs.py
lcm/ns/vnfs/terminate_nfs.py
lcm/pub/msapi/aai.py
lcm/workflows/build_in.py

index 83bb444..dc633f0 100644 (file)
@@ -22,6 +22,7 @@ from lcm.ns.vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND, INST_TYP
 from lcm.ns.vnfs.wait_job import wait_job_finish
 from lcm.pub.database.models import NfPackageModel, NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel
 from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.aai import create_vnf_aai
 from lcm.pub.msapi.extsys import get_vnfm_by_id
 from lcm.pub.msapi.resmgr import create_vnf, create_vnf_creation_info
 from lcm.pub.msapi.vnfmdriver import send_nf_init_request
@@ -75,6 +76,7 @@ class CreateVnfs(Thread):
             self.wait_vnfm_job_finish()
             self.write_vnf_creation_info()
             self.save_info_to_db()
+            self.create_vnf_in_aai()
         except NSLCMException as e:
             self.vnf_inst_failed_handle(e.message)
         except Exception:
@@ -265,3 +267,20 @@ class CreateVnfs(Thread):
                 raise NSLCMException('Vnffg instance not exist.')
             vnf_list = vnffg_inst_infos[0].vnflist
             vnffg_inst_infos.update(vnf_list=vnf_list + ',' + self.nf_inst_id if vnf_list else self.nf_inst_id)
+
+
+    def create_vnf_in_aai(self):
+        logger.debug("CreateVnfs::create_vnf_in_aai::report vnf instance[%s] to aai." % self.nf_inst_id)
+        data = {
+            "vnf-id": self.nf_inst_id,
+            "vnf-name": self.vnf_inst_name,
+            "vnf-type": "vnf-type-test111",
+            "service-id": self.ns_inst_id,
+            "in-maint": True,
+            "is-closed-loop-disabled": False
+        }
+        resp_data, resp_status = create_vnf_aai(self.nf_inst_id, data)
+        if resp_data:
+            logger.debug("Fail to create vnf instance[%s] to aai, resp_status: [%s]." % (self.nf_inst_id, resp_status))
+        else:
+            logger.debug("Success to create vnf instance[%s] to aai, resp_status: [%s]." % (self.nf_inst_id, resp_status))
index 7b0b21b..9bc0cbb 100644 (file)
@@ -20,6 +20,7 @@ import threading
 from lcm.ns.vnfs.wait_job import wait_job_finish
 from lcm.pub.database.models import NfInstModel
 from lcm.ns.vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND
+from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil
 from lcm.pub.exceptions import NSLCMException
@@ -48,6 +49,7 @@ class TerminateVnfs(threading.Thread):
             self.wait_vnfm_job_finish()
             self.send_terminate_vnf_to_resMgr()
             self.delete_data_from_db()
+            self.delete_vnf_in_aai()
         except NSLCMException as e:
             self.exception(e.message)
         except Exception:
@@ -123,3 +125,18 @@ class TerminateVnfs(threading.Thread):
     def delete_data_from_db(self):
         NfInstModel.objects.filter(nfinstid=self.vnf_inst_id).delete()
         JobUtil.add_job_status(self.job_id, 100, 'vnf terminate success', 0)
+
+    def delete_vnf_in_aai(self):
+        logger.debug("TerminateVnfs::delete_vnf_in_aai::delete vnf instance[%s] in aai." % self.vnf_inst_id)
+
+        # query vnf instance in aai, get resource_version
+        customer_info = query_vnf_aai(self.vnf_inst_id)
+        resource_version = customer_info["resource-version"]
+
+        # delete vnf instance from aai
+        resp_data, resp_status = delete_vnf_aai(self.vnf_inst_id, resource_version)
+        if resp_data:
+            logger.debug("Fail to delete vnf instance[%s] from aai, resp_status: [%s]." % (self.vnf_inst_id, resp_status))
+        else:
+            logger.debug(
+                "Success to delete vnf instance[%s] from aai, resp_status: [%s]." % (self.vnf_inst_id, resp_status))
index 51b13b8..25f6162 100644 (file)
@@ -76,7 +76,7 @@ def create_ns_aai(global_customer_id, service_type, service_instance_id, data):
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
         raise NSLCMException("Ns instance creation exception in AAI")
-    return json.JSONDecoder().decode(ret[1])
+    return json.JSONDecoder().decode(ret[1]), ret[2]
 
 def delete_ns_aai(global_customer_id, service_type, service_instance_id, resource_version=""):
     resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
@@ -92,7 +92,7 @@ def delete_ns_aai(global_customer_id, service_type, service_instance_id, resourc
 
 def query_ns_aai(global_customer_id, service_type, service_instance_id, data):
     resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
-               "%s/service-instances/service-instance/%s" % \
+               "%s/service-instances/service-instance/%s?depth=all" % \
                (global_customer_id, service_type, service_instance_id)
     ret = call_aai(resource, "GET", data)
     if ret[0] != 0:
@@ -106,7 +106,7 @@ def create_vnf_aai(vnf_id, data):
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
         raise NSLCMException("Vnf instance creation exception in AAI")
-    return json.JSONDecoder().decode(ret[1])
+    return json.JSONDecoder().decode(ret[1]), ret[2]
 
 def delete_vnf_aai(vnf_id, resource_version=""):
     resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
@@ -118,9 +118,9 @@ def delete_vnf_aai(vnf_id, resource_version=""):
         raise NSLCMException("Vnf instance delete exception in AAI")
     return json.JSONDecoder().decode(ret[1])
 
-def query_vnf_aai(vnf_id, data):
-    resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
-    ret = call_aai(resource, "GET", data)
+def query_vnf_aai(vnf_id):
+    resource = "/network/generic-vnfs/generic-vnf/%s?depth=all" % vnf_id
+    ret = call_aai(resource, "GET")
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
         raise NSLCMException("Vnf instance query exception in AAI")
@@ -134,7 +134,7 @@ def create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
         raise NSLCMException("Vserver creation exception in AAI")
-    return json.JSONDecoder().decode(ret[1])
+    return json.JSONDecoder().decode(ret[1]), ret[2]
 
 def delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, resource_version=""):
     resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
@@ -150,7 +150,7 @@ def delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, reso
 
 def query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
     resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
-               "%s/tenants/tenant/%s/vservers/vserver/%s" % \
+               "%s/tenants/tenant/%s/vservers/vserver/%s?depth=all" % \
                (cloud_owner, cloud_region_id, tenant_id, vserver_id)
     ret = call_aai(resource, "GET", data)
     if ret[0] != 0:
index 3d06984..1d7142f 100644 (file)
@@ -11,6 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import json
 import logging
 import traceback
 from threading import Thread