Add list by user to shell

Adds "--user" as a search option to the list command.

Also since seach by tenant or user also needs all_tenants=1 add
this to the seach options automatically instead of making users
remember to add it

Change-Id: Icc828080b400aecdb320b721c569992677848cc6
This commit is contained in:
Phil Day 2014-09-18 17:38:30 +00:00
parent 3e5dae84a8
commit 2e64986532
2 changed files with 19 additions and 0 deletions

View File

@ -838,6 +838,16 @@ class ShellTest(utils.TestCase):
self.run_command('list --flavor 1')
self.assert_called('GET', '/servers/detail?flavor=1')
def test_list_by_tenant(self):
self.run_command('list --tenant fake_tenant')
self.assert_called('GET',
'/servers/detail?all_tenants=1&tenant_id=fake_tenant')
def test_list_by_user(self):
self.run_command('list --user fake_user')
self.assert_called('GET',
'/servers/detail?all_tenants=1&user_id=fake_user')
def test_list_fields(self):
output = self.run_command('list --fields '
'host,security_groups,OS-EXT-MOD:some_thing')

View File

@ -1176,6 +1176,11 @@ def do_image_delete(cs, args):
metavar='<tenant>',
nargs='?',
help=_('Display information from single tenant (Admin only).'))
@utils.arg('--user',
dest='user',
metavar='<user>',
nargs='?',
help=_('Display information from single user (Admin only).'))
@utils.arg('--deleted',
dest='deleted',
action="store_true",
@ -1199,6 +1204,9 @@ def do_list(cs, args):
imageid = _find_image(cs, args.image).id
if args.flavor:
flavorid = _find_flavor(cs, args.flavor).id
# search by tenant or user only works with all_tenants
if args.tenant or args.user:
args.all_tenants = 1
search_opts = {
'all_tenants': args.all_tenants,
'reservation_id': args.reservation_id,
@ -1209,6 +1217,7 @@ def do_list(cs, args):
'flavor': flavorid,
'status': args.status,
'tenant_id': args.tenant,
'user_id': args.user,
'host': args.host,
'deleted': args.deleted,
'instance_name': args.instance_name}