def __init__(self, conn=None): """ Initialize device state @param conn: libvirt connection to validate device against @type conn: virConnect """ if not self._virtual_device_type: raise ValueError(_("Virtual device type must be set in subclass.")) if self._virtual_device_type not in self.virtual_device_types: raise ValueError(_("Unknown virtual device type '%s'.") % self._virtual_device_type) if conn: if not isinstance(conn, libvirt.virConnect): raise ValueError, _("'conn' must be a virConnect instance") self._conn = conn self.__remote = None if self.conn: self.__remote = _util.is_uri_remote(self.conn.getURI()) self._caps = None if self.conn: self._caps = CapabilitiesParser.parse(self.conn.getCapabilities())
def post_install_check(self, guest): """ Attempt to verify that installing to disk was successful. @param guest: guest instance that was installed @type L{Guest} """ if _util.is_uri_remote(guest.conn.getURI()): # XXX: Use block peek for this? return True if len(guest.disks) == 0 \ or guest.disks[0].device != VirtualDisk.DEVICE_DISK: return True if _util.is_vdisk(guest.disks[0].path): return True # Check for the 0xaa55 signature at the end of the MBR try: fd = os.open(guest.disks[0].path, os.O_RDONLY) except OSError, (err, msg): logging.debug("Failed to open guest disk: %s" % msg) if err == errno.EACCES and os.geteuid() != 0: return True # non root might not have access to block devices else: raise
def __init__(self, conn=None): """ Initialize device state @param conn: libvirt connection to validate device against @type conn: virConnect """ if not self._virtual_device_type: raise ValueError(_("Virtual device type must be set in subclass.")) if self._virtual_device_type not in self.virtual_device_types: raise ValueError( _("Unknown virtual device type '%s'.") % self._virtual_device_type) if conn: if not isinstance(conn, libvirt.virConnect): raise ValueError, _("'conn' must be a virConnect instance") self._conn = conn self.__remote = None if self.conn: self.__remote = _util.is_uri_remote(self.conn.getURI()) self._caps = None if self.conn: self._caps = CapabilitiesParser.parse(self.conn.getCapabilities())
def post_install_check(self, guest): """ Attempt to verify that installing to disk was successful. @param guest: guest instance that was installed @type L{Guest} """ if _util.is_uri_remote(guest.conn.getURI(), conn=guest.conn): # XXX: Use block peek for this? return True if (len(guest.disks) == 0 or guest.disks[0].device != VirtualDisk.DEVICE_DISK): return True disk = guest.disks[0] if _util.is_vdisk(disk.path): return True if (disk.driver_type and disk.driver_type not in [disk.DRIVER_TAP_RAW, disk.DRIVER_QEMU_RAW]): # Might be a non-raw format return True # Check for the 0xaa55 signature at the end of the MBR try: fd = os.open(disk.path, os.O_RDONLY) except OSError, (err, msg): logging.debug("Failed to open guest disk: %s", msg) if err == errno.EACCES and os.geteuid() != 0: return True # non root might not have access to block devices else: raise
def _daemon_lib_ver(conn, force_version): if force_version: default_ret = 0 else: default_ret = 100000000000 uri = conn.getURI() if not _util.is_uri_remote(uri): return _local_lib_ver() if not _has_command("getLibVersion", obj=conn): return default_ret if not _try_command(getattr(conn, "getLibVersion"), ()): return default_ret return conn.getLibVersion()
def _daemon_lib_ver(conn, force_version): if force_version: default_ret = 0 else: default_ret = 100000000000 uri = conn.getURI() if not _util.is_uri_remote(uri): return _local_lib_ver() if not _has_command("getLibVersion", obj=conn): return default_ret if not _try_command(getattr(conn, "getLibVersion"), ()): return default_ret return conn.getLibVersion()
def _daemon_lib_ver(conn, uri, force_version, minimum_libvirt_version): # Always force the required version if it's after the version which # has getLibVersion if force_version or minimum_libvirt_version >= 7004: default_ret = 0 else: default_ret = 100000000000 if not _util.is_uri_remote(uri, conn=conn): return _local_lib_ver() if not _has_command("getLibVersion", obj=conn): return default_ret if not _try_command(getattr(conn, "getLibVersion"), ()): return default_ret return conn.getLibVersion()
def _daemon_lib_ver(conn, uri, force_version, minimum_libvirt_version): # Always force the required version if it's after the version which # has getLibVersion if force_version or minimum_libvirt_version >= 7004: default_ret = 0 else: default_ret = 100000000000 if not _util.is_uri_remote(uri): return _local_lib_ver() if not _has_command("getLibVersion", obj=conn): return default_ret if not _try_command(getattr(conn, "getLibVersion"), ()): return default_ret return conn.getLibVersion()
def set_conn(self, val): if not isinstance(val, libvirt.virConnect): raise ValueError(_("'conn' must be a virConnect instance.")) self._conn = val self._conn_uri = self._conn.getURI() self.__remote = _util.is_uri_remote(self._conn_uri)
def set_conn(self, val): if not isinstance(val, libvirt.virConnect): raise ValueError(_("'conn' must be a virConnect instance.")) self._conn = val self._conn_uri = self._conn.getURI() self.__remote = _util.is_uri_remote(self._conn_uri, conn=self._conn)
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 _util.is_uri_remote(self.conn.getURI())) # 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 Exception, e: logging.debug(str(e)) raise ValueError( _("Checking installer location failed: " "Could not find media '%s'." % str(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 _util.is_uri_remote(self.conn.getURI())) # 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 Exception, e: logging.debug(str(e)) raise ValueError(_("Checking installer location failed: " "Could not find media '%s'." % str(val)))