1 # Copyright 2016 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.
19 from lcm.pub.config.config import REPORT_TO_AAI
20 from lcm.pub.database.models import DefPkgMappingModel, InputParamMappingModel, ServiceBaseInfoModel
21 from lcm.pub.database.models import NSInstModel
22 from lcm.pub.msapi.aai import delete_customer_aai, query_customer_aai
24 logger = logging.getLogger(__name__)
27 class DeleteNsService(object):
28 def __init__(self, ns_inst_id):
29 self.ns_inst_id = ns_inst_id
35 self.delete_ns_in_aai()
37 logger.error(traceback.format_exc())
40 logger.debug("delele NSInstModel(%s)", self.ns_inst_id)
41 NSInstModel.objects.filter(id=self.ns_inst_id).delete()
43 logger.debug("delele InputParamMappingModel(%s)", self.ns_inst_id)
44 InputParamMappingModel.objects.filter(service_id=self.ns_inst_id).delete()
46 logger.debug("delele DefPkgMappingModel(%s)", self.ns_inst_id)
47 DefPkgMappingModel.objects.filter(service_id=self.ns_inst_id).delete()
49 logger.debug("delele ServiceBaseInfoModel(%s)", self.ns_inst_id)
50 ServiceBaseInfoModel.objects.filter(service_id=self.ns_inst_id).delete()
52 def delete_ns_in_aai(self):
53 logger.debug("DeleteNsService::delete_ns_in_aai::delete ns instance[%s] in aai." % self.ns_inst_id)
54 global_customer_id = "global-customer-id-" + self.ns_inst_id
56 # query ns instance in aai, get resource_version
57 customer_info = query_customer_aai(global_customer_id)
58 resource_version = customer_info["resource-version"]
60 # delete ns instance from aai
61 resp_data, resp_status = delete_customer_aai(global_customer_id, resource_version)
63 logger.debug("Fail to delete ns instance[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))
66 "Success to delete ns instance[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))