summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorxiexs <xiexs@cn.fujitsu.com>2015-11-02 04:28:08 -0500
committerxiexs <xiexs@cn.fujitsu.com>2015-11-02 04:28:17 -0500
commit9e507523215bb38502832ceccea0a9b94b6f4cbd (patch)
tree4b713d5577e56762ef2decce95700b58cd96e388 /openstackclient
parentcb28cd9ac0135867117683d7a8d20730067b16e8 (diff)
downloadpython-openstackclient-9e507523215bb38502832ceccea0a9b94b6f4cbd.tar.gz
Fix the bug of "openstack usage show"
When there is no resouce usage associated with the project, an odd output will be displayed. This patch tried to fix this issue. Change-Id: I6f254c6ba37fbb760ada08e640c4938668d560dc Closes-Bug: #1512220
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/usage.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py
index 31b90c22..6d5d678f 100644
--- a/openstackclient/compute/v2/usage.py
+++ b/openstackclient/compute/v2/usage.py
@@ -183,10 +183,18 @@ class ShowUsage(show.ShowOne):
))
info = {}
- info['Servers'] = len(usage.server_usages)
- info['RAM MB-Hours'] = float("%.2f" % usage.total_memory_mb_usage)
- info['CPU Hours'] = float("%.2f" % usage.total_vcpus_usage)
- info['Disk GB-Hours'] = float("%.2f" % usage.total_local_gb_usage)
+ info['Servers'] = (
+ len(usage.server_usages)
+ if hasattr(usage, "server_usages") else None)
+ info['RAM MB-Hours'] = (
+ float("%.2f" % usage.total_memory_mb_usage)
+ if hasattr(usage, "total_memory_mb_usage") else None)
+ info['CPU Hours'] = (
+ float("%.2f" % usage.total_vcpus_usage)
+ if hasattr(usage, "total_vcpus_usage") else None)
+ info['Disk GB-Hours'] = (
+ float("%.2f" % usage.total_local_gb_usage)
+ if hasattr(usage, "total_local_gb_usage") else None)
return zip(*sorted(six.iteritems(info)))