Skip to content

Commit

Permalink
Merge branch 'caberos-issue1993'
Browse files Browse the repository at this point in the history
  • Loading branch information
allmightyspiff committed Jul 13, 2023
2 parents 3f13fe8 + 5ee003f commit 7b530a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
10 changes: 7 additions & 3 deletions SoftLayer/CLI/image/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
@click.option('--name', default=None, help='Filter on image name')
@click.option('--public/--private', is_flag=True, default=None,
help='Display only public or private images')
@click.option('--limit', '-l',
help='How many results to get in one api call',
default=100,
show_default=True)
@environment.pass_env
def cli(env, name, public):
def cli(env, name, public, limit):
"""List images."""

image_mgr = SoftLayer.ImageManager(env.client)

images = []
if public in [False, None]:
for image in image_mgr.list_private_images(name=name, mask=image_mod.MASK):
for image in image_mgr.list_private_images(name=name, limit=limit, mask=image_mod.MASK):
images.append(image)

if public in [True, None]:
for image in image_mgr.list_public_images(name=name, mask=image_mod.MASK):
for image in image_mgr.list_public_images(name=name, limit=limit, mask=image_mod.MASK):
images.append(image)

table = formatting.Table(['Id', 'Name', 'Type', 'Visibility', 'Account', 'OS', 'Created', 'Notes'])
Expand Down
9 changes: 5 additions & 4 deletions SoftLayer/managers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def delete_image(self, image_id):
"""
self.vgbdtg.deleteObject(id=image_id)

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

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

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

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

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

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

def _get_ids_from_name_public(self, name):
"""Get public images which match the given name."""
Expand Down
32 changes: 14 additions & 18 deletions tests/managers/image_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,41 @@ def test_delete_image(self):
self.assert_called_with(IMAGE_SERVICE, 'deleteObject', identifier=100)

def test_list_private_images(self):
results = self.image.list_private_images()

# Casting to list() to force the iter_call generator to run
results = list(self.image.list_private_images())
self.assertEqual(len(results), 2)
self.assert_called_with('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups')
self.assert_called_with('SoftLayer_Account', 'getPrivateBlockDeviceTemplateGroups')

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

self.assertEqual(len(results), 2)
_filter = {
'privateBlockDeviceTemplateGroups': {
'globalIdentifier': {
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
'name': {'operation': '_= name'}}
}
self.assert_called_with('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups',
filter=_filter)
self.assertEqual(len(results), 2)
self.assert_called_with('SoftLayer_Account', 'getPrivateBlockDeviceTemplateGroups', filter=_filter)

def test_list_public_images(self):
results = self.image.list_public_images()

# Casting to list() to force the iter_call generator to run
results = list(self.image.list_public_images())
self.assertEqual(len(results), 2)
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages')

def test_list_public_images_with_filters(self):
results = self.image.list_public_images(
guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name')

# Casting to list() to force the iter_call generator to run
results = list(self.image.list_public_images(guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name'))
self.assertEqual(len(results), 2)
_filter = {
'globalIdentifier': {
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
'name': {'operation': '_= name'}
}
self.assertEqual(len(results), 2)
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages',
filter=_filter)

self.assert_called_with(IMAGE_SERVICE, 'getPublicImages', filter=_filter)

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

0 comments on commit 7b530a0

Please sign in to comment.