Add aaiapi file in gvnfm vnflcm
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / vnf_cancel / delete_vnf_identifier.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 import logging
15
16 from lcm.pub.aaiapi.aai import call_aai
17 from lcm.pub.config.config import AAI_BASE_URL
18 from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel
19
20 logger = logging.getLogger(__name__)
21
22
23 class DeleteVnf:
24     def __init__(self, data, instanceid):
25         self.data = data
26         self.nf_inst_id = instanceid
27
28     def do_biz(self):
29         vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
30         if not vnf_insts.exists():
31             logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id)
32             return
33         #sel_vnf = vnf_insts[0]
34         #if sel_vnf.status != 'NOT_INSTANTIATED':
35         #    raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status)
36         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete()
37         NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete()
38
39     def delete_data_from_aai(self, req_data):
40         full_url = AAI_BASE_URL + "api/aai-service-design-and-creation/v1/%s" % self.nf_inst_id
41         del_result = call_aai(full_url, "DELETE", req_data)
42         pass