Esempio n. 1
0
    def _copy_volume_from_snapshot(self, snapshot, volume, volume_size):
        """Copy data from snapshot to destination volume.

        This is done with a qemu-img convert to raw/qcow2 from the snapshot
        qcow2.
        """

        LOG.debug(
            "_copy_volume_from_snapshot: snapshot: %(snap)s, "
            "volume: %(vol)s, volume_size: %(size)s.", {
                'snap': snapshot['id'],
                'vol': volume['id'],
                'size': volume_size,
            })

        info_path = self._local_path_volume_info(snapshot['volume'])
        snap_info = self._read_info_file(info_path)
        vol_dir = self._local_volume_dir(snapshot['volume'])
        out_format = self.choose_volume_format(volume)
        qemu_out_format = image_utils.fixup_disk_format(out_format)
        volume_format = self.get_volume_format(snapshot.volume)
        volume_path = self.local_path(volume)

        forward_file = snap_info[snapshot['id']]
        forward_path = os.path.join(vol_dir, forward_file)

        if volume_format in (DISK_FORMAT_QCOW2, DISK_FORMAT_RAW):
            forward_file = snap_info[snapshot.id]
            forward_path = os.path.join(vol_dir, forward_file)

            # Find the file which backs this file, which represents the point
            # when this snapshot was created.
            img_info = self._qemu_img_info(forward_path, snapshot.volume.name)
            path_to_snap_img = os.path.join(vol_dir, img_info.backing_file)

            LOG.debug(
                "_copy_volume_from_snapshot: will copy "
                "from snapshot at %s.", path_to_snap_img)

            image_utils.convert_image(path_to_snap_img, volume_path,
                                      qemu_out_format)
        else:
            msg = _("Unsupported volume format %s") % volume_format
            raise exception.InvalidVolume(msg)

        self._extend_volume(volume, volume_size, out_format)
        # Query qemu-img info to cache the output
        img_info = self._qemu_img_info(volume_path, volume.name)
Esempio n. 2
0
    def _copy_volume_from_snapshot(self, snapshot, volume, volume_size):
        """Copy data from snapshot to destination volume.

        This is done with a qemu-img convert to raw/qcow2 from the snapshot
        qcow2.
        """

        info_path = self._local_path_volume_info(snapshot.volume)
        snap_info = self._read_info_file(info_path)
        vol_dir = self._local_volume_dir(snapshot.volume)
        out_format = self.choose_volume_format(volume)
        qemu_out_format = image_utils.fixup_disk_format(out_format)
        volume_format = self.get_volume_format(snapshot.volume)
        volume_path = self.local_path(volume)

        if volume_format in (DISK_FORMAT_QCOW2, DISK_FORMAT_RAW):
            forward_file = snap_info[snapshot.id]
            forward_path = os.path.join(vol_dir, forward_file)

            # Find the file which backs this file, which represents the point
            # when this snapshot was created.
            img_info = self._qemu_img_info(forward_path,
                                           snapshot.volume.name)
            path_to_snap_img = os.path.join(vol_dir, img_info.backing_file)

            LOG.debug("_copy_volume_from_snapshot: will copy "
                      "from snapshot at %s.", path_to_snap_img)

            image_utils.convert_image(path_to_snap_img,
                                      volume_path,
                                      qemu_out_format)
        elif volume_format == DISK_FORMAT_PLOOP:
            with PloopDevice(self.local_path(snapshot.volume),
                             snapshot.id,
                             execute=self._execute) as dev:
                base_file = os.path.join(volume_path, 'root.hds')
                image_utils.convert_image(dev,
                                          base_file,
                                          qemu_out_format)
        else:
            msg = _("Unsupported volume format %s") % volume_format
            raise exception.InvalidVolume(msg)

        self._extend_volume(volume, volume_size, out_format)
        # Query qemu-img info to cache the output
        img_info = self._qemu_img_info(volume_path, volume.name)
Esempio n. 3
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        volume_format = self.get_volume_format(volume)
        qemu_volume_format = image_utils.fixup_disk_format(volume_format)
        image_path = self.local_path(volume)
        if volume_format == DISK_FORMAT_PLOOP:
            image_path = os.path.join(image_path, PLOOP_BASE_DELTA_NAME)

        image_utils.fetch_to_volume_format(
            context, image_service, image_id, image_path, qemu_volume_format,
            self.configuration.volume_dd_blocksize)

        if volume_format == DISK_FORMAT_PLOOP:
            self._recreate_ploop_desc(self.local_path(volume), image_path)

        self._do_extend_volume(self.local_path(volume), volume.size,
                               volume_format)
        # Query qemu-img info to cache the output
        self._qemu_img_info(self.local_path(volume), volume.name)
Esempio n. 4
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        volume_format = self.get_volume_format(volume)
        qemu_volume_format = image_utils.fixup_disk_format(volume_format)
        image_path = self.local_path(volume)
        if volume_format == DISK_FORMAT_PLOOP:
            image_path = os.path.join(image_path, PLOOP_BASE_DELTA_NAME)

        image_utils.fetch_to_volume_format(
            context, image_service, image_id,
            image_path, qemu_volume_format,
            self.configuration.volume_dd_blocksize)

        if volume_format == DISK_FORMAT_PLOOP:
            self._recreate_ploop_desc(self.local_path(volume), image_path)

        self._do_extend_volume(self.local_path(volume),
                               volume.size,
                               volume_format)
        # Query qemu-img info to cache the output
        self._qemu_img_info(self.local_path(volume), volume.name)