summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-04-11 17:06:16 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-04-11 17:25:09 +0800
commit5c1d6e15e279935e9764455f39a545b366254218 (patch)
tree633bd88fce5e7bb15b7fc308d448eefc2b79c2f8 /lcm
parente1408d5e2d5542fe584805ff77bfe42bdccd7f07 (diff)
Refactor vnflcm termination do_notify_delete
Change-Id: I33aebf02aa084f686bc25915e420f8c5b450918c Issue-ID: VFC-873 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnf_cancel/term_vnf.py41
1 files changed, 14 insertions, 27 deletions
diff --git a/lcm/lcm/nf/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnf_cancel/term_vnf.py
index b0e3471d..2b6f2e6c 100644
--- a/lcm/lcm/nf/vnf_cancel/term_vnf.py
+++ b/lcm/lcm/nf/vnf_cancel/term_vnf.py
@@ -19,7 +19,7 @@ from threading import Thread
from lcm.nf.const import VNF_STATUS
from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, StorageInstModel, \
- FlavourInstModel, PortInstModel, SubNetworkInstModel, VNFCInstModel, NfvoRegInfoModel
+ PortInstModel, VNFCInstModel, NfvoRegInfoModel, FlavourInstModel, SubNetworkInstModel
from lcm.pub.exceptions import NFLCMException
from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo
from lcm.pub.utils.jobutil import JobUtil
@@ -41,6 +41,8 @@ class TermVnf(Thread):
self.apply_result = None
self.notify_data = None
self.inst_resource = {'volumn': [], 'network': [], 'subnet': [], 'port': [], 'flavor': [], 'vm': []}
+ self.resource_map = {'Storage': 'volumn', 'Network': 'network', 'SubNetwork': 'subnet', 'Port': 'port',
+ 'Flavour': 'flavor', 'Vm': 'vm'}
def run(self):
try:
@@ -111,21 +113,13 @@ class TermVnf(Thread):
def query_inst_resource(self):
logger.info('[query_resource begin]:inst_id=%s' % self.nf_inst_id)
- 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:
+ for resource_type in self.resource_map.keys():
+ resource_table = globals().get(resource_type + 'InstModel')
+ resource_insts = resource_table.objects.filter(instid=self.nf_inst_id)
+ for resource_inst in resource_insts:
+ if not resource_inst.resouceid:
continue
- self.inst_resource[resoure_map.get(resoure_type)].append(self.get_resource(resoure_inst))
+ self.inst_resource[self.resource_map.get(resource_type)].append(self.get_resource(resource_inst))
logger.info('[query_resource]:ret_resource=%s' % self.inst_resource)
def get_resource(self, resource):
@@ -183,6 +177,8 @@ class TermVnf(Thread):
'changeType': 'removed',
'storageResource': {'vimId': vs.vimid, 'resourceId': vs.resouceid,
'resourceName': vs.name, 'resourceType': 'volume'}})
+ FlavourInstModel.objects.filter(instid=self.nf_inst_id)
+ SubNetworkInstModel.objects.filter(instid=self.nf_inst_id)
self.notify_data = {
"status": 'result',
"vnfInstanceId": self.nf_inst_id,
@@ -206,18 +202,9 @@ class TermVnf(Thread):
def do_notify_delete(self, res_type, res_id):
logger.error('Deleting [%s] resource:resourceid [%s]' % (res_type, res_id))
- if res_type == adaptor.RES_VM:
- VmInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
- elif res_type == adaptor.RES_FLAVOR:
- FlavourInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
- elif res_type == adaptor.RES_PORT:
- PortInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
- elif res_type == adaptor.RES_SUBNET:
- SubNetworkInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
- elif res_type == adaptor.RES_NETWORK:
- NetworkInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
- elif res_type == adaptor.RES_VOLUME:
- StorageInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
+ resource_type = self.resource_map.keys()[self.resource_map.values().index(res_type)]
+ resource_table = globals().get(resource_type + 'InstModel')
+ resource_table.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete()
def lcm_notify(self):
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='NOT_INSTANTIATED', lastuptime=now_time())