From 7d138b94eccdc30487d3aa95c8bd6338933eefe6 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 29 Jul 2013 12:28:53 -0500 Subject: Remove tenant round 3 - other commands Mostly options and help strings: * image, server, project usage, volume Change-Id: I788b0660f8c2daacde53c20a72dd1afc60cf5159 --- openstackclient/compute/v2/usage.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'openstackclient/compute/v2/usage.py') 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), -- cgit v1.2.1