Skip to content

Commit 49d2b74

Browse files
committed
Make get all usages more human readable
1 parent 587615c commit 49d2b74

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

os_capacity/commands/commands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class ListUsagesAll(Lister):
7777
"""List all current resource usages."""
7878

7979
def take_action(self, parsed_args):
80-
allocations = utils.get_allocations_with_server_info(self.app)
80+
allocations = utils.get_allocations_with_server_info(
81+
self.app, get_names=True)
8182
return (
8283
('Provider Name', 'Server UUID', 'Resources',
8384
'Flavor', 'Days', 'Project', 'User'), allocations)

os_capacity/utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _get_now():
116116
"project_id", "user_id"))
117117

118118

119-
def get_allocations_with_server_info(app, flat_usage=True):
119+
def get_allocations_with_server_info(app, flat_usage=True, get_names=False):
120120
"""Get allocations, add in server and resource provider details."""
121121
resource_providers = resource_provider.get_all(app.placement_client)
122122
rp_dict = {rp.uuid: rp.name for rp in resource_providers}
@@ -150,6 +150,28 @@ def get_allocations_with_server_info(app, flat_usage=True):
150150
allocation_tuples.sort(key=lambda x: (x.project_id, x.user_id,
151151
x.days * -1, x.flavor_id))
152152

153+
if get_names:
154+
all_users = users.get_all(app.identity_client)
155+
all_projects = users.get_all_projects(app.identity_client)
156+
all_flavors_list = flavors.get_all(
157+
app.compute_client, include_extra_specs=False)
158+
all_flavors = {flavor.id: flavor.name for flavor in all_flavors_list}
159+
160+
updated = []
161+
for allocation in allocation_tuples:
162+
user_id = all_users.get(allocation.user_id)
163+
project_id = all_projects.get(allocation.project_id)
164+
flavor_id = all_flavors.get(allocation.flavor_id)
165+
updated.append(AllocationList(
166+
allocation.resource_provider_name,
167+
allocation.consumer_uuid,
168+
allocation.usage,
169+
flavor_id,
170+
allocation.days,
171+
project_id,
172+
user_id))
173+
allocation_tuples = updated
174+
153175
return allocation_tuples
154176

155177

0 commit comments

Comments
 (0)