1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel
18 from lcm.pub.exceptions import NFLCMException
20 logger = logging.getLogger(__name__)
24 def __init__(self, data, instanceid):
26 self.nf_inst_id = instanceid
30 self.check_parameter()
31 self.delete_info_from_db()
32 except NFLCMException as e:
33 logger.debug('Delete VNF instance[%s] failed: %s', self.nf_inst_id, e.message)
35 logger.debug('Delete VNF instance[%s] failed' % self.nf_inst_id)
37 def check_parameter(self):
38 vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
39 if not vnf_insts.exists():
40 logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id)
42 # sel_vnf = vnf_insts[0]
43 # if sel_vnf.status != 'NOT_INSTANTIATED':
44 # raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status)
46 def delete_info_from_db(self):
47 NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete()
48 NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete()