def createDialog(self):

        if self.repo:
            self.nameEntry.set_text(self.repo.name)
            if self.repo.anacondaBaseURLs:
                url = self.repo.anacondaBaseURLs[0]
            else:
                url = ''
            self.typeComboBox.set_active(self._methodToIndex(url))

            if not url or url.startswith("http") or url.startswith("ftp"):
                if self.repo.mirrorlist:
                    self.baseurlEntry.set_text(self.repo.mirrorlist)
                    self.mirrorlistCheckbox.set_active(True)
                else:
                    self.baseurlEntry.set_text(url)

                    self.mirrorlistCheckbox.set_active(False)

                if self.repo.proxy:
                    self.proxyCheckbox.set_active(True)
                    self.proxyTable.set_sensitive(True)
                    self.proxyEntry.set_text(self.repo.proxy)
                    self.usernameEntry.set_text(self.repo.proxy_username or '')
                    self.passwordEntry.set_text(self.repo.proxy_password or '')
                else:
                    self.proxyCheckbox.set_active(False)
                    self.proxyTable.set_sensitive(False)
            elif url.startswith("nfs"):
                (opts, server, path) = iutil.parseNfsUrl(url)
                self.nfsServerEntry.set_text(server)
                self.nfsPathEntry.set_text(path)
                self.nfsOptionsEntry.set_text(opts)
            elif url.startswith("cdrom:"):
                pass
            elif url.startswith("hd:"):
                m = url[3:]
                if m.count(":") == 1:
                    (device, path) = m.split(":")
                    fstype = "auto"
                else:
                    (device, fstype, path) = m.split(":")

                # find device in self.partitionComboBox and select it
                self.directoryChooser.set_current_folder("%s%s" % (self.anaconda.backend.ayum.isodir, path))
            else:
                self.baseurlEntry.set_text(url)

        else:
            self.typeComboBox.set_active(0)
            self.proxyCheckbox.set_active(False)
            self.proxyTable.set_sensitive(False)

        gui.addFrame(self.dialog)

        lbl = self.dxml.get_widget("descLabel")
        txt = lbl.get_text()
        lbl.set_text(txt)

        self.dialog.show_all()
Example #2
0
def set_installation_method_from_anaconda_options(anaconda, ksdata):
    """Set the installation method from Anaconda options.

    This basically means to set the installation method from options provided
    to Anaconda via command line/boot options.

    :param anaconda: instance of the Anaconda class
    :param ksdata: data model corresponding to the installation kickstart
    """
    if anaconda.methodstr.startswith("cdrom"):
        ksdata.method.method = "cdrom"
    elif anaconda.methodstr.startswith("nfs"):
        ksdata.method.method = "nfs"
        nfs_options, server, path = iutil.parseNfsUrl(anaconda.methodstr)
        ksdata.method.server = server
        ksdata.method.dir = path
        ksdata.method.opts = nfs_options
    elif anaconda.methodstr.startswith("hd:"):
        ksdata.method.method = "harddrive"
        url = anaconda.methodstr.split(":", 1)[1]
        url_parts = url.split(":")
        device = url_parts[0]
        path = ""
        if len(url_parts) == 2:
            path = url_parts[1]
        elif len(url_parts) == 3:
            path = url_parts[2]

        ksdata.method.partition = device
        ksdata.method.dir = path
    elif anaconda.methodstr.startswith("http") or anaconda.methodstr.startswith("ftp") or anaconda.methodstr.startswith("file"):
        ksdata.method.method = "url"
        ksdata.method.url = anaconda.methodstr
        # installation source specified by bootoption
        # overrides source set from kickstart;
        # the kickstart might have specified a mirror list,
        # so we need to clear it here if plain url source is provided
        # by a bootoption, because having both url & mirror list
        # set at once is not supported and breaks dnf in
        # unpredictable ways
        # FIXME: Is this still needed for dnf?
        ksdata.method.mirrorlist = None
        ksdata.method.metalink = None
    elif anaconda.methodstr.startswith("livecd"):
        ksdata.method.method = "harddrive"
        device = anaconda.methodstr.split(":", 1)[1]
        ksdata.method.partition = os.path.normpath(device)
    elif anaconda.methodstr.startswith("hmc"):
        ksdata.method.method = "hmc"
    else:
        log.error("Unknown method: %s", anaconda.methodstr)
Example #3
0
def set_installation_method_from_anaconda_options(anaconda, ksdata):
    """Set the installation method from Anaconda options.

    This basically means to set the installation method from options provided
    to Anaconda via command line/boot options.

    :param anaconda: instance of the Anaconda class
    :param ksdata: data model corresponding to the installation kickstart
    """
    if anaconda.methodstr.startswith("cdrom"):
        ksdata.method.method = "cdrom"
    elif anaconda.methodstr.startswith("nfs"):
        ksdata.method.method = "nfs"
        nfs_options, server, path = iutil.parseNfsUrl(anaconda.methodstr)
        ksdata.method.server = server
        ksdata.method.dir = path
        ksdata.method.opts = nfs_options
    elif anaconda.methodstr.startswith("hd:"):
        ksdata.method.method = "harddrive"
        url = anaconda.methodstr.split(":", 1)[1]
        url_parts = url.split(":")
        device = url_parts[0]
        path = ""
        if len(url_parts) == 2:
            path = url_parts[1]
        elif len(url_parts) == 3:
            path = url_parts[2]

        ksdata.method.partition = device
        ksdata.method.dir = path
    elif anaconda.methodstr.startswith("http") or anaconda.methodstr.startswith("ftp") or anaconda.methodstr.startswith("file"):
        ksdata.method.method = "url"
        ksdata.method.url = anaconda.methodstr
        # installation source specified by bootoption
        # overrides source set from kickstart;
        # the kickstart might have specified a mirror list,
        # so we need to clear it here if plain url source is provided
        # by a bootoption, because having both url & mirror list
        # set at once is not supported and breaks dnf in
        # unpredictable ways
        # FIXME: Is this still needed for dnf?
        ksdata.method.mirrorlist = None
        ksdata.method.metalink = None
    elif anaconda.methodstr.startswith("livecd"):
        ksdata.method.method = "harddrive"
        device = anaconda.methodstr.split(":", 1)[1]
        ksdata.method.partition = os.path.normpath(device)
    else:
        log.error("Unknown method: %s", anaconda.methodstr)
Example #4
0
    def _setupInstallDevice(self, storage, checkmount):
        # XXX FIXME: does this need to handle whatever was set up by dracut?
        method = self.data.method
        sslverify = True
        url = None
        mirrorlist = None

        # See if we already have stuff mounted due to dracut
        isodev = blivet.util.get_mount_device(DRACUT_ISODIR)
        device = blivet.util.get_mount_device(DRACUT_REPODIR)

        if method.method == "harddrive":
            if method.biospart:
                log.warning("biospart support is not implemented")
                devspec = method.biospart
            else:
                devspec = method.partition
                needmount = True
                # See if we used this method for stage2, thus dracut left it
                if isodev and method.partition and method.partition in isodev \
                and DRACUT_ISODIR in device:
                    # Everything should be setup
                    url = "file://" + DRACUT_REPODIR
                    needmount = False
                    # We don't setup an install_device here
                    # because we can't tear it down

            isodevice = storage.devicetree.resolveDevice(devspec)
            if needmount:
                if not isodevice:
                    raise PayloadSetupError(
                        "device for HDISO install %s does not exist" % devspec)

                self._setupMedia(isodevice)
                url = "file://" + INSTALL_TREE
                self.install_device = isodevice
        elif method.method == "nfs":
            # There are several possible scenarios here:
            # 1. dracut could have mounted both the nfs repo and an iso and used
            #    the stage2 from inside the iso to boot from.
            #    isodev and device will be set in this case.
            # 2. dracut could have mounted the nfs repo and used a stage2 from
            #    the NFS mount w/o mounting the iso.
            #    isodev will be None and device will be the nfs: path
            # 3. dracut did not mount the nfs (eg. stage2 came from elsewhere)
            #    isodev and device are both None
            # 4. The repo may not contain an iso, in that case use it as is
            if isodev:
                path = iutil.parseNfsUrl('nfs:%s' % isodev)[2]
                # See if the dir holding the iso is what we want
                # and also if we have an iso mounted to /run/install/repo
                if path and path in isodev and DRACUT_ISODIR in device:
                    # Everything should be setup
                    url = "file://" + DRACUT_REPODIR
            else:
                # see if the nfs dir is mounted
                needmount = True
                if device:
                    _options, host, path = iutil.parseNfsUrl('nfs:%s' % device)
                    if method.server and method.server == host and \
                       method.dir and method.dir == path:
                        needmount = False
                        path = DRACUT_REPODIR
                if needmount:
                    # Mount the NFS share on INSTALL_TREE. If it ends up
                    # being nfsiso we will move the mountpoint to ISO_DIR.
                    if method.dir.endswith(".iso"):
                        nfsdir = os.path.dirname(method.dir)
                    else:
                        nfsdir = method.dir
                    self._setupNFS(INSTALL_TREE, method.server, nfsdir,
                                   method.opts)
                    path = INSTALL_TREE

                # check for ISO images in the newly mounted dir
                if method.dir.endswith(".iso"):
                    # if the given URL includes a specific ISO image file, use it
                    image_file = os.path.basename(method.dir)
                    path = os.path.normpath("%s/%s" % (path, image_file))

                image = findFirstIsoImage(path)

                # An image was found, mount it on INSTALL_TREE
                if image:
                    if path.startswith(INSTALL_TREE):
                        # move the INSTALL_TREE mount to ISO_DIR so we can
                        # mount the contents of the iso there.
                        # work around inability to move shared filesystems
                        iutil.execWithRedirect("mount",
                                               ["--make-rprivate", "/"])
                        iutil.execWithRedirect(
                            "mount", ["--move", INSTALL_TREE, ISO_DIR])
                        # The iso is now under ISO_DIR
                        path = ISO_DIR
                    elif path.endswith(".iso"):
                        path = os.path.dirname(path)

                    # mount the ISO on a loop
                    image = os.path.normpath("%s/%s" % (path, image))
                    mountImage(image, INSTALL_TREE)

                    url = "file://" + INSTALL_TREE
                else:
                    # Fall back to the mount path instead of a mounted iso
                    url = "file://" + path
        elif method.method == "url":
            url = method.url
            mirrorlist = method.mirrorlist
            sslverify = not (method.noverifyssl or flags.noverifyssl)
        elif method.method == "cdrom" or (checkmount and not method.method):
            # Did dracut leave the DVD or NFS mounted for us?
            device = blivet.util.get_mount_device(DRACUT_REPODIR)

            # Check for valid optical media if we didn't boot from one
            if not verifyMedia(DRACUT_REPODIR):
                self.install_device = opticalInstallMedia(storage.devicetree)

            # Only look at the dracut mount if we don't already have a cdrom
            if device and not self.install_device:
                self.install_device = storage.devicetree.getDeviceByPath(
                    device)
                url = "file://" + DRACUT_REPODIR
                if not method.method:
                    # See if this is a nfs mount
                    if ':' in device:
                        # prepend nfs: to the url as that's what the parser
                        # wants.  Note we don't get options from this, but
                        # that's OK for the UI at least.
                        _options, host, path = iutil.parseNfsUrl("nfs:%s" %
                                                                 device)
                        method.method = "nfs"
                        method.server = host
                        method.dir = path
                    else:
                        method.method = "cdrom"
            else:
                if self.install_device:
                    if not method.method:
                        method.method = "cdrom"
                    self._setupMedia(self.install_device)
                    url = "file://" + INSTALL_TREE
                elif method.method == "cdrom":
                    raise PayloadSetupError("no usable optical media found")

        return url, mirrorlist, sslverify
Example #5
0
    def parse_nfs_url_test(self):
        """Test parseNfsUrl."""

        # empty NFS url should return 3 blanks
        self.assertEqual(iutil.parseNfsUrl(""), ("", "", ""))

        # the string is delimited by :, there is one prefix and 3 parts,
        # the prefix is discarded and all parts after the 3th part
        # are also discarded
        self.assertEqual(iutil.parseNfsUrl("discard:options:host:path"),
                         ("options", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl("discard:options:host:path:foo:bar"),
                         ("options", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":options:host:path::"),
                         ("options", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":::::"),
                         ("", "", ""))

        # if there is only prefix & 2 parts,
        # the two parts are host and path
        self.assertEqual(iutil.parseNfsUrl("prefix:host:path"),
                         ("", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":host:path"),
                         ("", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl("::"),
                         ("", "", ""))

        # if there is only a prefix and single part,
        # the part is the host

        self.assertEqual(iutil.parseNfsUrl("prefix:host"),
                         ("", "host", ""))
        self.assertEqual(iutil.parseNfsUrl(":host"),
                         ("", "host", ""))
        self.assertEqual(iutil.parseNfsUrl(":"),
                         ("", "", ""))
Example #6
0
    def parse_nfs_url_test(self):
        """Test parseNfsUrl."""

        # empty NFS url should return 3 blanks
        self.assertEqual(iutil.parseNfsUrl(""), ("", "", ""))

        # the string is delimited by :, there is one prefix and 3 parts,
        # the prefix is discarded and all parts after the 3th part
        # are also discarded
        self.assertEqual(iutil.parseNfsUrl("discard:options:host:path"),
                         ("options", "host", "path"))
        self.assertEqual(
            iutil.parseNfsUrl("discard:options:host:path:foo:bar"),
            ("options", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":options:host:path::"),
                         ("options", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":::::"), ("", "", ""))

        # if there is only prefix & 2 parts,
        # the two parts are host and path
        self.assertEqual(iutil.parseNfsUrl("prefix:host:path"),
                         ("", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl(":host:path"), ("", "host", "path"))
        self.assertEqual(iutil.parseNfsUrl("::"), ("", "", ""))

        # if there is only a prefix and single part,
        # the part is the host

        self.assertEqual(iutil.parseNfsUrl("prefix:host"), ("", "host", ""))
        self.assertEqual(iutil.parseNfsUrl(":host"), ("", "host", ""))
        self.assertEqual(iutil.parseNfsUrl(":"), ("", "", ""))
Example #7
0
            iutil.setenv("ftp_proxy", proxy.url)
            iutil.setenv("HTTPS_PROXY", proxy.url)

    if flags.noverifyssl:
        ksdata.method.noverifyssl = flags.noverifyssl
    if opts.multiLib:
        # sets dnf's multilib_policy to "all" (as opposed to "best")
        ksdata.packages.multiLib = opts.multiLib

    # set ksdata.method based on anaconda.method if it isn't already set
    if anaconda.methodstr and not ksdata.method.seen:
        if anaconda.methodstr.startswith("cdrom"):
            ksdata.method.method = "cdrom"
        elif anaconda.methodstr.startswith("nfs"):
            ksdata.method.method = "nfs"
            (nfsOptions, server, path) = iutil.parseNfsUrl(anaconda.methodstr)
            ksdata.method.server = server
            ksdata.method.dir = path
            ksdata.method.opts = nfsOptions
        elif anaconda.methodstr.startswith("hd:"):
            ksdata.method.method = "harddrive"
            url = anaconda.methodstr.split(":", 1)[1]
            url_parts = url.split(":")
            device = url_parts[0]
            path = ""
            if len(url_parts) == 2:
                path = url_parts[1]
            elif len(url_parts) == 3:
                fstype = url_parts[1]  # XXX not used
                path = url_parts[2]
Example #8
0
    def _setupInstallDevice(self, storage, checkmount):
        # XXX FIXME: does this need to handle whatever was set up by dracut?
        method = self.data.method
        sslverify = True
        url = None
        mirrorlist = None

        # See if we already have stuff mounted due to dracut
        isodev = blivet.util.get_mount_device(DRACUT_ISODIR)
        device = blivet.util.get_mount_device(DRACUT_REPODIR)

        if method.method == "harddrive":
            if method.biospart:
                log.warning("biospart support is not implemented")
                devspec = method.biospart
            else:
                devspec = method.partition
                needmount = True
                # See if we used this method for stage2, thus dracut left it
                if isodev and method.partition and method.partition in isodev \
                and DRACUT_ISODIR in device:
                    # Everything should be setup
                    url = "file://" + DRACUT_REPODIR
                    needmount = False
                    # We don't setup an install_device here
                    # because we can't tear it down

            isodevice = storage.devicetree.resolveDevice(devspec)
            if needmount:
                if not isodevice:
                    raise PayloadSetupError("device for HDISO install %s does not exist" % devspec)

                self._setupMedia(isodevice)
                url = "file://" + INSTALL_TREE
                self.install_device = isodevice
        elif method.method == "nfs":
            # There are several possible scenarios here:
            # 1. dracut could have mounted both the nfs repo and an iso and used
            #    the stage2 from inside the iso to boot from.
            #    isodev and device will be set in this case.
            # 2. dracut could have mounted the nfs repo and used a stage2 from
            #    the NFS mount w/o mounting the iso.
            #    isodev will be None and device will be the nfs: path
            # 3. dracut did not mount the nfs (eg. stage2 came from elsewhere)
            #    isodev and device are both None
            # 4. The repo may not contain an iso, in that case use it as is
            if isodev:
                path = iutil.parseNfsUrl('nfs:%s' % isodev)[2]
                # See if the dir holding the iso is what we want
                # and also if we have an iso mounted to /run/install/repo
                if path and path in isodev and DRACUT_ISODIR in device:
                    # Everything should be setup
                    url = "file://" + DRACUT_REPODIR
            else:
                # see if the nfs dir is mounted
                needmount = True
                if device:
                    _options, host, path = iutil.parseNfsUrl('nfs:%s' % device)
                    if method.server and method.server == host and \
                       method.dir and method.dir == path:
                        needmount = False
                        path = DRACUT_REPODIR
                if needmount:
                    # Mount the NFS share on INSTALL_TREE. If it ends up
                    # being nfsiso we will move the mountpoint to ISO_DIR.
                    if method.dir.endswith(".iso"):
                        nfsdir = os.path.dirname(method.dir)
                    else:
                        nfsdir = method.dir
                    self._setupNFS(INSTALL_TREE, method.server, nfsdir,
                                   method.opts)
                    path = INSTALL_TREE

                # check for ISO images in the newly mounted dir
                if method.dir.endswith(".iso"):
                    # if the given URL includes a specific ISO image file, use it
                    image_file = os.path.basename(method.dir)
                    path = os.path.normpath("%s/%s" % (path, image_file))

                image = findFirstIsoImage(path)

                # An image was found, mount it on INSTALL_TREE
                if image:
                    if path.startswith(INSTALL_TREE):
                        # move the INSTALL_TREE mount to ISO_DIR so we can
                        # mount the contents of the iso there.
                        # work around inability to move shared filesystems
                        iutil.execWithRedirect("mount",
                                               ["--make-rprivate", "/"])
                        iutil.execWithRedirect("mount",
                                               ["--move", INSTALL_TREE, ISO_DIR])
                        # The iso is now under ISO_DIR
                        path = ISO_DIR
                    elif path.endswith(".iso"):
                        path = os.path.dirname(path)

                    # mount the ISO on a loop
                    image = os.path.normpath("%s/%s" % (path, image))
                    mountImage(image, INSTALL_TREE)

                    url = "file://" + INSTALL_TREE
                else:
                    # Fall back to the mount path instead of a mounted iso
                    url = "file://" + path
        elif method.method == "url":
            url = method.url
            mirrorlist = method.mirrorlist
            sslverify = not (method.noverifyssl or flags.noverifyssl)
        elif method.method == "cdrom" or (checkmount and not method.method):
            # Did dracut leave the DVD or NFS mounted for us?
            device = blivet.util.get_mount_device(DRACUT_REPODIR)

            # Check for valid optical media if we didn't boot from one
            if not verifyMedia(DRACUT_REPODIR):
                self.install_device = opticalInstallMedia(storage.devicetree)

            # Only look at the dracut mount if we don't already have a cdrom
            if device and not self.install_device:
                self.install_device = storage.devicetree.getDeviceByPath(device)
                url = "file://" + DRACUT_REPODIR
                if not method.method:
                    # See if this is a nfs mount
                    if ':' in device:
                        # prepend nfs: to the url as that's what the parser
                        # wants.  Note we don't get options from this, but
                        # that's OK for the UI at least.
                        _options, host, path = iutil.parseNfsUrl("nfs:%s" % device)
                        method.method = "nfs"
                        method.server = host
                        method.dir = path
                    else:
                        method.method = "cdrom"
            else:
                if self.install_device:
                    if not method.method:
                        method.method = "cdrom"
                    self._setupMedia(self.install_device)
                    url = "file://" + INSTALL_TREE
                elif method.method == "cdrom":
                    raise PayloadSetupError("no usable optical media found")

        return url, mirrorlist, sslverify
Example #9
0
            iutil.setenv("ftp_proxy", proxy.url)
            iutil.setenv("HTTPS_PROXY", proxy.url)

    if flags.noverifyssl:
        ksdata.method.noverifyssl = flags.noverifyssl
    if opts.multiLib:
        # sets dnf's multilib_policy to "all" (as opposed to "best")
        ksdata.packages.multiLib = opts.multiLib

    # set ksdata.method based on anaconda.method if it isn't already set
    if anaconda.methodstr and not ksdata.method.seen:
        if anaconda.methodstr.startswith("cdrom"):
            ksdata.method.method = "cdrom"
        elif anaconda.methodstr.startswith("nfs"):
            ksdata.method.method = "nfs"
            (nfsOptions, server, path) = iutil.parseNfsUrl(anaconda.methodstr)
            ksdata.method.server = server
            ksdata.method.dir = path
            ksdata.method.opts = nfsOptions
        elif anaconda.methodstr.startswith("hd:"):
            ksdata.method.method = "harddrive"
            url = anaconda.methodstr.split(":", 1)[1]
            url_parts = url.split(":")
            device = url_parts[0]
            path = ""
            if len(url_parts) == 2:
                path = url_parts[1]
            elif len(url_parts) == 3:
                fstype = url_parts[1]   # XXX not used
                path = url_parts[2]