def generate_clone_disk_path(origpath, design, newname=None): origname = design.original_guest newname = newname or design.clone_name path = origpath suffix = "" # Try to split the suffix off the existing disk name. Ex. # foobar.img -> foobar-clone.img # # If the suffix is greater than 7 characters, assume it isn't # a file extension and is part of the disk name, at which point # just stick '-clone' on the end. if origpath.count(".") and len(origpath.rsplit(".", 1)[1]) <= 7: path, suffix = origpath.rsplit(".", 1) suffix = "." + suffix dirname = os.path.dirname(path) basename = os.path.basename(path) clonebase = basename + "-clone" if origname and basename == origname: clonebase = newname clonebase = os.path.join(dirname, clonebase) return _util.generate_name( clonebase, lambda p: VirtualDisk.path_exists(design.original_conn, p), suffix, lib_collision=False)
def _get_original_devices_info(self): clonelist = [] retdisks = [] for disk in self._guest.get_devices("disk"): if self._do_we_clone_device(disk): clonelist.append(disk) continue # Set up virtual disk to encapsulate all relevant path info for disk in clonelist: validate = not self.preserve_dest_disks try: if (disk.path and validate and not VirtualDisk.path_exists(self._hyper_conn, disk.path)): raise ValueError(_("Disk '%s' does not exist.") % disk.path) device = VirtualDisk.DEVICE_DISK if not disk.path: # Tell VirtualDisk we are a cdrom to allow empty media device = VirtualDisk.DEVICE_CDROM d = VirtualDisk(disk.path, conn=self._hyper_conn, device=device, driverType=disk.driver_type, validate=validate) d.target = disk.target except Exception, e: logging.debug("", exc_info=True) raise ValueError(_("Could not determine original disk " "information: %s" % str(e))) retdisks.append(d)
def generate_clone_disk_path(origpath, design): basename = origpath suffix = "" # Try to split the suffix off the existing disk name. Ex. # foobar.img -> foobar-clone.img # # If the suffix is greater than 7 characters, assume it isn't # a file extension and is part of the disk name, at which point # just stick '-clone' on the end. if basename.count(".") and len(basename.rsplit(".", 1)[1]) <= 7: basename, suffix = basename.rsplit(".", 1) suffix = "." + suffix return _util.generate_name(basename + "-clone", lambda p: VirtualDisk.path_exists(design.original_conn, p), suffix, lib_collision=False)
def _get_original_devices_info(self, xml): disks = [] lst = [] count = _util.get_xml_path(xml, "count(/domain/devices/disk)") for i in range(1, int(count + 1)): # Check if the disk needs cloning (path, target) = self._do_we_clone_device(xml, i) if target == None: continue lst.append((path, target)) # Set up virtual disk to encapsulate all relevant path info for path, target in lst: d = None validate = not self.preserve_dest_disks try: if (path and validate and not VirtualDisk.path_exists(self._hyper_conn, path)): raise ValueError(_("Disk '%s' does not exist.") % path) device = VirtualDisk.DEVICE_DISK if not path: # Tell VirtualDisk we are a cdrom to allow empty media device = VirtualDisk.DEVICE_CDROM d = VirtualDisk(path, conn=self._hyper_conn, device=device, validate=validate) d.target = target except Exception, e: _util.log_exception(e) raise ValueError( _("Could not determine original disk " "information: %s" % str(e))) disks.append(d)
def _get_original_devices_info(self, xml): disks = [] lst = [] count = _util.get_xml_path(xml, "count(/domain/devices/disk)") for i in range(1, int(count + 1)): # Check if the disk needs cloning (path, target) = self._do_we_clone_device(xml, i) if target == None: continue lst.append((path, target)) # Set up virtual disk to encapsulate all relevant path info for path, target in lst: d = None validate = not self.preserve_dest_disks try: if (path and validate and not VirtualDisk.path_exists(self._hyper_conn, path)): raise ValueError(_("Disk '%s' does not exist.") % path) device = VirtualDisk.DEVICE_DISK if not path: # Tell VirtualDisk we are a cdrom to allow empty media device = VirtualDisk.DEVICE_CDROM d = VirtualDisk(path, conn=self._hyper_conn, device=device, validate=validate) d.target = target except Exception, e: _util.log_exception(e) raise ValueError(_("Could not determine original disk " "information: %s" % str(e))) disks.append(d)