Add the ability to list projects based on a user

Essentially performing GET /users/{user_id}/projects

Change-Id: Iae6ddfc86a856fa24fbe293ec4af52ea671390f8
Closes-Bug: #1394793
This commit is contained in:
Steve Martinelli 2014-11-20 18:42:00 -05:00
parent 4b239eea42
commit 5bc768bbc2
2 changed files with 29 additions and 2 deletions

View File

@ -79,6 +79,7 @@ List projects
os project list os project list
[--domain <domain>] [--domain <domain>]
[--user <user>]
[--long] [--long]
.. option:: --domain <domain> .. option:: --domain <domain>
@ -87,6 +88,12 @@ List projects
.. versionadded:: 3 .. versionadded:: 3
.. option:: --user <user>
Filter projects by :option:`\<user\> <--user>` (name or ID)
.. versionadded:: 3
.. option:: --long .. option:: --long
List additional fields in output List additional fields in output

View File

@ -162,6 +162,11 @@ class ListProject(lister.Lister):
metavar='<domain>', metavar='<domain>',
help='Filter projects by <domain> (name or ID)', help='Filter projects by <domain> (name or ID)',
) )
parser.add_argument(
'--user',
metavar='<user>',
help='Filter projects by <user> (name or ID)',
)
parser.add_argument( parser.add_argument(
'--long', '--long',
action='store_true', action='store_true',
@ -178,9 +183,24 @@ class ListProject(lister.Lister):
else: else:
columns = ('ID', 'Name') columns = ('ID', 'Name')
kwargs = {} kwargs = {}
domain_id = None
if parsed_args.domain: if parsed_args.domain:
kwargs['domain'] = common.find_domain(identity_client, domain_id = common.find_domain(identity_client,
parsed_args.domain).id 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) data = identity_client.projects.list(**kwargs)
return (columns, return (columns,
(utils.get_item_properties( (utils.get_item_properties(