示例#1
0
 def set_conn(self, val):
     if not isinstance(val, libvirt.virConnect):
         raise ValueError(_("'conn' must be a libvirt connection object."))
     if not util.is_storage_capable(val):
         raise ValueError(_("Passed connection is not libvirt storage "
                            "capable"))
     self._conn = val
示例#2
0
    def lookup_pool_by_name(pool_object=None, pool_name=None, conn=None):
        """
        Returns pool object determined from passed parameters.

        Largely a convenience function for the other static functions.
        """
        if pool_object is None and pool_name is None:
            raise ValueError(_("Must specify pool_object or pool_name"))

        if pool_name is not None and pool_object is None:
            if conn is None:
                raise ValueError(_("'conn' must be specified with 'pool_name'"))
            if not util.is_storage_capable(conn):
                raise ValueError(_("Connection does not support storage "
                                   "management."))
            try:
                pool_object = conn.storagePoolLookupByName(pool_name)
            except Exception, e:
                raise ValueError(_("Couldn't find storage pool '%s': %s" %
                                   (pool_name, str(e))))
    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 (not validated 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:
                logging.debug("Error validating install location",
                              exc_info=True)
                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 (not validated 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:
                logging.debug("Error validating install location", exc_info=True)
                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