summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-15 17:39:02 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-15 17:39:02 +0800
commit7f062af4fa8adb4e8bbf2b79c9b72ab32f284cd4 (patch)
tree7bb09bdef892a621800650c8ef8d761527c1f354
parent485eca389e366c8478ab513249222a8cb6723402 (diff)
Add creation and deletion of VNF instance
Change-Id: I804056d5c3b3f8a79c3932a4bf6887777b2e8b76 Issue-ID: VFC-365 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/ns/vnfs/create_vnfs.py19
-rw-r--r--lcm/ns/vnfs/terminate_nfs.py17
-rw-r--r--lcm/pub/msapi/aai.py16
-rw-r--r--lcm/workflows/build_in.py1
4 files changed, 45 insertions, 8 deletions
diff --git a/lcm/ns/vnfs/create_vnfs.py b/lcm/ns/vnfs/create_vnfs.py
index 83bb4443..dc633f02 100644
--- a/lcm/ns/vnfs/create_vnfs.py
+++ b/lcm/ns/vnfs/create_vnfs.py
@@ -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))
diff --git a/lcm/ns/vnfs/terminate_nfs.py b/lcm/ns/vnfs/terminate_nfs.py
index 7b0b21b3..9bc0cbbd 100644
--- a/lcm/ns/vnfs/terminate_nfs.py
+++ b/lcm/ns/vnfs/terminate_nfs.py
@@ -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))
diff --git a/lcm/pub/msapi/aai.py b/lcm/pub/msapi/aai.py
index 51b13b89..25f61626 100644
--- a/lcm/pub/msapi/aai.py
+++ b/lcm/pub/msapi/aai.py
@@ -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:
diff --git a/lcm/workflows/build_in.py b/lcm/workflows/build_in.py
index 3d06984d..1d7142f1 100644
--- a/lcm/workflows/build_in.py
+++ b/lcm/workflows/build_in.py
@@ -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