Skip to content

Commit 10db0df

Browse files
kafkaSteve Martinelli
authored andcommitted
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 <stevemar@ca.ibm.com> Closes-Bug: #1483974 Change-Id: Ifdade6dc9ca8400fbd85f6b55793ab15ed17b97d
1 parent 66010b4 commit 10db0df

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

doc/source/command-objects/server.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ List servers
237237
Domain the project belongs to (name or ID).
238238
This can be used in case collisions between project names exist.
239239
240+
.. option:: --user <user>
241+
242+
Search by user (admin only) (name or ID)
243+
244+
.. option:: --user-domain <user-domain>
245+
246+
Domain the user belongs to (name or ID).
247+
This can be used in case collisions between user names exist.
248+
240249
.. option:: --long
241250
242251
List additional fields in output

openstackclient/compute/v2/server.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ def get_parser(self, prog_name):
699699
metavar='<project>',
700700
help="Search by project (admin only) (name or ID)")
701701
identity_common.add_project_domain_option_to_parser(parser)
702+
parser.add_argument(
703+
'--user',
704+
metavar='<user>',
705+
help=_('Search by user (admin only) (name or ID)'),
706+
)
707+
identity_common.add_user_domain_option_to_parser(parser)
702708
parser.add_argument(
703709
'--long',
704710
action='store_true',
@@ -710,17 +716,25 @@ def get_parser(self, prog_name):
710716
def take_action(self, parsed_args):
711717
self.log.debug('take_action(%s)', parsed_args)
712718
compute_client = self.app.client_manager.compute
719+
identity_client = self.app.client_manager.identity
713720

714721
project_id = None
715722
if parsed_args.project:
716-
identity_client = self.app.client_manager.identity
717723
project_id = identity_common.find_project(
718724
identity_client,
719725
parsed_args.project,
720726
parsed_args.project_domain,
721727
).id
722728
parsed_args.all_projects = True
723729

730+
user_id = None
731+
if parsed_args.user:
732+
user_id = identity_common.find_project(
733+
identity_client,
734+
parsed_args.user,
735+
parsed_args.user_domain,
736+
).id
737+
724738
search_opts = {
725739
'reservation_id': parsed_args.reservation_id,
726740
'ip': parsed_args.ip,
@@ -733,6 +747,7 @@ def take_action(self, parsed_args):
733747
'host': parsed_args.host,
734748
'tenant_id': project_id,
735749
'all_tenants': parsed_args.all_projects,
750+
'user_id': user_id,
736751
}
737752
self.log.debug('search options: %s', search_opts)
738753

0 commit comments

Comments
 (0)