diff options
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py | 19 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py | 40 | ||||
-rw-r--r-- | lcm/lcm/pub/msapi/aai.py | 22 |
3 files changed, 53 insertions, 28 deletions
diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py index b3dee2f4..5730b6c1 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py @@ -16,7 +16,7 @@ import logging from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel from lcm.pub.exceptions import NFLCMException -from lcm.pub.msapi.aai import delete_vnf +from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai logger = logging.getLogger(__name__) @@ -38,8 +38,23 @@ class DeleteVnf: NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete() NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete() - delete_vnf(self.nf_inst_id) + self.delete_vnf_in_aai() except NFLCMException as e: logger.debug('Delete VNF instance[%s] from AAI failed' % self.nf_inst_id) except: logger.debug('Delete VNF instance[%s] failed' % self.nf_inst_id) + + def delete_vnf_in_aai(self): + logger.debug("DeleteVnf::delete_vnf_in_aai::delete vnf instance[%s] in aai." % self.nf_inst_id) + + # query vnf instance in aai, get resource_version + customer_info = query_vnf_aai(self.nf_inst_id) + resource_version = customer_info["resource-version"] + + # delete vnf instance from aai + resp_data, resp_status = delete_vnf_aai(self.nf_inst_id, resource_version) + if resp_data: + logger.debug("Fail to delete vnf instance[%s] from aai, resp_status: [%s]." % (self.nf_inst_id, resp_status)) + else: + logger.debug( + "Success to delete vnf instance[%s] from aai, resp_status: [%s]." % (self.nf_inst_id, resp_status)) diff --git a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py index b1b87c4b..495be6e2 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py @@ -18,7 +18,7 @@ import uuid from lcm.pub.database.models import NfInstModel from lcm.pub.exceptions import NFLCMException -from lcm.pub.msapi.aai import create_vnf +from lcm.pub.msapi.aai import create_vnf_aai from lcm.pub.msapi.catalog import query_rawdata_from_catalog from lcm.pub.msapi.gvnfmdriver import get_packageinfo_by_vnfdid from lcm.pub.utils import toscautil @@ -46,7 +46,7 @@ class CreateVnf: if is_exist: raise NFLCMException('VNF is already exist.') - nf_inst_id = str(uuid.uuid4()) + self.nf_inst_id = str(uuid.uuid4()) try: self.package_info = get_packageinfo_by_vnfdid(self.vnfd_id) for val in ignore_case_get(self.package_info, "csars"): @@ -64,29 +64,39 @@ class CreateVnf: netype = ignore_case_get(metadata, "vnf_type") vnfsoftwareversion = ignore_case_get(metadata, "version") vnfd_model = self.vnfd - NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.package_id, + NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.package_id, version=version, vendor=vendor, netype=netype, vnfd_model=vnfd_model, status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, vnfSoftwareVersion=vnfsoftwareversion, create_time=now_time()) - data = { - "vnf-id": nf_inst_id, - "vnf-name": self.vnf_instance_mame, - "vnf-type": "INFRA", - "in-maint": "true", - "is-closed-loop-disabled": "false" - } - create_vnf(nf_inst_id, data) + + self.create_vnf_in_aai() except NFLCMException as e: - logger.debug('Create VNF instance[%s] to AAI failed' % nf_inst_id) + logger.debug('Create VNF instance[%s] to AAI failed' % self.nf_inst_id) except: - NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id='', + NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name=self.vnf_instance_mame, package_id='', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, vnfSoftwareVersion='', create_time=now_time()) - vnf_inst = NfInstModel.objects.get(nfinstid=nf_inst_id) + vnf_inst = NfInstModel.objects.get(nfinstid=self.nf_inst_id) logger.debug('id is [%s],name is [%s],vnfd_id is [%s],vnfd_model is [%s],' 'description is [%s],create_time is [%s]' % (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid, vnf_inst.vnfd_model, vnf_inst.nf_desc, vnf_inst.create_time)) - return nf_inst_id + return self.nf_inst_id + + def create_vnf_in_aai(self): + logger.debug("CreateVnf::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_instance_mame, + "vnf-type": "INFRA", + "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/lcm/pub/msapi/aai.py b/lcm/lcm/pub/msapi/aai.py index c62e4e97..a7fc8f00 100644 --- a/lcm/lcm/pub/msapi/aai.py +++ b/lcm/lcm/pub/msapi/aai.py @@ -18,7 +18,7 @@ import uuid from lcm.pub.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWORD from lcm.pub.exceptions import NFLCMException -from lcm.pub.utils.restcall import rest_no_auth, call_req +from lcm.pub.utils import restcall logger = logging.getLogger(__name__) @@ -28,10 +28,10 @@ def call_aai(resource, method, data=''): 'X-FromAppId': 'VFC-GVNFM-VNFLCM', 'X-TransactionId': str(uuid.uuid1()) } - return call_req(AAI_BASE_URL, + return restcall.call_req(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, - rest_no_auth, + restcall.rest_no_auth, resource, method, data, @@ -71,27 +71,27 @@ def query_ns(global_customer_id, service_type, service_instance_id, data): return json.JSONDecoder().decode(ret[1]) -def create_vnf(vnf_id, data): +def create_vnf_aai(vnf_id, data): resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id ret = call_aai(resource, "PUT", data) if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NFLCMException("Vnf instance creation exception in AAI") - return json.JSONDecoder().decode(ret[1]) - + return json.JSONDecoder().decode(ret[1]), ret[2] -def delete_vnf(vnf_id): +def delete_vnf_aai(vnf_id, resource_version=""): resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id + if resource_version: + resource = resource + "?resource-version=%s" % resource_version ret = call_aai(resource, "DELETE") if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NFLCMException("Vnf instance delete exception in AAI") return json.JSONDecoder().decode(ret[1]) - -def query_vnf(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 NFLCMException("Vnf instance query exception in AAI") |