コード例 #1
0
    def convert_disks(self, disk_format, destdir=None, dry=False):
        """
        Convert a disk into the requested format if possible, in the
        given output directory.  Raises RuntimeError or other failures.
        """
        if disk_format == "none":
            disk_format = None

        if destdir is None:
            destdir = StoragePool.get_default_path(self.conn, build=not dry)

        guest = self.get_guest()
        for disk in guest.get_devices("disk"):
            if disk.device != "disk":
                continue

            if disk_format and disk.driver_type == disk_format:
                logging.debug("path=%s is already in requested format=%s",
                              disk.path, disk_format)
                disk_format = None

            basepath = os.path.splitext(os.path.basename(disk.path))[0]
            newpath = re.sub(r'\s', '_', basepath)
            if disk_format:
                newpath += ("." + disk_format)
            newpath = os.path.join(destdir, newpath)
            if os.path.exists(newpath):
                raise RuntimeError(
                    _("New path name '%s' already exists") % newpath)

            if not disk_format or disk_format == "none":
                self._copy_file(disk.path, newpath, dry)
            else:
                self._qemu_convert(disk.path, newpath, disk_format, dry)
            disk.driver_type = disk_format
            disk.path = newpath
            self._err_clean.append(newpath)
コード例 #2
0
ファイル: formats.py プロジェクト: aurex-linux/virt-manager
    def convert_disks(self, disk_format, destdir=None, dry=False):
        """
        Convert a disk into the requested format if possible, in the
        given output directory.  Raises RuntimeError or other failures.
        """
        if disk_format == "none":
            disk_format = None

        if destdir is None:
            destdir = StoragePool.get_default_path(self.conn)

        guest = self.get_guest()
        for disk in guest.get_devices("disk"):
            if disk.device != "disk":
                continue

            if disk_format and disk.driver_type == disk_format:
                logging.debug("path=%s is already in requested format=%s",
                    disk.path, disk_format)
                disk_format = None

            basepath = os.path.splitext(os.path.basename(disk.path))[0]
            newpath = re.sub(r'\s', '_', basepath)
            if disk_format:
                newpath += ("." + disk_format)
            newpath = os.path.join(destdir, newpath)
            if os.path.exists(newpath):
                raise RuntimeError(_("New path name '%s' already exists") %
                    newpath)

            if not disk_format or disk_format == "none":
                self._copy_file(disk.path, newpath, dry)
            else:
                self._qemu_convert(disk.path, newpath, disk_format, dry)
            disk.driver_type = disk_format
            disk.path = newpath
            self._err_clean.append(newpath)