summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/usage.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2013-07-29 12:28:53 -0500
committerDean Troyer <dtroyer@gmail.com>2013-07-31 10:12:20 -0500
commit7d138b94eccdc30487d3aa95c8bd6338933eefe6 (patch)
tree02099c651c87d9f908d7c456eb7e8c571ca273d2 /openstackclient/compute/v2/usage.py
parentc385180df2338a52e89b1dfdf4d59dd698eaba67 (diff)
downloadpython-openstackclient-7d138b94eccdc30487d3aa95c8bd6338933eefe6.tar.gz
Remove tenant round 3 - other commands
Mostly options and help strings: * image, server, project usage, volume Change-Id: I788b0660f8c2daacde53c20a72dd1afc60cf5159
Diffstat (limited to 'openstackclient/compute/v2/usage.py')
-rw-r--r--openstackclient/compute/v2/usage.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py
index 0bfbc9b8..f60c2105 100644
--- a/openstackclient/compute/v2/usage.py
+++ b/openstackclient/compute/v2/usage.py
@@ -47,6 +47,15 @@ class ListUsage(lister.Lister):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
+
+ def _format_project(project):
+ if not project:
+ return ""
+ if project in project_cache.keys():
+ return project_cache[project].name
+ else:
+ return project
+
compute_client = self.app.client_manager.compute
columns = (
"tenant_id",
@@ -55,7 +64,7 @@ class ListUsage(lister.Lister):
"total_local_gb_usage"
)
column_headers = (
- "Project ID",
+ "Project",
"RAM MB-Hours",
"CPU Hours",
"Disk GB-Hours"
@@ -76,6 +85,15 @@ class ListUsage(lister.Lister):
usage_list = compute_client.usage.list(start, end)
+ # Cache the project list
+ project_cache = {}
+ try:
+ for p in self.app.client_manager.identity.tenants.list():
+ project_cache[p.id] = p
+ except Exception:
+ # Just forget it if there's any trouble
+ pass
+
if len(usage_list) > 0:
print("Usage from %s to %s:" % (start.strftime(dateformat),
end.strftime(dateformat)))
@@ -84,6 +102,7 @@ class ListUsage(lister.Lister):
(utils.get_item_properties(
s, columns,
formatters={
+ 'tenant_id': _format_project,
'total_memory_mb_usage': lambda x: float("%.2f" % x),
'total_vcpus_usage': lambda x: float("%.2f" % x),
'total_local_gb_usage': lambda x: float("%.2f" % x),