Fix bug for status code 303 location HEAD field is NULL
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / biz / delete_vnf.py
1 # Copyright 2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import logging
16
17 from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel
18
19 logger = logging.getLogger(__name__)
20
21
22 class DeleteVnf:
23     def __init__(self, data, instanceid):
24         self.data = data
25         self.nf_inst_id = instanceid
26
27     def do_biz(self):
28         self.check_parameter()
29         self.delete_info_from_db()
30         logger.debug('VnfInst(%s) is deleted.' % self.nf_inst_id)
31
32     def check_parameter(self):
33         vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
34         if not vnf_insts.exists():
35             logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id)
36
37     def delete_info_from_db(self):
38         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete()
39         NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete()