Beispiel #1
0
 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
Beispiel #2
0
 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()
Beispiel #3
0
 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')
Beispiel #4
0
 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
Beispiel #5
0
 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()
Beispiel #6
0
    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)
Beispiel #7
0
    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)
Beispiel #8
0
 def dst_glance(self):
     dst_cloud = self.config.clouds[self.migration.destination]
     return clients.image_client(dst_cloud)
Beispiel #9
0
 def src_glance(self):
     src_cloud = self.config.clouds[self.migration.source]
     return clients.image_client(src_cloud)
Beispiel #10
0
 def image_client(self, scope=None):
     # pylint: disable=no-member
     return clients.image_client(self.credential, scope or self.scope)
Beispiel #11
0
 def dst_glance(self):
     dst_cloud = self.config.clouds[self.migration.destination]
     return clients.image_client(dst_cloud)
Beispiel #12
0
 def src_glance(self):
     src_cloud = self.config.clouds[self.migration.source]
     return clients.image_client(src_cloud)