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)
def do_creds(creds, cbdata): try: return _do_creds(creds, cbdata) except: _util.log_exception("Error in creds callback.") raise
def fail(msg): """Convenience function when failing in cli app""" logging.error(msg) _util.log_exception() _fail_exit()
def set_location(self, val): """ Valid values for location: 1) it can be a local file (ex. boot.iso), directory (ex. distro tree) or physical device (ex. cdrom media) 2) tuple of the form (poolname, volname) pointing to a file or device which will set location as that path 3) http, ftp, or nfs path for an install tree """ is_tuple = False validated = True self._location_is_path = True is_local = (not self.conn or not self.is_remote()) # Basic validation if type(val) is not str and (type(val) is not tuple and len(val) != 2): raise ValueError(_("Invalid 'location' type %s." % type(val))) if type(val) is tuple and len(val) == 2: logging.debug("DistroInstaller location is a (poolname, volname)" " tuple") if not self.conn: raise ValueError(_("'conn' must be specified if 'location' is" " a storage tuple.")) is_tuple = True elif _is_url(val, is_local): val = _sanitize_url(val) self._location_is_path = False logging.debug("DistroInstaller location is a network source.") elif os.path.exists(os.path.abspath(val)) and is_local: val = os.path.abspath(val) logging.debug("DistroInstaller location is a local " "file/path: %s", val) else: # Didn't determine anything about the location validated = False if self._location_is_path or (validated == False and self.conn and _util.is_storage_capable(self.conn)): # If user passed a storage tuple, OR # We couldn't determine the location type and a storage capable # connection was passed: # Pass the parameters off to VirtualDisk to validate, and pull # out the path stuple = (is_tuple and val) or None path = (not is_tuple and val) or None try: d = VirtualDisk(path=path, device=VirtualDisk.DEVICE_CDROM, transient=True, readOnly=True, conn=self.conn, volName=stuple) val = d.path except: _util.log_exception("Error validating install location") raise ValueError(_("Checking installer location failed: " "Could not find media '%s'." % str(val))) elif not validated: raise ValueError(_("Install media location must be an NFS, HTTP " "or FTP network install source, or an existing " "file/device")) if (not self._location_is_path and val.startswith("nfs:") and not User.current().has_priv(User.PRIV_NFS_MOUNT, (self.conn and self.get_uri()))): raise ValueError(_('Privilege is required for NFS installations')) self._location = val
def set_location(self, val): """ Valid values for location: 1) it can be a local file (ex. boot.iso), directory (ex. distro tree) or physical device (ex. cdrom media) 2) tuple of the form (poolname, volname) pointing to a file or device which will set location as that path 3) http, ftp, or nfs path for an install tree """ is_tuple = False validated = True self._location_is_path = True is_local = (not self.conn or not self.is_remote()) # Basic validation if type(val) is not str and (type(val) is not tuple and len(val) != 2): raise ValueError(_("Invalid 'location' type %s." % type(val))) if type(val) is tuple and len(val) == 2: logging.debug("DistroInstaller location is a (poolname, volname)" " tuple") if not self.conn: raise ValueError( _("'conn' must be specified if 'location' is" " a storage tuple.")) is_tuple = True elif _is_url(val, is_local): val = _sanitize_url(val) self._location_is_path = False logging.debug("DistroInstaller location is a network source.") elif os.path.exists(os.path.abspath(val)) and is_local: val = os.path.abspath(val) logging.debug( "DistroInstaller location is a local " "file/path: %s", val) else: # Didn't determine anything about the location validated = False if self._location_is_path or (validated == False and self.conn and _util.is_storage_capable(self.conn)): # If user passed a storage tuple, OR # We couldn't determine the location type and a storage capable # connection was passed: # Pass the parameters off to VirtualDisk to validate, and pull # out the path stuple = (is_tuple and val) or None path = (not is_tuple and val) or None try: d = VirtualDisk(path=path, device=VirtualDisk.DEVICE_CDROM, transient=True, readOnly=True, conn=self.conn, volName=stuple) val = d.path except: _util.log_exception("Error validating install location") raise ValueError( _("Checking installer location failed: " "Could not find media '%s'." % str(val))) elif not validated: raise ValueError( _("Install media location must be an NFS, HTTP " "or FTP network install source, or an existing " "file/device")) if (not self._location_is_path and val.startswith("nfs:") and not User.current().has_priv(User.PRIV_NFS_MOUNT, (self.conn and self.get_uri()))): raise ValueError(_('Privilege is required for NFS installations')) self._location = val