def execute(self, args): image_mgr = ImageManager(self.client) image_id = resolve_id(image_mgr.resolve_ids, args.get('<identifier>'), 'image') image_mgr.delete_image(image_id)
def execute(self, args): image_mgr = ImageManager(self.client) neither = not any([args['--private'], args['--public']]) mask = 'id,accountId,name,globalIdentifier,blockDevices,parentId' images = [] if args['--private'] or neither: for image in image_mgr.list_private_images(mask=mask): image['visibility'] = 'private' images.append(image) if args['--public'] or neither: for image in image_mgr.list_public_images(mask=mask): image['visibility'] = 'public' images.append(image) t = Table(['id', 'account', 'visibility', 'name', 'global_identifier']) images = filter(lambda x: x['parentId'] == '', images) for image in images: t.add_row([ image['id'], image.get('accountId', blank()), image['visibility'], image['name'].strip(), image.get('globalIdentifier', blank()), ]) return t
def getImageTemplateGuid(self, imageName): imgManager = ImageManager(self.Client) images = imgManager.list_private_images(name=imageName) if len(images) == 1: return images[0]['globalIdentifier'] else: return None
def execute(self, args): image_mgr = ImageManager(self.client) data = {} if args.get('--name'): data['name'] = args.get('--name') if args.get('--note'): data['note'] = args.get('--note') if args.get('--tag'): data['tag'] = args.get('--tag') image_id = resolve_id(image_mgr.resolve_ids, args.get('<identifier>'), 'image') if not image_mgr.edit(image_id, **data): raise CLIAbort("Failed to Edit Image")
def execute(self, args): image_mgr = ImageManager(self.client) image_id = resolve_id(image_mgr.resolve_ids, args.get('<identifier>'), 'image') image = image_mgr.get_image(image_id) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' t.add_row(['id', image['id']]) t.add_row(['account', image.get('accountId', blank())]) t.add_row(['name', image['name'].strip()]) t.add_row(['global_identifier', image.get('globalIdentifier', blank())]) return t
def listImages(): imgManager = ImageManager(client) imgs = imgManager.list_private_images() return imgs
def listImages(name=None): imgManager = ImageManager(client) imgs = imgManager.list_private_images(name=name) return imgs
def deleteImage(id): imgManager = ImageManager(client) imgManager.delete_image(image_id=id)
def setUp(self): self.client = FixtureClient() self.image = ImageManager(self.client) self.vgbdtg = self.client['Virtual_Guest_Block_Device_Template_Group'] self.account = self.client['Account']
class ImageTests(unittest.TestCase): def setUp(self): self.client = FixtureClient() self.image = ImageManager(self.client) self.vgbdtg = self.client['Virtual_Guest_Block_Device_Template_Group'] self.account = self.client['Account'] def test_get_image(self): result = self.image.get_image(100) self.vgbdtg.getObject.assert_called_once_with(id=100, mask=ANY) self.assertEqual(result, Virtual_Guest_Block_Device_Template_Group.getObject) def test_delete_image(self): self.image.delete_image(100) self.vgbdtg.deleteObject.assert_called_once_with(id=100) def test_list_private_images(self): results = self.image.list_private_images() f = self.account.getPrivateBlockDeviceTemplateGroups f.assert_called_once_with(filter={}, mask=ANY) self.assertEqual(results, Account.getPrivateBlockDeviceTemplateGroups) def test_list_private_images_with_filters(self): results = self.image.list_private_images( guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name') f = self.account.getPrivateBlockDeviceTemplateGroups f.assert_called_once_with( filter={ 'privateBlockDeviceTemplateGroups': { 'globalIdentifier': { 'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'}, 'name': {'operation': '_= name'}}}, mask=ANY) self.assertEqual(results, Account.getPrivateBlockDeviceTemplateGroups) def test_list_public_images(self): results = self.image.list_public_images() self.vgbdtg.getPublicImages.assert_called_once_with(filter={}, mask=ANY) self.assertEqual( results, Virtual_Guest_Block_Device_Template_Group.getPublicImages) def test_list_public_images_with_filters(self): results = self.image.list_public_images( guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name') self.vgbdtg.getPublicImages.assert_called_once_with( filter={ 'globalIdentifier': { 'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'}, 'name': {'operation': '_= name'}}, mask=ANY) self.assertEqual( results, Virtual_Guest_Block_Device_Template_Group.getPublicImages) def test_resolve_ids_guid(self): result = self.image.resolve_ids('3C1F3C68-0B67-4F5E-8907-D0FC84BF3F12') self.assertEquals(['3C1F3C68-0B67-4F5E-8907-D0FC84BF3F12'], result) def test_resolve_ids_name_public(self): self.vgbdtg.getPublicImages.return_value = [{'id': 100}] self.account.getPrivateBlockDeviceTemplateGroups.return_value = [] result = self.image.resolve_ids('image_name') self.assertEquals([100], result) def test_resolve_ids_name_private(self): self.vgbdtg.getPublicImages.return_value = [] self.account.getPrivateBlockDeviceTemplateGroups.return_value = \ [{'id': 100}] result = self.image.resolve_ids('private_image_name') self.assertEquals([100], result) def test_resolve_ids_not_found(self): self.vgbdtg.getPublicImages.return_value = [] self.account.getPrivateBlockDeviceTemplateGroups.return_value = [] result = self.image.resolve_ids('unknown_name') self.assertEquals([], result)
def listImages(): imgManager = ImageManager(client) imgs = imgManager.list_private_images() print json.dumps(imgs, sort_keys=True, indent=4) return imgs