summaryrefslogtreecommitdiff
path: root/troveclient/utils.py
diff options
context:
space:
mode:
authorwangyao <wangyao@cmss.chinamobile.com>2017-11-20 17:57:17 +0800
committerwangyao <wangyao@cmss.chinamobile.com>2017-12-21 10:44:24 +0800
commit3d9576bfa581be42e8892440eddeb62f88d6e7c9 (patch)
tree96f6860d7f9119bdd5f9c44306dc5ceea16f1480 /troveclient/utils.py
parent34dbdd2198a17cde04911f39fb084681f581743c (diff)
downloadpython-troveclient-3d9576bfa581be42e8892440eddeb62f88d6e7c9.tar.gz
Support delete and cluster_delete with many resources
Not like nova-delete when use trove-delete there is only support delete an instance everytime. With this patch, we can delete many instances or clusters in the same call, like trove delete instance1 instance2. Change-Id: I6bb0c406ba7f4c0e43cddfdff1d156b7e82ffa7a
Diffstat (limited to 'troveclient/utils.py')
-rw-r--r--troveclient/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/troveclient/utils.py b/troveclient/utils.py
index a6ea4bd..3dfcad0 100644
--- a/troveclient/utils.py
+++ b/troveclient/utils.py
@@ -334,3 +334,19 @@ def do_action_with_msg(action, success_msg):
action
print(success_msg)
+
+
+def do_action_on_many(action, resources, success_msg, error_msg):
+ """Helper to run an action on many resources."""
+ failure_flag = False
+
+ for resource in resources:
+ try:
+ action(resource)
+ print(success_msg % resource)
+ except Exception as e:
+ failure_flag = True
+ print(encodeutils.safe_encode(six.text_type(e)))
+
+ if failure_flag:
+ raise exceptions.CommandError(error_msg)