Merge "Allow v1 client to list all users' images"
This commit is contained in:
@@ -219,6 +219,8 @@ class ImageManager(base.Manager):
|
||||
if kwargs.get('owner') is not None:
|
||||
params['owner'] = kwargs['owner']
|
||||
params['is_public'] = None
|
||||
if 'is_public' in kwargs:
|
||||
params['is_public'] = kwargs['is_public']
|
||||
|
||||
return paginate(params)
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ DISK_FORMATS = ('Acceptable formats: ami, ari, aki, vhd, vmdk, raw, '
|
||||
'to list images with no owner. Note: This option overrides '
|
||||
'the --is-public argument if present. Note: the v2 API '
|
||||
'supports more efficient server-side owner based filtering.')
|
||||
@utils.arg('--all-tenants', action='store_true', default=False,
|
||||
help=('Allows the admin user to list all images '
|
||||
'irrespective of the image\'s owner or is_public value.'))
|
||||
def do_image_list(gc, args):
|
||||
"""List images you can access."""
|
||||
filter_keys = ['name', 'status', 'container_format', 'disk_format',
|
||||
@@ -91,6 +94,8 @@ def do_image_list(gc, args):
|
||||
kwargs['sort_key'] = args.sort_key
|
||||
kwargs['sort_dir'] = args.sort_dir
|
||||
kwargs['owner'] = args.owner
|
||||
if args.all_tenants is True:
|
||||
kwargs['is_public'] = None
|
||||
|
||||
images = gc.images.list(**kwargs)
|
||||
|
||||
|
||||
+21
-2
@@ -75,17 +75,20 @@ fixtures = {
|
||||
{
|
||||
'id': 'a',
|
||||
'owner': 'A',
|
||||
'is_public': 'True',
|
||||
'name': 'image-1',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
{
|
||||
'id': 'b',
|
||||
'owner': 'B',
|
||||
'is_public': 'False',
|
||||
'name': 'image-2',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
{
|
||||
'id': 'c',
|
||||
'is_public': 'False',
|
||||
'name': 'image-3',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
@@ -129,12 +132,14 @@ fixtures = {
|
||||
{
|
||||
'id': 'a',
|
||||
'owner': 'A',
|
||||
'is_public': 'False',
|
||||
'name': 'image-1',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
{
|
||||
'id': 'b',
|
||||
'owner': 'B',
|
||||
'owner': 'A',
|
||||
'is_public': 'False',
|
||||
'name': 'image-2',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
@@ -146,6 +151,7 @@ fixtures = {
|
||||
},
|
||||
{
|
||||
'id': 'c',
|
||||
'is_public': 'True',
|
||||
'name': 'image-3',
|
||||
'properties': {'arch': 'x86_64'},
|
||||
},
|
||||
@@ -608,7 +614,7 @@ class ImageManagerTest(testtools.TestCase):
|
||||
image_list = list(images)
|
||||
self.assertEqual(image_list[0].owner, 'A')
|
||||
self.assertEqual(image_list[0].id, 'a')
|
||||
self.assertEqual(image_list[1].owner, 'B')
|
||||
self.assertEqual(image_list[1].owner, 'A')
|
||||
self.assertEqual(image_list[1].id, 'b')
|
||||
self.assertEqual(image_list[2].owner, 'B')
|
||||
self.assertEqual(image_list[2].id, 'b2')
|
||||
@@ -623,6 +629,19 @@ class ImageManagerTest(testtools.TestCase):
|
||||
self.assertEqual(image_list[0].id, 'b')
|
||||
self.assertEqual(len(image_list), 1)
|
||||
|
||||
def test_image_list_all_tenants(self):
|
||||
images = self.mgr.list(is_public=None, page_size=5)
|
||||
image_list = list(images)
|
||||
self.assertEqual(image_list[0].owner, 'A')
|
||||
self.assertEqual(image_list[0].id, 'a')
|
||||
self.assertEqual(image_list[1].owner, 'B')
|
||||
self.assertEqual(image_list[1].id, 'b')
|
||||
self.assertEqual(image_list[2].owner, 'B')
|
||||
self.assertEqual(image_list[2].id, 'b2')
|
||||
self.assertRaises(AttributeError, lambda: image_list[3].owner)
|
||||
self.assertEqual(image_list[3].id, 'c')
|
||||
self.assertEqual(len(image_list), 4)
|
||||
|
||||
|
||||
class ImageTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user