Modify vfc-lcm variable name to hump
[vfc/nfvo/lcm.git] / lcm / ns / ns_delete.py
index dde89d1..131cb76 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-
-
 import logging
 import traceback
 
 from lcm.pub.config.config import REPORT_TO_AAI
 from lcm.pub.database.models import DefPkgMappingModel, InputParamMappingModel, ServiceBaseInfoModel
 from lcm.pub.database.models import NSInstModel
-from lcm.pub.msapi.aai import delete_customer_aai, query_customer_aai
+from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.aai import query_ns_aai, delete_ns_aai
 
 logger = logging.getLogger(__name__)
 
@@ -51,16 +50,35 @@ class DeleteNsService(object):
 
     def delete_ns_in_aai(self):
         logger.debug("DeleteNsService::delete_ns_in_aai::delete ns instance[%s] in aai." % self.ns_inst_id)
-        global_customer_id = "global-customer-id-" + self.ns_inst_id
+        try:
+            # global_customer_id = "global-customer-id-" + self.ns_inst_id
+            #
+            # # query ns instance in aai, get resource_version
+            # customer_info = query_customer_aai(global_customer_id)
+            # resource_version = customer_info["resource-version"]
+            #
+            # # delete ns instance from aai
+            # resp_data, resp_status = delete_customer_aai(global_customer_id, resource_version)
 
-        # query ns instance in aai, get resource_version
-        customer_info = query_customer_aai(global_customer_id)
-        resource_version = customer_info["resource-version"]
+            ns_insts = NSInstModel.objects.filter(id=self.ns_inst_id)
+            self.global_customer_id = ns_insts[0].global_customer_id
+            self.service_type = ns_insts[0].service_type
+            # query ns instance in aai, get resource_version
+            logger.debug("self.global_customer_id=[%s], self.service_type=[%s], self.ns_inst_id=[%s]"
+                         % (self.global_customer_id, self.service_type, self.ns_inst_id))
+            ns_info = query_ns_aai(self.global_customer_id, self.service_type, self.ns_inst_id)
+            resource_version = ns_info["resource-version"]
 
-        # delete ns instance from aai
-        resp_data, resp_status = delete_customer_aai(global_customer_id, resource_version)
-        if resp_data:
-            logger.debug("Fail to delete ns instance[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))
-        else:
-            logger.debug("Success to delete ns instance[%s] from aai, resp_status: [%s]."
-                         % (self.ns_inst_id, resp_status))
+            # delete ns instance from aai
+            logger.debug("ns instance resource_version=[%s]" % resource_version)
+            resp_data, resp_status = delete_ns_aai(self.global_customer_id, self.service_type,
+                                                   self.ns_inst_id, resource_version)
+            if resp_data:
+                logger.debug("Fail to delete ns[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))
+            else:
+                logger.debug("Success to delete ns[%s] from aai, resp_status: [%s]."
+                             % (self.ns_inst_id, resp_status))
+        except NSLCMException as e:
+            logger.debug("Fail to delete ns[%s] from aai, detail message: %s" % (self.ns_inst_id, e.message))
+        except:
+            logger.error(traceback.format_exc())