Refactor delete resource adaptor of vimdriver
authorfujinhua <fu.jinhua@zte.com.cn>
Mon, 13 Feb 2017 07:20:58 +0000 (15:20 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Mon, 13 Feb 2017 07:20:58 +0000 (15:20 +0800)
Change-Id: Iac9f1d4666a5346e37883232126b4a2acf40cdeb
Issue-Id: GVNFM-30
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/lcm/pub/vimapi/adaptor.py
lcm/lcm/pub/vimapi/exceptions.py

index f7ffc1f..d047537 100644 (file)
@@ -62,17 +62,16 @@ def create_vim_res(data, do_notify, do_rollback):
         do_rollback(str(sys.exc_info()))
     
 def delete_vim_res(data, do_notify):
-    def ignore_exception_call(fun, *args):
-        try:
-            fun(*args)
-        except VimException as e:
-            logger.error(e.message)
     res_types = ["vm", "flavor", "port", "subnet", "network", "volume"]
     res_del_funs = [api.delete_vm, api.delete_flavor, api.delete_port, 
         api.delete_subnet, api.delete_network, api.delete_volume]
     for res_type, res_del_fun in zip(res_types, res_del_funs):
         for res in ignore_case_get(data, res_type):
-            ignore_exception_call(res_del_fun, res["vim_id"], res["res_id"])
+            try:
+                res_del_fun(res["vim_id"], res["res_id"])
+            except VimException as e:
+                logger.error("Failed to delete %s(%s): %s", 
+                    res_type, res["res_id"], e.message)
             do_notify(res_type)
 
 def create_volume(vol, do_notify, progress):
@@ -96,7 +95,7 @@ def create_volume(vol, do_notify, progress):
         retry_count = retry_count + 1
     if return_code == RES_NEW:
         api.delete_volume(vim_id, vol_id)
-    raise VimException("Failed to create Volume(%s): Timeout." % vol_name)
+    raise VimException("Failed to create Volume(%s): Timeout." % vol_name, "500")
     
 def create_network(network, do_notify, progress):
     param = {
@@ -196,4 +195,4 @@ def create_vm(vm, do_notify, progress):
         retry_count = retry_count + 1
     if return_code == RES_NEW:
         api.delete_vm(vim_id, vm_id)
-    raise VimException("Failed to create Vm(%s): %s." % (vm_name, opt_vm_status))
+    raise VimException("Failed to create Vm(%s): %s." % (vm_name, opt_vm_status), "500")
index adddb71..0d6ccec 100644 (file)
@@ -15,6 +15,6 @@
 from lcm.pub.exceptions import NFLCMException
 
 class VimException(NFLCMException):
-    def __init__(self, error_msg='', http_code=''):
-        self.error_msg = error_msg
+    def __init__(self, message='', http_code=''):
+        self.message = message
         self.http_code = http_code