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: poolxml = StoragePool.build_default_pool(self.conn) destdir = poolxml.target_path guest = self.get_guest() for disk in guest.devices.disk: if disk.device != "disk": continue if disk_format and disk.driver_type == disk_format: log.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) and not _is_test(): 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)