diff options
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py index 5172abc4..dcf5c4ba 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py @@ -17,7 +17,7 @@ from threading import Thread from lcm.nf.vnfs.const import VNF_STATUS from lcm.pub.database.models import JobStatusModel, NfInstModel, VmInstModel, NetworkInstModel, StorageInstModel, \ - FlavourInstModel, PortInstModel, SubNetworkInstModel, NfvoRegInfoModel, VNFCInstModel + FlavourInstModel, PortInstModel, SubNetworkInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.msapi.nfvolcm import apply_grant_to_nfvo from lcm.pub.utils.jobutil import JobUtil @@ -47,20 +47,15 @@ class TermVnf(Thread): try: self.term_pre() self.grant_resource() - # self.query_inst_resource() + self.query_inst_resource() + # self.delete_resource() + # self.lcm_notify() JobUtil.add_job_status(self.job_id, 100, "Terminate Vnf success.") - is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists() - logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) except NFLCMException as e: - self.vnf_inst_failed_handle(e.message) + self.vnf_term_failed_handle(e.message) except: logger.error(traceback.format_exc()) - self.vnf_inst_failed_handle(traceback.format_exc()) - - def vnf_inst_failed_handle(self, error_msg): - logger.error('VNF termination failed, detail message: %s' % error_msg) - NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time()) - JobUtil.add_job_status(self.job_id, 255, error_msg) + self.vnf_term_failed_handle(traceback.format_exc()) def term_pre(self): vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) @@ -76,6 +71,28 @@ class TermVnf(Thread): JobUtil.add_job_status(self.job_id, 10, 'Nf terminating pre-check finish') logger.info("Nf terminating pre-check finish") + def grant_resource(self): + logger.info("nf_cancel_task grant_resource begin") + content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '', + 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id, + 'addResource': [], 'removeResource': [], + 'placementConstraint': [], 'additionalParam': {}} + + vdus = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + res_index = 1 + for vdu in vdus: + res_def = {'type': 'VDU', + 'resDefId': str(res_index), + 'resDesId': vdu.resouceid} + content_args['removeResource'].append(res_def) + res_index += 1 + + logger.info('content_args=%s' % content_args) + self.apply_result = apply_grant_to_nfvo(content_args) + vim_info = ignore_case_get(self.apply_result, "vim") + logger.info("nf_cancel_task grant_resource end") + JobUtil.add_job_status(self.job_id, 20, 'Nf terminating grant_resource finish') + def query_inst_resource(self): logger.info('[query_resource begin]:inst_id=%s' % self.nf_inst_id) # query_volumn_resource @@ -84,8 +101,9 @@ class TermVnf(Thread): vol_info = {} if not vol.resouceid: continue - vol_info["res_id"] = vol.resouceid vol_info["vim_id"] = vol.vimid + vol_info["tenant_id"] = vol.tenant + vol_info["res_id"] = vol.resouceid self.inst_resource['volumn'].append(vol_info) logger.info('[query_volumn_resource]:ret_volumns=%s' % self.inst_resource['volumn']) @@ -95,8 +113,9 @@ class TermVnf(Thread): network_info = {} if not network.resouceid: continue - network_info["res_id"] = network.resouceid network_info["vim_id"] = network.vimid + network_info["tenant_id"] = network.tenant + network_info["res_id"] = network.resouceid self.inst_resource['network'].append(network_info) logger.info('[query_network_resource]:ret_networks=%s' % self.inst_resource['network']) @@ -106,8 +125,9 @@ class TermVnf(Thread): subnetwork_info = {} if not subnetwork.resouceid: continue - subnetwork_info["res_id"] = subnetwork.resouceid subnetwork_info["vim_id"] = subnetwork.vimid + subnetwork_info["tenant_id"] = subnetwork.tenant + subnetwork_info["res_id"] = subnetwork.resouceid self.inst_resource['subnet'].append(subnetwork_info) logger.info('[query_subnetwork_resource]:ret_networks=%s' % self.inst_resource['subnet']) @@ -117,8 +137,9 @@ class TermVnf(Thread): port_info = {} if not port.resouceid: continue - port_info["res_id"] = port.resouceid port_info["vim_id"] = port.vimid + port_info["tenant_id"] = port.tenant + port_info["res_id"] = port.resouceid self.inst_resource['port'].append(port_info) logger.info('[query_port_resource]:ret_networks=%s' % self.inst_resource['port']) @@ -128,8 +149,9 @@ class TermVnf(Thread): flavor_info = {} if not flavor.resouceid: continue - flavor_info["res_id"] = flavor.resouceid flavor_info["vim_id"] = flavor.vimid + flavor_info["tenant_id"] = flavor.tenant + flavor_info["res_id"] = flavor.resouceid self.inst_resource['flavor'].append(flavor_info) logger.info('[query_flavor_resource]:ret_networks=%s' % self.inst_resource['flavor']) @@ -139,31 +161,17 @@ class TermVnf(Thread): vm_info = {} if not vm.resouceid: continue - vm_info["res_id"] = vm.resouceid vm_info["vim_id"] = vm.vimid + vm_info["tenant_id"] = vm.tenant + vm_info["res_id"] = vm.resouceid self.inst_resource['vm'].append(vm_info) logger.info('[query_vm_resource]:ret_vms=%s' % self.inst_resource['vm']) - def grant_resource(self): - logger.info("nf_cancel_task grant_resource begin") - content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '', - 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id, - 'addResource': [], 'removeResource': [], - 'placementConstraint': [], 'additionalParam': {}} + def delete_resource(self): + pass - vdus = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) - res_index = 1 - for vdu in vdus: - res_def = {'type': 'VDU', - 'resDefId': str(res_index), - 'resDesId': vdu.resouceid} - content_args['removeResource'].append(res_def) - res_index += 1 - - logger.info('content_args=%s' % content_args) - self.apply_result = apply_grant_to_nfvo(content_args) - vim_info = ignore_case_get(self.apply_result, "vim") - logger.info("nf_cancel_task grant_resource end") + def lcm_notify(self): + pass # def load_nfvo_config(self): # logger.info("[NF instantiation]get nfvo connection info start") @@ -175,3 +183,8 @@ class TermVnf(Thread): # else: # raise NFLCMException("Nfvo was not registered") # logger.info("[NF instantiation]get nfvo connection info end") + + def vnf_term_failed_handle(self, error_msg): + logger.error('VNF termination failed, detail message: %s' % error_msg) + NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time()) + JobUtil.add_job_status(self.job_id, 255, error_msg)
\ No newline at end of file |