Exemple #1
0
    def _delete_image(self, image_name, snapshot_name):
        """
        Find the image file to delete.

        :param image_name Image's name
        :param snapshot_name Image snapshot's name

        :raises NotFound if image does not exist;
                InUseByStore if image is in use or snapshot unprotect failed
        """
        with rados.Rados(conffile=self.conf_file, rados_id=self.user) as conn:
            with conn.open_ioctx(self.pool) as ioctx:
                if snapshot_name:
                    with rbd.Image(ioctx, image_name) as image:
                        try:
                            image.unprotect_snap(snapshot_name)
                        except rbd.ImageBusy:
                            log_msg = _("snapshot %s@%s could not be "
                                        "unprotected because it is in use")
                            LOG.debug(log_msg % (image_name, snapshot_name))
                            raise exception.InUseByStore()
                        image.remove_snap(snapshot_name)
                try:
                    rbd.RBD().remove(ioctx, image_name)
                except rbd.ImageNotFound:
                    raise exception.NotFound(
                        _("RBD image %s does not exist") % image_name)
                except rbd.ImageBusy:
                    log_msg = _("image %s could not be removed "
                                "because it is in use")
                    LOG.debug(log_msg % image_name)
                    raise exception.InUseByStore()
Exemple #2
0
    def delete(self, location):
        """
        Takes a `glance.store.location.Location` object that indicates
        where to find the image file to delete

        :location `glance.store.location.Location` object, supplied
                  from glance.store.location.get_location_from_uri()

        :raises NotFound if image does not exist
        """
        loc = location.store_location

        with rados.Rados(conffile=self.conf_file, rados_id=self.user) as conn:
            with conn.open_ioctx(self.pool) as ioctx:
                if loc.snapshot:
                    with rbd.Image(ioctx, loc.image) as image:
                        try:
                            image.unprotect_snap(loc.snapshot)
                        except rbd.ImageBusy:
                            log_msg = _("snapshot %s@%s could not be "
                                        "unprotected because it is in use")
                            LOG.debug(log_msg % (loc.image, loc.snapshot))
                            raise exception.InUseByStore()
                        image.remove_snap(loc.snapshot)
                try:
                    rbd.RBD().remove(ioctx, loc.image)
                except rbd.ImageNotFound:
                    raise exception.NotFound(
                        _('RBD image %s does not exist') % loc.image)
                except rbd.ImageBusy:
                    log_msg = _("image %s could not be removed"
                                "because it is in use")
                    LOG.debug(log_msg % loc.image)
                    raise exception.InUseByStore()
Exemple #3
0
    def _delete_image(self, image_name, snapshot_name=None):
        """
        Delete RBD image and snapshot.

        :param image_name Image's name
        :param snapshot_name Image snapshot's name

        :raises NotFound if image does not exist;
                InUseByStore if image is in use or snapshot unprotect failed
        """
        with rados.Rados(conffile=self.conf_file, rados_id=self.user) as conn:
            with conn.open_ioctx(self.pool) as ioctx:
                try:
                    # First remove snapshot.
                    if snapshot_name is not None:
                        with rbd.Image(ioctx, image_name) as image:
                            try:
                                image.unprotect_snap(snapshot_name)
                            except rbd.ImageBusy:
                                log_msg = _("snapshot %(image)s@%(snap)s "
                                            "could not be unprotected because "
                                            "it is in use")
                                LOG.debug(log_msg % {
                                    'image': image_name,
                                    'snap': snapshot_name
                                })
                                raise exception.InUseByStore()
                            image.remove_snap(snapshot_name)

                    # Then delete image.
                    rbd.RBD().remove(ioctx, image_name)
                except rbd.ImageNotFound:
                    raise exception.NotFound(
                        _("RBD image %s does not exist") % image_name)
                except rbd.ImageBusy:
                    log_msg = _("image %s could not be removed "
                                "because it is in use")
                    LOG.debug(log_msg % image_name)
                    raise exception.InUseByStore()
Exemple #4
0
 def _fake_delete_image(*args, **kwargs):
     self.called_commands_actual.append('delete')
     raise exception.InUseByStore()