diff --git a/doc/source/command-objects/project.rst b/doc/source/command-objects/project.rst index 0be4e80680..305e611495 100644 --- a/doc/source/command-objects/project.rst +++ b/doc/source/command-objects/project.rst @@ -79,6 +79,7 @@ List projects os project list [--domain ] + [--user ] [--long] .. option:: --domain @@ -87,6 +88,12 @@ List projects .. versionadded:: 3 +.. option:: --user + + Filter projects by :option:`\ <--user>` (name or ID) + + .. versionadded:: 3 + .. option:: --long List additional fields in output diff --git a/openstackclient/identity/v3/project.py b/openstackclient/identity/v3/project.py index 1e3977ba36..e9adfe348a 100644 --- a/openstackclient/identity/v3/project.py +++ b/openstackclient/identity/v3/project.py @@ -162,6 +162,11 @@ class ListProject(lister.Lister): metavar='', help='Filter projects by (name or ID)', ) + parser.add_argument( + '--user', + metavar='', + help='Filter projects by (name or ID)', + ) parser.add_argument( '--long', action='store_true', @@ -178,9 +183,24 @@ class ListProject(lister.Lister): else: columns = ('ID', 'Name') kwargs = {} + + domain_id = None if parsed_args.domain: - kwargs['domain'] = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain(identity_client, + parsed_args.domain).id + kwargs['domain'] = domain_id + + if parsed_args.user: + if parsed_args.domain: + user_id = utils.find_resource(identity_client.users, + parsed_args.user, + domain_id=domain_id).id + else: + user_id = utils.find_resource(identity_client.users, + parsed_args.user).id + + kwargs['user'] = user_id + data = identity_client.projects.list(**kwargs) return (columns, (utils.get_item_properties(