Skip to content

Commit

Permalink
Make it possible to filter the comput server list (#1115)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Nov 3, 2024
1 parent 70ea6c6 commit 8267c7d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion osism/commands/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ def take_action(self, parsed_args):
class ComputeList(Command):
def get_parser(self, prog_name):
parser = super(ComputeList, self).get_parser(prog_name)
parser.add_argument(
"--project",
default=None,
type=str,
help="Filter by project ID",
)
parser.add_argument(
"--domain",
default=None,
type=str,
help="Filter by domain ID",
)
parser.add_argument(
"host",
nargs="?",
Expand All @@ -96,11 +108,20 @@ def get_parser(self, prog_name):
def take_action(self, parsed_args):
host = parsed_args.host
conn = get_cloud_connection()
domain = parsed_args.domain
project = parsed_args.project

result = []
if host:
for server in conn.compute.servers(all_projects=True, node=host):
result.append([server.id, server.name, server.status])
if project and server.project_id == project:
result.append([server.id, server.name, server.status])
elif domain:
server_project = get_cloud_project(server.project_id)
if server_project.domain_id == domain:
result.append([server.id, server.name, server.status])
else:
result.append([server.id, server.name, server.status])

print(
tabulate(
Expand Down

0 comments on commit 8267c7d

Please sign in to comment.