summaryrefslogtreecommitdiff
path: root/novaclient/utils.py
diff options
context:
space:
mode:
authorTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2018-08-06 00:16:29 +0900
committerTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2018-08-07 15:30:48 +0900
commit33e89f99a43ca0ef4273d1896e849b7980f4769b (patch)
tree3e8765a5591896a3f67be7d81778ced07b702b0c /novaclient/utils.py
parent045f641cec19c6d2826ef20e3ed1409b1991836f (diff)
downloadpython-novaclient-33e89f99a43ca0ef4273d1896e849b7980f4769b.tar.gz
Fix server strings in reboot operation
The following message is shown currently in the reboot operation. Request to reboot server <Server: server1> has been accepted. The server name string is a bit odd. So fix it as follows. Request to reboot server server1 (ff79e91e-e2a7-4e0f-b4c3-7157676d43c9) has been accepted. Change-Id: I62df4589dc950f69fdc23eafcbb5792e897cb635 Closes-Bug: #1785495
Diffstat (limited to 'novaclient/utils.py')
-rw-r--r--novaclient/utils.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/novaclient/utils.py b/novaclient/utils.py
index 6f3cf640..6de65997 100644
--- a/novaclient/utils.py
+++ b/novaclient/utils.py
@@ -361,6 +361,18 @@ def safe_issubclass(*args):
return False
+def _get_resource_string(resource):
+ if hasattr(resource, 'human_id') and resource.human_id:
+ if hasattr(resource, 'id') and resource.id:
+ return "%s (%s)" % (resource.human_id, resource.id)
+ else:
+ return resource.human_id
+ elif hasattr(resource, 'id') and resource.id:
+ return resource.id
+ else:
+ return resource
+
+
def do_action_on_many(action, resources, success_msg, error_msg):
"""Helper to run an action on many resources."""
failure_flag = False
@@ -368,7 +380,7 @@ def do_action_on_many(action, resources, success_msg, error_msg):
for resource in resources:
try:
action(resource)
- print(success_msg % resource)
+ print(success_msg % _get_resource_string(resource))
except Exception as e:
failure_flag = True
print(encodeutils.safe_encode(six.text_type(e)))