Skip to content

Commit 7b530a0

Browse files
Merge branch 'caberos-issue1993'
2 parents 3f13fe8 + 5ee003f commit 7b530a0

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

SoftLayer/CLI/image/list.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414
@click.option('--name', default=None, help='Filter on image name')
1515
@click.option('--public/--private', is_flag=True, default=None,
1616
help='Display only public or private images')
17+
@click.option('--limit', '-l',
18+
help='How many results to get in one api call',
19+
default=100,
20+
show_default=True)
1721
@environment.pass_env
18-
def cli(env, name, public):
22+
def cli(env, name, public, limit):
1923
"""List images."""
2024

2125
image_mgr = SoftLayer.ImageManager(env.client)
2226

2327
images = []
2428
if public in [False, None]:
25-
for image in image_mgr.list_private_images(name=name, mask=image_mod.MASK):
29+
for image in image_mgr.list_private_images(name=name, limit=limit, mask=image_mod.MASK):
2630
images.append(image)
2731

2832
if public in [True, None]:
29-
for image in image_mgr.list_public_images(name=name, mask=image_mod.MASK):
33+
for image in image_mgr.list_public_images(name=name, limit=limit, mask=image_mod.MASK):
3034
images.append(image)
3135

3236
table = formatting.Table(['Id', 'Name', 'Type', 'Visibility', 'Account', 'OS', 'Created', 'Notes'])

SoftLayer/managers/image.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def delete_image(self, image_id):
4646
"""
4747
self.vgbdtg.deleteObject(id=image_id)
4848

49-
def list_private_images(self, guid=None, name=None, **kwargs):
49+
def list_private_images(self, guid=None, name=None, limit=100, **kwargs):
5050
"""List all private images.
5151
5252
:param string guid: filter based on GUID
@@ -67,8 +67,8 @@ def list_private_images(self, guid=None, name=None, **kwargs):
6767

6868
kwargs['filter'] = _filter.to_dict()
6969

70-
account = self.client['Account']
71-
return account.getPrivateBlockDeviceTemplateGroups(**kwargs)
70+
return self.client.iter_call('SoftLayer_Account', 'getPrivateBlockDeviceTemplateGroups',
71+
filter=kwargs['filter'], mask=kwargs['mask'], limit=limit)
7272

7373
def list_public_images(self, guid=None, name=None, limit=100, **kwargs):
7474
"""List all public images.
@@ -89,7 +89,8 @@ def list_public_images(self, guid=None, name=None, limit=100, **kwargs):
8989

9090
kwargs['filter'] = _filter.to_dict()
9191

92-
return self.vgbdtg.getPublicImages(**kwargs, limit=limit)
92+
return self.client.iter_call('SoftLayer_Virtual_Guest_Block_Device_Template_Group', 'getPublicImages',
93+
filter=kwargs['filter'], mask=kwargs['mask'], limit=limit)
9394

9495
def _get_ids_from_name_public(self, name):
9596
"""Get public images which match the given name."""

tests/managers/image_tests.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,41 @@ def test_delete_image(self):
3333
self.assert_called_with(IMAGE_SERVICE, 'deleteObject', identifier=100)
3434

3535
def test_list_private_images(self):
36-
results = self.image.list_private_images()
37-
36+
# Casting to list() to force the iter_call generator to run
37+
results = list(self.image.list_private_images())
3838
self.assertEqual(len(results), 2)
39-
self.assert_called_with('SoftLayer_Account',
40-
'getPrivateBlockDeviceTemplateGroups')
39+
self.assert_called_with('SoftLayer_Account', 'getPrivateBlockDeviceTemplateGroups')
4140

4241
def test_list_private_images_with_filters(self):
43-
results = self.image.list_private_images(
44-
guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name')
42+
# Casting to list() to force the iter_call generator to run
43+
results = list(self.image.list_private_images(guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name'))
4544

46-
self.assertEqual(len(results), 2)
4745
_filter = {
4846
'privateBlockDeviceTemplateGroups': {
4947
'globalIdentifier': {
5048
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
5149
'name': {'operation': '_= name'}}
5250
}
53-
self.assert_called_with('SoftLayer_Account',
54-
'getPrivateBlockDeviceTemplateGroups',
55-
filter=_filter)
51+
self.assertEqual(len(results), 2)
52+
self.assert_called_with('SoftLayer_Account', 'getPrivateBlockDeviceTemplateGroups', filter=_filter)
5653

5754
def test_list_public_images(self):
58-
results = self.image.list_public_images()
59-
55+
# Casting to list() to force the iter_call generator to run
56+
results = list(self.image.list_public_images())
6057
self.assertEqual(len(results), 2)
6158
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages')
6259

6360
def test_list_public_images_with_filters(self):
64-
results = self.image.list_public_images(
65-
guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name')
66-
61+
# Casting to list() to force the iter_call generator to run
62+
results = list(self.image.list_public_images(guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name'))
63+
self.assertEqual(len(results), 2)
6764
_filter = {
6865
'globalIdentifier': {
6966
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
7067
'name': {'operation': '_= name'}
7168
}
72-
self.assertEqual(len(results), 2)
73-
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages',
74-
filter=_filter)
69+
70+
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages', filter=_filter)
7571

7672
def test_resolve_ids_guid(self):
7773
result = self.image.resolve_ids('3C1F3C68-0B67-4F5E-8907-D0FC84BF3F12')

0 commit comments

Comments
 (0)