diff options
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/.gitignore | 2 | ||||
-rw-r--r-- | lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py | 2 | ||||
-rw-r--r-- | lcm/lcm/nf/vnf_cancel/term_vnf.py | 132 |
3 files changed, 46 insertions, 90 deletions
diff --git a/lcm/.gitignore b/lcm/.gitignore index 6a415b13..f8b7e60c 100644 --- a/lcm/.gitignore +++ b/lcm/.gitignore @@ -1,4 +1,4 @@ .idea -logs/runtime_lcm.log +logs/* *.pyc bash.exe.stackdump diff --git a/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py index d24cc081..42e52d6f 100644 --- a/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnf_cancel/delete_vnf_identifier.py @@ -30,6 +30,7 @@ class DeleteVnf: try: self.check_parameter() self.delete_info_from_db() + logger.debug('VnfInst(%s) is deleted.' % self.nf_inst_id) except NFLCMException as e: logger.debug('Delete VNF instance[%s] failed: %s', self.nf_inst_id, e.message) except Exception as e: @@ -41,7 +42,6 @@ class DeleteVnf: vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) if not vnf_insts.exists(): logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id) - return # sel_vnf = vnf_insts[0] # if sel_vnf.status != 'NOT_INSTANTIATED': # raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) diff --git a/lcm/lcm/nf/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnf_cancel/term_vnf.py index 86780309..b0e3471d 100644 --- a/lcm/lcm/nf/vnf_cancel/term_vnf.py +++ b/lcm/lcm/nf/vnf_cancel/term_vnf.py @@ -40,14 +40,7 @@ class TermVnf(Thread): self.gracefulTerminationTimeout = ignore_case_get(self.data, "gracefulTerminationTimeout") self.apply_result = None self.notify_data = None - self.inst_resource = { - 'volumn': [], - 'network': [], - 'subnet': [], - 'port': [], - 'flavor': [], - 'vm': [], - } + self.inst_resource = {'volumn': [], 'network': [], 'subnet': [], 'port': [], 'flavor': [], 'vm': []} def run(self): try: @@ -85,17 +78,24 @@ class TermVnf(Thread): def grant_resource(self): logger.info("nf_cancel_task grant_resource begin") - content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '', - 'lifecycleOperation': 'Terminate', 'jobId': self.job_id, - 'addResource': [], 'removeResource': [], - 'placementConstraint': [], 'additionalParam': {}} + content_args = { + 'vnfInstanceId': self.nf_inst_id, + 'vnfDescriptorId': '', + 'lifecycleOperation': 'Terminate', + '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} + res_def = { + 'type': 'VDU', + 'resDefId': str(res_index), + 'resDesId': vdu.resouceid} content_args['removeResource'].append(res_def) res_index += 1 @@ -111,77 +111,30 @@ class TermVnf(Thread): def query_inst_resource(self): logger.info('[query_resource begin]:inst_id=%s' % self.nf_inst_id) - vol_list = StorageInstModel.objects.filter(instid=self.nf_inst_id) - for vol in vol_list: - vol_info = {} - if not vol.resouceid: - continue - vol_info["vim_id"] = vol.vimid - vol_info["tenant_id"] = vol.tenant - vol_info["res_id"] = vol.resouceid - vol_info["is_predefined"] = vol.is_predefined - self.inst_resource['volumn'].append(vol_info) - logger.info('[query_volumn_resource]:ret_volumns=%s' % self.inst_resource['volumn']) - - network_list = NetworkInstModel.objects.filter(instid=self.nf_inst_id) - for network in network_list: - network_info = {} - if not network.resouceid: - continue - network_info["vim_id"] = network.vimid - network_info["tenant_id"] = network.tenant - network_info["res_id"] = network.resouceid - network_info["is_predefined"] = network.is_predefined - self.inst_resource['network'].append(network_info) - logger.info('[query_network_resource]:ret_networks=%s' % self.inst_resource['network']) - - subnetwork_list = SubNetworkInstModel.objects.filter(instid=self.nf_inst_id) - for subnetwork in subnetwork_list: - subnetwork_info = {} - if not subnetwork.resouceid: - continue - subnetwork_info["vim_id"] = subnetwork.vimid - subnetwork_info["tenant_id"] = subnetwork.tenant - subnetwork_info["res_id"] = subnetwork.resouceid - subnetwork_info["is_predefined"] = subnetwork.is_predefined - self.inst_resource['subnet'].append(subnetwork_info) - logger.info('[query_subnetwork_resource]:ret_networks=%s' % self.inst_resource['subnet']) - - port_list = PortInstModel.objects.filter(instid=self.nf_inst_id) - for port in port_list: - port_info = {} - if not port.resouceid: - continue - port_info["vim_id"] = port.vimid - port_info["tenant_id"] = port.tenant - port_info["res_id"] = port.resouceid - port_info["is_predefined"] = port.is_predefined - self.inst_resource['port'].append(port_info) - logger.info('[query_port_resource]:ret_networks=%s' % self.inst_resource['port']) - - flavor_list = FlavourInstModel.objects.filter(instid=self.nf_inst_id) - for flavor in flavor_list: - flavor_info = {} - if not flavor.resouceid: - continue - flavor_info["vim_id"] = flavor.vimid - flavor_info["tenant_id"] = flavor.tenant - flavor_info["res_id"] = flavor.resouceid - flavor_info["is_predefined"] = flavor.is_predefined - self.inst_resource['flavor'].append(flavor_info) - logger.info('[query_flavor_resource]:ret_networks=%s' % self.inst_resource['flavor']) - - vm_list = VmInstModel.objects.filter(instid=self.nf_inst_id) - for vm in vm_list: - vm_info = {} - if not vm.resouceid: - continue - vm_info["vim_id"] = vm.vimid - vm_info["tenant_id"] = vm.tenant - vm_info["res_id"] = vm.resouceid - vm_info["is_predefined"] = vm.is_predefined - self.inst_resource['vm'].append(vm_info) - logger.info('[query_vm_resource]:ret_vms=%s' % self.inst_resource['vm']) + resoure_map = { + 'Storage': 'volumn', + 'Network': 'network', + 'SubNetwork': 'subnet', + 'Port': 'port', + 'Flavour': 'flavor', + 'Vm': 'vm' + } + for resoure_type in resoure_map.keys(): + resoure_table = globals().get(resoure_type + 'InstModel') + resoure_insts = resoure_table.objects.filter(instid=self.nf_inst_id) + for resoure_inst in resoure_insts: + if not resoure_inst.resouceid: + continue + self.inst_resource[resoure_map.get(resoure_type)].append(self.get_resource(resoure_inst)) + logger.info('[query_resource]:ret_resource=%s' % self.inst_resource) + + def get_resource(self, resource): + return { + "vim_id": resource.vimid, + "tenant_id": resource.tenant, + "res_id": resource.resouceid, + "is_predefined": resource.is_predefined + } def query_notify_data(self): logger.info('[NF terminate] send notify request to nfvo start') @@ -202,8 +155,11 @@ class TermVnf(Thread): affected_vl = [] networks = NetworkInstModel.objects.filter(instid=self.nf_inst_id) for network in networks: - network_resource = {'vimId': network.vimid, 'resourceId': network.resouceid, - 'resourceName': network.name, 'resourceType': 'network'} + network_resource = { + 'vimId': network.vimid, + 'resourceId': network.resouceid, + 'resourceName': network.name, + 'resourceType': 'network'} affected_vl.append( {'vlInstanceId': network.networkid, 'vldid': network.nodeId, |