示例#1
0
    def _setup_url_image(self):
        """ Check to make sure the url is available and estimate the space
            needed to download and install it.
        """
        self._proxies = {}
        if self.data.method.proxy:
            try:
                proxy = ProxyString(self.data.method.proxy)
                self._proxies = {"http": proxy.url, "https": proxy.url}
            except ProxyStringError as e:
                log.info(
                    "Failed to parse proxy for liveimg --proxy=\"%s\": %s",
                    self.data.method.proxy, e)

        error = None
        try:
            req = urllib.urlopen(self.data.method.url, proxies=self._proxies)

            # At this point we know we can get the image and what its size is
            # Make a guess as to minimum size needed:
            # Enough space for image and image * 3
            if req.info().get("content-length"):
                self._min_size = int(req.info().get("content-length")) * 4
        except IOError as e:
            log.error("Error opening liveimg: %s", e)
            error = e
        else:
            # If it is a http request we need to check the code
            method = self.data.method.url.split(":", 1)[0]
            if method.startswith("http") and req.getcode() != 200:
                error = "http request returned %s" % req.getcode()

        return error
示例#2
0
    def refresh(self):
        GUIObject.refresh(self)

        if not self.proxyUrl:
            self._proxyCheck.set_active(False)
            self.on_proxy_enable_toggled(self._proxyCheck)
            self._authCheck.set_active(False)
            self.on_proxy_auth_toggled(self._authCheck)
            return

        try:
            proxy = ProxyString(self.proxyUrl)
            if proxy.username:
                self._proxyUsernameEntry.set_text(proxy.username)
            if proxy.password:
                self._proxyPasswordEntry.set_text(proxy.password)
            self._proxyURLEntry.set_text(proxy.noauth_url)
        except ProxyStringError as e:
            log.error("Failed to parse proxy for ProxyDialog.refresh %s: %s",
                      self.proxyUrl, e)
            return

        self._proxyCheck.set_active(True)
        self._authCheck.set_active(bool(proxy.username or proxy.password))
        self.on_proxy_enable_toggled(self._proxyCheck)
        self.on_proxy_auth_toggled(self._authCheck)
示例#3
0
    def on_proxy_add_clicked(self, *args):
        # If the user unchecked the proxy entirely, that means they want it
        # disabled.
        if not self._proxyCheck.get_active():
            self.proxyUrl = ""
            self.window.destroy()
            return

        url = self._proxyURLEntry.get_text()
        if self._authCheck.get_active():
            username = self._proxyUsernameEntry.get_text()
            password = self._proxyPasswordEntry.get_text()
        else:
            username = None
            password = None

        try:
            proxy = ProxyString(url=url, username=username, password=password)
            self.proxyUrl = proxy.url
        except ProxyStringError as e:
            log.error(
                "Failed to parse proxy for ProxyDialog Add - %s:%s@%s: %s",
                username, password, url, e)
            # TODO - tell the user they entered an invalid proxy and let them retry
            self.proxyUrl = ""

        self.window.destroy()
示例#4
0
    def _setup_url_image(self):
        """ Check to make sure the url is available and estimate the space
            needed to download and install it.
        """
        self._proxies = {}
        if self.data.method.proxy:
            try:
                proxy = ProxyString(self.data.method.proxy)
                self._proxies = {"http": proxy.url, "https": proxy.url}
            except ProxyStringError as e:
                log.info(
                    "Failed to parse proxy for liveimg --proxy=\"%s\": %s",
                    self.data.method.proxy, e)

        error = None
        try:
            response = self._session.get(self.data.method.url,
                                         proxies=self._proxies,
                                         verify=True)

            # At this point we know we can get the image and what its size is
            # Make a guess as to minimum size needed:
            # Enough space for image and image * 3
            if response.headers.get('content-length'):
                self._min_size = int(
                    response.headers.get('content-length')) * 4
        except IOError as e:
            log.error("Error opening liveimg: %s", e)
            error = e
        else:
            if response.status_code != 200:
                error = "http request returned %s" % response.status_code

        return error
示例#5
0
    def _add_repo(self, ksrepo):
        """Add a repo to the dnf repo object

           :param ksrepo: Kickstart Repository to add
           :type ksrepo: Kickstart RepoData object.
           :returns: None
        """
        repo = dnf.repo.Repo(ksrepo.name, DNF_CACHE_DIR)
        url = self._replace_vars(ksrepo.baseurl)
        mirrorlist = self._replace_vars(ksrepo.mirrorlist)

        if url and url.startswith("nfs://"):
            (server, path) = url[6:].split(":", 1)
            mountpoint = "%s/%s.nfs" % (constants.MOUNT_DIR, repo.name)
            self._setupNFS(mountpoint, server, path, None)

            url = "file://" + mountpoint

        if url:
            repo.baseurl = [url]
        if mirrorlist:
            repo.mirrorlist = mirrorlist
        repo.sslverify = not (ksrepo.noverifyssl or flags.noverifyssl)
        if ksrepo.proxy:
            try:
                repo.proxy = ProxyString(ksrepo.proxy).url
            except ProxyStringError as e:
                log.error("Failed to parse proxy for _add_repo %s: %s",
                          ksrepo.proxy, e)

        # If this repo is already known, it's one of two things:
        # (1) The user is trying to do "repo --name=updates" in a kickstart file
        #     and we should just know to enable the already existing on-disk
        #     repo config.
        # (2) It's a duplicate, and we need to delete the existing definition
        #     and use this new one.  The highest profile user of this is livecd
        #     kickstarts.
        if repo.id in self._base.repos:
            if not url and not mirrorlist:
                self._base.repos[repo.id].enable()
            else:
                self._base.repos.pop(repo.id)
                self._base.repos.add(repo)
                repo.enable()
        # If the repo's not already known, we've got to add it.
        else:
            self._base.repos.add(repo)
            repo.enable()

        # Load the metadata to verify that the repo is valid
        try:
            self._base.repos[repo.id].load()
        except dnf.exceptions.RepoError as e:
            raise packaging.MetadataError(e)

        log.info("added repo: '%s' - %s", ksrepo.name, url or mirrorlist)
示例#6
0
    def _getTreeInfo(self, url, proxy_url, sslverify):
        """ Retrieve treeinfo and return the path to the local file.

            :param baseurl: url of the repo
            :type baseurl: string
            :param proxy_url: Optional full proxy URL of or ""
            :type proxy_url: string
            :param sslverify: True if SSL certificate should be verified
            :type sslverify: bool
            :returns: Path to retrieved .treeinfo file or None
            :rtype: string or None
        """
        if not url:
            return None

        log.debug("retrieving treeinfo from %s (proxy: %s ; sslverify: %s)",
                  url, proxy_url, sslverify)

        proxies = {}
        if proxy_url:
            try:
                proxy = ProxyString(proxy_url)
                proxies = {"http": proxy.url, "https": proxy.url}
            except ProxyStringError as e:
                log.info("Failed to parse proxy for _getTreeInfo %s: %s",
                         proxy_url, e)

        response = None
        headers = {"user-agent": USER_AGENT}
        try:
            response = self._session.get("%s/.treeinfo" % url,
                                         headers=headers,
                                         proxies=proxies,
                                         verify=sslverify)
        except requests.exceptions.RequestException as e:
            try:
                response = self._session.get("%s/treeinfo" % url,
                                             headers=headers,
                                             proxies=proxies,
                                             verify=sslverify)
            except requests.exceptions.RequestException as e:
                log.info("Error downloading treeinfo: %s", e)
                self.verbose_errors.append(str(e))
                response = None

        if response:
            # write the local treeinfo file
            with open("/tmp/.treeinfo", "w") as f:
                f.write(response.text)

            # and also return the treeinfo contents as a string
            return response.text
        else:
            return None
示例#7
0
    def _writeDNFRepo(self, repo, repo_path):
        """ Write a repo object to a DNF repo.conf file

            :param repo: DNF repository object
            :param string repo_path: Path to write the repo to
            :raises: PayloadSetupError if the repo doesn't have a url
        """
        with open(repo_path, "w") as f:
            f.write("[%s]\n" % repo.id)
            f.write("name=%s\n" % repo.id)
            if self.isRepoEnabled(repo.id):
                f.write("enabled=1\n")
            else:
                f.write("enabled=0\n")

            if repo.mirrorlist:
                f.write("mirrorlist=%s\n" % repo.mirrorlist)
            elif repo.metalink:
                f.write("metalink=%s\n" % repo.metalink)
            elif repo.baseurl:
                f.write("baseurl=%s\n" % repo.baseurl[0])
            else:
                f.close()
                os.unlink(repo_path)
                raise packaging.PayloadSetupError(
                    "repo %s has no baseurl, mirrorlist or metalink", repo.id)

            # kickstart repo modifiers
            ks_repo = self.getAddOnRepo(repo.id)
            if not ks_repo:
                return

            if ks_repo.noverifyssl:
                f.write("sslverify=0\n")

            if ks_repo.proxy:
                try:
                    proxy = ProxyString(ks_repo.proxy)
                    f.write("proxy=%s\n" % proxy.url)
                except ProxyStringError as e:
                    log.error(
                        "Failed to parse proxy for _writeInstallConfig %s: %s",
                        ks_repo.proxy, e)

            if ks_repo.cost:
                f.write("cost=%d\n" % ks_repo.cost)

            if ks_repo.includepkgs:
                f.write("include=%s\n" % ",".join(ks_repo.includepkgs))

            if ks_repo.excludepkgs:
                f.write("exclude=%s\n" % ",".join(ks_repo.excludepkgs))
示例#8
0
    def _update_repo_info(self, repo):
        """ Update the text boxes with data from repo

            :param repo: kickstart repository object
            :type repo: RepoData
        """
        self._repoNameEntry.set_text(repo.name)

        self._display_repo_name_message(repo, repo.name)

        self._repoMirrorlistCheckbox.handler_block_by_func(
            self.on_repoMirrorlistCheckbox_toggled)
        if repo.mirrorlist:
            url = repo.mirrorlist
            self._repoMirrorlistCheckbox.set_active(True)
        else:
            url = repo.baseurl
            self._repoMirrorlistCheckbox.set_active(False)
        self._repoMirrorlistCheckbox.handler_unblock_by_func(
            self.on_repoMirrorlistCheckbox_toggled)

        if url:
            for idx, proto in REPO_PROTO:
                if url.startswith(proto):
                    self._repoProtocolComboBox.set_active(idx)
                    self._repoUrlEntry.set_text(url[len(proto):])
                    break
            else:
                # Unknown protocol, just set the url then
                self._repoUrlEntry.set_text(url)
        else:
            self._repoUrlEntry.set_text("")

        if not repo.proxy:
            self._repoProxyUrlEntry.set_text("")
            self._repoProxyUsernameEntry.set_text("")
            self._repoProxyPasswordEntry.set_text("")
        else:
            try:
                proxy = ProxyString(repo.proxy)
                if proxy.username:
                    self._repoProxyUsernameEntry.set_text(proxy.username)
                if proxy.password:
                    self._repoProxyPasswordEntry.set_text(proxy.password)
                self._repoProxyUrlEntry.set_text(proxy.noauth_url)
            except ProxyStringError as e:
                log.error("Failed to parse proxy for repo %s: %s", repo.name,
                          e)
                return
示例#9
0
    def _getTreeInfo(self, url, proxy_url, sslverify):
        """ Retrieve treeinfo and return the path to the local file.

            :param baseurl: url of the repo
            :type baseurl: string
            :param proxy_url: Optional full proxy URL of or ""
            :type proxy_url: string
            :param sslverify: True if SSL certificate should be varified
            :type sslverify: bool
            :returns: Path to retrieved .treeinfo file or None
            :rtype: string or None
        """
        if not url:
            return None

        log.debug("retrieving treeinfo from %s (proxy: %s ; sslverify: %s)",
                  url, proxy_url, sslverify)

        ugopts = {"ssl_verify_peer": sslverify, "ssl_verify_host": sslverify}

        proxies = {}
        if proxy_url:
            try:
                proxy = ProxyString(proxy_url)
                proxies = {"http": proxy.url, "https": proxy.url}
            except ProxyStringError as e:
                log.info("Failed to parse proxy for _getTreeInfo %s: %s",
                         proxy_url, e)

        ug = URLGrabber()
        try:
            treeinfo = ug.urlgrab("%s/.treeinfo" % url,
                                  "/tmp/.treeinfo",
                                  copy_local=True,
                                  proxies=proxies,
                                  **ugopts)
        except URLGrabError as e:
            try:
                treeinfo = ug.urlgrab("%s/treeinfo" % url,
                                      "/tmp/.treeinfo",
                                      copy_local=True,
                                      proxies=proxies,
                                      **ugopts)
            except URLGrabError as e:
                log.info("Error downloading treeinfo: %s", e)
                treeinfo = None

        return treeinfo
示例#10
0
    def _configure(self):
        self._base = dnf.Base()
        conf = self._base.conf
        conf.cachedir = DNF_CACHE_DIR
        conf.pluginconfpath = DNF_PLUGINCONF_DIR
        conf.logdir = '/tmp/'
        # disable console output completely:
        conf.debuglevel = 0
        conf.errorlevel = 0
        self._base.logging.setup_from_dnf_conf(conf)

        conf.releasever = self._getReleaseVersion(None)
        conf.installroot = pyanaconda.iutil.getSysroot()
        conf.prepend_installroot('persistdir')

        # NSS won't survive the forking we do to shield out chroot during
        # transaction, disable it in RPM:
        conf.tsflags.append('nocrypto')

        if self.data.packages.multiLib:
            conf.multilib_policy = "all"

        if hasattr(self.data.method, "proxy") and self.data.method.proxy:
            try:
                proxy = ProxyString(self.data.method.proxy)
                conf.proxy = proxy.noauth_url
                if proxy.username:
                    conf.proxy_username = proxy.username
                if proxy.password:
                    conf.proxy_password = proxy.password
                log.info("Using %s as proxy", self.data.method.proxy)
            except ProxyStringError as e:
                log.error("Failed to parse proxy for dnf configure %s: %s",
                          self.data.method.proxy, e)

        # Start with an empty comps so we can go ahead and use the environment
        # and group properties. Unset reposdir to ensure dnf has nothing it can
        # check automatically
        conf.reposdir = []
        self._base.read_comps()

        conf.reposdir = REPO_DIRS

        # Two reasons to turn this off:
        # 1. Minimal installs don't want all the extras this brings in.
        # 2. Installs aren't reproducible due to weak deps. failing silently.
        if self.data.packages.excludeWeakdeps:
            conf.install_weak_deps = False
示例#11
0
    def on_repoProxy_changed(self, *args):
        """ Update the selected repo's proxy settings
        """
        itr = self._repoSelection.get_selected()[1]
        if not itr:
            return
        repo = self._repoStore[itr][REPO_OBJ]

        url = self._repoProxyUrlEntry.get_text().strip()
        username = self._repoProxyUsernameEntry.get_text().strip() or None
        password = self._repoProxyPasswordEntry.get_text().strip() or None

        try:
            proxy = ProxyString(url=url, username=username, password=password)
            repo.proxy = proxy.url
        except ProxyStringError as e:
            log.error("Failed to parse proxy - %s:%s@%s: %s", username,
                      password, url, e)
示例#12
0
    def _configure_proxy(self):
        """ Configure the proxy on the dnf.Base object."""
        conf = self._base.conf

        if hasattr(self.data.method, "proxy") and self.data.method.proxy:
            try:
                proxy = ProxyString(self.data.method.proxy)
                conf.proxy = proxy.noauth_url
                if proxy.username:
                    conf.proxy_username = proxy.username
                if proxy.password:
                    conf.proxy_password = proxy.password
                log.info("Using %s as proxy", self.data.method.proxy)
            except ProxyStringError as e:
                log.error("Failed to parse proxy for dnf configure %s: %s",
                          self.data.method.proxy, e)
        else:
            # No proxy configured
            conf.proxy = None
            conf.proxy_username = None
            conf.proxy_password = None
示例#13
0
    def setup(self, storage, instClass):
        """ Check the availability and size of the image.
        """
        # This is on purpose, we don't want to call LiveImagePayload's setup method.
        ImagePayload.setup(self, storage, instClass)

        self._proxies = {}
        if self.data.method.proxy:
            try:
                proxy = ProxyString(self.data.method.proxy)
                self._proxies = {"http": proxy.url,
                                 "https": proxy.url}
            except ProxyStringError as e:
                log.info("Failed to parse proxy for liveimg --proxy=\"%s\": %s",
                         self.data.method.proxy, e)

        error = None
        try:
            req = urllib.urlopen(self.data.method.url, proxies=self._proxies)
        except IOError as e:
            log.error("Error opening liveimg: %s", e)
            error = e
        else:
            # If it is a http request we need to check the code
            method = self.data.method.url.split(":", 1)[0]
            if method.startswith("http") and req.getcode() != 200:
                error = "http request returned %s" % req.getcode()

        if error:
            exn = PayloadInstallError(str(error))
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # At this point we know we can get the image and what its size is
        # Make a guess as to minimum size needed:
        # Enough space for image and image * 3
        if req.info().get("content-length"):
            self._min_size = int(req.info().get("content-length")) * 4

        log.debug("liveimg size is %s", self._min_size)
示例#14
0
    def _download_repoMD(self, method):
        proxies = {}
        repomd = ""
        headers = {"user-agent": USER_AGENT}
        sslverify = not flags.noverifyssl

        if hasattr(method, "proxy"):
            proxy_url = method.proxy
            try:
                proxy = ProxyString(proxy_url)
                proxies = {"http": proxy.url, "https": proxy.url}
            except ProxyStringError as e:
                log.info(
                    "Failed to parse proxy for test if repo available %s: %s",
                    proxy_url, e)

        session = requests_session()

        # Test all urls for this repo. If any of these is working it is enough.
        for url in self._urls:
            try:
                result = session.get("%s/repodata/repomd.xml" % url,
                                     headers=headers,
                                     proxies=proxies,
                                     verify=sslverify)
                if result.ok:
                    repomd = result.text
                    break
                else:
                    log.debug(
                        "Server returned %i code when downloading repomd",
                        result.status_code)
                    continue
            except RequestException as e:
                log.debug(
                    "Can't download new repomd.xml from %s with proxy: %s. Error: %s",
                    url, proxies, e)

        return repomd
示例#15
0
    def _configureAddOnRepo(self, repo):
        """ Configure a single ksdata repo. """
        if repo.mirrorlist:
            log.info("mirrorlist %s" % repo.mirrorlist)
            self._smart.repo_manager.mirrors(repo.mirrorlist)
            return

        url = repo.baseurl
        if url and url.startswith("nfs://"):
            # Let the assignment throw ValueError for bad NFS urls from kickstart
            (server, path) = url[6:].split(":", 1)
            mountpoint = "%s/%s.nfs" % (os.path.dirname(MOUNT_DIR), repo.name)
            self._setupNFS(mountpoint, server, path, None)

            url = "file://" + mountpoint

        if self._repoNeedsNetwork(repo) and not nm_is_connected():
            raise NoNetworkError

        repoid = "Addon_%s" % repo.name
        repodata = SmartRepoData(repoid)
        if repo.proxy:
            proxy = ProxyString(repo.proxy)
            repodata.proxy = proxy.noauth_url
            repodata.proxy_username = proxy.username
            repodata.proxy_password = proxy.password
        else:
            proxy = None

        if repoid not in self._smart.repo_manager.repos():
            repodata.name = repo.name
            repodata.baseurl = [url]
            self._smart.repo_manager.add(repodata)
        else:
            self._smart.repo_manager.enable(repoid)

        self._smart.repo_manager.update()
示例#16
0
        else:
            # at least make sure we have all the values
            keyboard.populate_missing_items(ksdata.keyboard)

    # Some post-install parts of anaconda are implemented as kickstart
    # scripts.  Add those to the ksdata now.
    kickstart.appendPostScripts(ksdata)

    # cmdline flags override kickstart settings
    if anaconda.proxy:
        ksdata.method.proxy = anaconda.proxy

        # Setup proxy environmental variables so that pre/post scripts use it
        # as well as libreport
        try:
            proxy = ProxyString(anaconda.proxy)
        except ProxyStringError as e:
            log.info("Failed to parse proxy \"%s\": %s", anaconda.proxy, e)
        else:
            # Set environmental variables to be used by pre/post scripts
            iutil.setenv("PROXY", proxy.noauth_url)
            iutil.setenv("PROXY_USER", proxy.username or "")
            iutil.setenv("PROXY_PASSWORD", proxy.password or "")

            # Variables used by curl, libreport, etc.
            iutil.setenv("http_proxy", proxy.url)
            iutil.setenv("ftp_proxy", proxy.url)
            iutil.setenv("HTTPS_PROXY", proxy.url)

    if flags.noverifyssl:
        ksdata.method.noverifyssl = flags.noverifyssl
示例#17
0
    def updateBaseRepo(self, fallback=True, root=None, checkmount=True):
        log.info("%s %s" % (self.__class__.__name__, inspect.stack()[0][3]))
        """ Update the base repo based on self.data.method.

            - Tear down any previous base repo devices, symlinks, &c.
            - Reset the YumBase instance.
            - Try to convert the new method to a base repo.
            - If that fails, we'll use whatever repos smart finds in the config.
            - Set up addon repos.
            - Filter out repos that don't make sense to have around.
            - Get metadata for all enabled repos, disabling those for which the
              retrieval fails.
        """
        log.info("configuring base repo")

        try:
            log.debug("method %s" % self.data.method.method)
            url, mirrorlist, sslverify = self._setupInstallDevice(
                self.storage, checkmount)
            log.debug("method %s, url %s, mirrorlist %s, sslverify %s" %
                      (self.data.method.method, url, mirrorlist, sslverify))
        except PayloadSetupError:
            self.data.method.method = None
            log.debug("PayloadSetupError")

        releasever = None
        method = self.data.method
        if method.method:
            try:
                releasever = self._getReleaseVersion(url)
                log.debug("releasever from %s is %s", url, releasever)
            except ConfigParser.MissingSectionHeaderError as e:
                log.error("couldn't set releasever from base repo (%s): %s",
                          method.method, e)

        # Create default repository
        if method.method == "cdrom" and url.startswith("file://"):
            self._smart.createDefaultRepo(url)
        elif method.method == "url" and (url.startswith("http://")
                                         or url.startswith("https://")
                                         or url.startswith("ftp://")):
            if method.proxy:
                proxy = ProxyString(method.proxy)
            else:
                proxy = None
            self._smart.createDefaultRepo(url, proxy)
        elif method.method == "nfs" and url.startswith("file://"):
            self._smart.createDefaultRepo(url)

        # set up addon repos
        for repo in self.data.repo.dataList():
            log.info("repo %s" % repo)
            if not repo.enabled:
                continue
            try:
                self._configureAddOnRepo(repo)
                log.info("enable repo %s" % repo)
            except NoNetworkError as e:
                log.error("repo %s needs an active network connection",
                          repo.name)
                self.disableRepo(repo.name)
            except PayloadError as e:
                log.error("repo %s setup failed: %s", repo.name, e)
                self.disableRepo(repo.name)

        # TODO
        return