def run(self, cfg, migration): cloud = cfg.clouds[getattr(migration, self.location)] image_client = clients.image_client(cloud) try: with model.Session() as session: object_id = model.ObjectId(self.image_id, cloud.name) session.delete(image.Image, object_id=object_id) clients.retry(image_client.images.delete, self.image_id, expected_exceptions=[glance_exceptions.NotFound]) except glance_exceptions.NotFound: pass
def discover_one(self, uuid): image_client = clients.image_client(self.cloud) try: raw_image = self.retry( image_client.images.get, uuid, expected_exceptions=[glance_exc.HTTPNotFound]) img = self.load_from_cloud(raw_image) with model.Session() as session: session.store(img) self._populate_members(img, image_client) return img except glance_exc.HTTPNotFound: raise discover.NotFound()
def _upload_cirros_image(self, session): image_client = clients.image_client(self.cloud) with open(_get_image_location(), 'r') as f: img = image_client.images.create(data=f, name=IMAGE_FILENAME, container_format='bare', disk_format='qcow2', is_public=False, protected=False, owner=_get_admin_tenant_id( self.cloud, session)) return clients.wait_for(_object_status_is, image_client, 'images', img.id, 'active')
def _find_supported_cirros_image(self, session): image_client = clients.image_client(self.cloud) for img in session.list(image.Image, self.cloud): if img.checksum.lower() == _get_image_md5(): # Test if image is good image_id = img.object_id.id try: next(image_client.images.data(image_id)) except Exception: LOG.debug('Failed to download part of image %s from %s', image_id, self.location) continue return image_id return None
def discover_one(self, uuid): image_client = clients.image_client(self.cloud) try: raw_image = self.retry( image_client.images.get, uuid, expected_exceptions=[glance_exc.HTTPNotFound]) img = self.load_from_cloud(raw_image) with model.Session() as session: session.store(img) self._populate_members(img, image_client) return img except glance_exc.HTTPNotFound: raise discover.NotFound()
def discover_all(self): images = [] image_client = clients.image_client(self.cloud) raw_images = self.retry(image_client.images.list, filters={'is_public': None, 'status': 'active'}, returns_iterable=True) for raw_image in raw_images: try: images.append(self.load_from_cloud(raw_image)) except model.ValidationError as e: LOG.warning('Invalid image %s in cloud %s: %s', raw_image.id, self.cloud.name, e) with model.Session() as session: for img in images: session.store(img) for img in images: self._populate_members(img, image_client)
def discover_all(self): images = [] image_client = clients.image_client(self.cloud) raw_images = self.retry(image_client.images.list, filters={ 'is_public': None, 'status': 'active' }, returns_iterable=True) for raw_image in raw_images: try: images.append(self.load_from_cloud(raw_image)) except model.ValidationError as e: LOG.warning('Invalid image %s in cloud %s: %s', raw_image.id, self.cloud.name, e) with model.Session() as session: for img in images: session.store(img) for img in images: self._populate_members(img, image_client)
def dst_glance(self): dst_cloud = self.config.clouds[self.migration.destination] return clients.image_client(dst_cloud)
def src_glance(self): src_cloud = self.config.clouds[self.migration.source] return clients.image_client(src_cloud)
def image_client(self, scope=None): # pylint: disable=no-member return clients.image_client(self.credential, scope or self.scope)
def dst_glance(self): dst_cloud = self.config.clouds[self.migration.destination] return clients.image_client(dst_cloud)
def src_glance(self): src_cloud = self.config.clouds[self.migration.source] return clients.image_client(src_cloud)