From 10db0df857f8982110b67094f237384acda2fa3a Mon Sep 17 00:00:00 2001 From: kafka Date: Wed, 12 Aug 2015 12:07:34 +0800 Subject: [PATCH] Add filtering by user for 'openstack server list' Add a new option to search by user when listing servers, include support for domain scoped users, also update docs Co-Authored-By: Steve Martinelli Closes-Bug: #1483974 Change-Id: Ifdade6dc9ca8400fbd85f6b55793ab15ed17b97d --- doc/source/command-objects/server.rst | 9 +++++++++ openstackclient/compute/v2/server.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index b00b94479d..9ff4843727 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -237,6 +237,15 @@ List servers Domain the project belongs to (name or ID). This can be used in case collisions between project names exist. +.. option:: --user + + Search by user (admin only) (name or ID) + +.. option:: --user-domain + + Domain the user belongs to (name or ID). + This can be used in case collisions between user names exist. + .. option:: --long List additional fields in output diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index a246a04d2a..30a1b0636d 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -699,6 +699,12 @@ class ListServer(lister.Lister): metavar='', help="Search by project (admin only) (name or ID)") identity_common.add_project_domain_option_to_parser(parser) + parser.add_argument( + '--user', + metavar='', + help=_('Search by user (admin only) (name or ID)'), + ) + identity_common.add_user_domain_option_to_parser(parser) parser.add_argument( '--long', action='store_true', @@ -710,10 +716,10 @@ class ListServer(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) compute_client = self.app.client_manager.compute + identity_client = self.app.client_manager.identity project_id = None if parsed_args.project: - identity_client = self.app.client_manager.identity project_id = identity_common.find_project( identity_client, parsed_args.project, @@ -721,6 +727,14 @@ class ListServer(lister.Lister): ).id parsed_args.all_projects = True + user_id = None + if parsed_args.user: + user_id = identity_common.find_project( + identity_client, + parsed_args.user, + parsed_args.user_domain, + ).id + search_opts = { 'reservation_id': parsed_args.reservation_id, 'ip': parsed_args.ip, @@ -733,6 +747,7 @@ class ListServer(lister.Lister): 'host': parsed_args.host, 'tenant_id': project_id, 'all_tenants': parsed_args.all_projects, + 'user_id': user_id, } self.log.debug('search options: %s', search_opts)