@@ -47,6 +47,15 @@ def get_parser(self, prog_name):
4747
4848 def take_action (self , parsed_args ):
4949 self .log .debug ("take_action(%s)" % parsed_args )
50+
51+ def _format_project (project ):
52+ if not project :
53+ return ""
54+ if project in project_cache .keys ():
55+ return project_cache [project ].name
56+ else :
57+ return project
58+
5059 compute_client = self .app .client_manager .compute
5160 columns = (
5261 "tenant_id" ,
@@ -55,7 +64,7 @@ def take_action(self, parsed_args):
5564 "total_local_gb_usage"
5665 )
5766 column_headers = (
58- "Project ID " ,
67+ "Project" ,
5968 "RAM MB-Hours" ,
6069 "CPU Hours" ,
6170 "Disk GB-Hours"
@@ -76,6 +85,15 @@ def take_action(self, parsed_args):
7685
7786 usage_list = compute_client .usage .list (start , end )
7887
88+ # Cache the project list
89+ project_cache = {}
90+ try :
91+ for p in self .app .client_manager .identity .tenants .list ():
92+ project_cache [p .id ] = p
93+ except Exception :
94+ # Just forget it if there's any trouble
95+ pass
96+
7997 if len (usage_list ) > 0 :
8098 print ("Usage from %s to %s:" % (start .strftime (dateformat ),
8199 end .strftime (dateformat )))
@@ -84,6 +102,7 @@ def take_action(self, parsed_args):
84102 (utils .get_item_properties (
85103 s , columns ,
86104 formatters = {
105+ 'tenant_id' : _format_project ,
87106 'total_memory_mb_usage' : lambda x : float ("%.2f" % x ),
88107 'total_vcpus_usage' : lambda x : float ("%.2f" % x ),
89108 'total_local_gb_usage' : lambda x : float ("%.2f" % x ),
0 commit comments