Skip to content

Commit 0ff1b22

Browse files
authored
Add additional ID columns to server list command output (#1748)
Enhance the server list command to display contextual IDs based on the filter flag: - --domain: adds User ID column - --project: adds Domain and User ID columns - --user: adds Domain and Project ID columns This provides better visibility into the relationships between servers, projects, domains, and users. AI-assisted: Claude Code Signed-off-by: Christian Berendt <[email protected]>
1 parent 2cd6a04 commit 0ff1b22

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

osism/commands/server.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def take_action(self, parsed_args):
166166
[
167167
project.name,
168168
project.id,
169+
server.user_id if hasattr(server, "user_id") else None,
169170
server.id,
170171
server.name,
171172
server.flavor["original_name"],
@@ -176,7 +177,15 @@ def take_action(self, parsed_args):
176177
print(
177178
tabulate(
178179
result,
179-
headers=["Project", "Project ID", "ID", "Name", "Flavor", "Status"],
180+
headers=[
181+
"Project",
182+
"Project ID",
183+
"User ID",
184+
"ID",
185+
"Name",
186+
"Flavor",
187+
"Status",
188+
],
180189
tablefmt="psql",
181190
)
182191
)
@@ -196,9 +205,20 @@ def take_action(self, parsed_args):
196205
return
197206
query = {"project_id": _project.id}
198207

208+
# Get domain name from project
209+
domain_name = None
210+
if hasattr(_project, "domain_id") and _project.domain_id:
211+
try:
212+
_domain = conn.identity.get_domain(_project.domain_id)
213+
domain_name = _domain.name if _domain else _project.domain_id
214+
except Exception:
215+
domain_name = _project.domain_id
216+
199217
for server in conn.compute.servers(all_projects=True, **query):
200218
result.append(
201219
[
220+
domain_name,
221+
server.user_id if hasattr(server, "user_id") else None,
202222
server.id,
203223
server.name,
204224
server.flavor["original_name"],
@@ -209,7 +229,7 @@ def take_action(self, parsed_args):
209229
print(
210230
tabulate(
211231
result,
212-
headers=["ID", "Name", "Flavor", "Status"],
232+
headers=["Domain", "User ID", "ID", "Name", "Flavor", "Status"],
213233
tablefmt="psql",
214234
)
215235
)
@@ -218,8 +238,27 @@ def take_action(self, parsed_args):
218238
query = {"user_id": user_id}
219239

220240
for server in conn.compute.servers(all_projects=True, **query):
241+
# Get domain name from project
242+
domain_name = None
243+
if hasattr(server, "project_id") and server.project_id:
244+
try:
245+
_project = conn.identity.get_project(server.project_id)
246+
if (
247+
_project
248+
and hasattr(_project, "domain_id")
249+
and _project.domain_id
250+
):
251+
_domain = conn.identity.get_domain(_project.domain_id)
252+
domain_name = (
253+
_domain.name if _domain else _project.domain_id
254+
)
255+
except Exception:
256+
domain_name = None
257+
221258
result.append(
222259
[
260+
domain_name,
261+
server.project_id if hasattr(server, "project_id") else None,
223262
server.id,
224263
server.name,
225264
server.flavor["original_name"],
@@ -230,7 +269,7 @@ def take_action(self, parsed_args):
230269
print(
231270
tabulate(
232271
result,
233-
headers=["ID", "Name", "Flavor", "Status"],
272+
headers=["Domain", "Project ID", "ID", "Name", "Flavor", "Status"],
234273
tablefmt="psql",
235274
)
236275
)

0 commit comments

Comments
 (0)