def _setup_cdrom_device(self, method, iso_device_path, repo_device_path): url = None # FIXME: We really should not talk about NFS here - regression from re-factorization? # Check for valid optical media if we didn't boot from one if not verifyMedia(DRACUT_REPODIR): self.install_device = find_optical_install_media(self.storage) # Only look at the dracut mount if we don't already have a cdrom if repo_device_path and not self.install_device: self.install_device = payload_utils.resolve_device(self.storage, repo_device_path) url = "file://" + DRACUT_REPODIR if not method.method: # See if this is a nfs mount if ':' in repo_device_path: # 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 = util.parseNfsUrl("nfs:%s" % repo_device_path) 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._setup_media(self.install_device) url = "file://" + INSTALL_TREE elif method.method == "cdrom": raise PayloadSetupError("no usable optical media found") return url
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 = util.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)
def parse_repo_cmdline_string(cls, cmdline): """Parse cmdline string to source class.""" if cls.is_cdrom(cmdline): return CDRomSource() elif cls.is_nfs(cmdline): nfs_options, server, path = parseNfsUrl(cmdline) return NFSSource(server, path, nfs_options) elif cls.is_harddrive(cmdline): url = cmdline.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] return HDDSource(device, path) elif cls.is_http(cmdline): # 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 return HTTPSource(cmdline) elif cls.is_https(cmdline): return HTTPSSource(cmdline) elif cls.is_ftp(cmdline): return FTPSource(cmdline) elif cls.is_file(cmdline): return FileSource(cmdline) elif cls.is_livecd(cmdline): device = cmdline.split(":", 1)[1] return LiveSource(device) elif cls.is_hmc(cmdline): return HMCSource() else: raise PayloadSourceTypeUnrecognized("Can't find source type for {}".format(cmdline))
def _setup_cdrom_device(self, storage, method, isodev, device): url = None # FIXME: We really should not talk about NFS here - regression from re-factorization? # Did dracut leave the DVD or NFS mounted for us? device = payload_utils.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.get_device_by_path(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 = util.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._setup_media(self.install_device) url = "file://" + INSTALL_TREE elif method.method == "cdrom": raise PayloadSetupError("no usable optical media found") return url
def parse_nfs_url_test(self): """Test parseNfsUrl.""" # empty NFS url should return 3 blanks self.assertEqual(util.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(util.parseNfsUrl("discard:options:host:path"), ("options", "host", "path")) self.assertEqual(util.parseNfsUrl("discard:options:host:path:foo:bar"), ("options", "host", "path")) self.assertEqual(util.parseNfsUrl(":options:host:path::"), ("options", "host", "path")) self.assertEqual(util.parseNfsUrl(":::::"), ("", "", "")) # if there is only prefix & 2 parts, # the two parts are host and path self.assertEqual(util.parseNfsUrl("prefix:host:path"), ("", "host", "path")) self.assertEqual(util.parseNfsUrl(":host:path"), ("", "host", "path")) self.assertEqual(util.parseNfsUrl("::"), ("", "", "")) # if there is only a prefix and single part, # the part is the host self.assertEqual(util.parseNfsUrl("prefix:host"), ("", "host", "")) self.assertEqual(util.parseNfsUrl(":host"), ("", "host", "")) self.assertEqual(util.parseNfsUrl(":"), ("", "", ""))
def _setup_nfs_device(self, method, iso_device_path, repo_device_path): # 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. # iso_device_path and repo_device_path 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. # iso_device_path will be None and repo_device_path will be the nfs: path # 3. dracut did not mount the nfs (eg. stage2 came from elsewhere) # iso_device_path and/or repo_device_path are None # 4. The repo may not contain an iso, in that case use it as is url = None path = None if iso_device_path and repo_device_path: path = util.parseNfsUrl('nfs:%s' % iso_device_path)[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 iso_device_path and DRACUT_ISODIR in repo_device_path: # Everything should be setup url = "file://" + DRACUT_REPODIR else: # see if the nfs dir is mounted need_mount = True if repo_device_path: _options, host, path = util.parseNfsUrl('nfs:%s' % repo_device_path) if method.server and method.server == host and \ method.dir and method.dir == path: need_mount = False path = DRACUT_REPODIR elif iso_device_path: # iso_device_path with no repo_device_path can happen when options on an existing # nfs mount have changed. It is already mounted, but on INSTALL_TREE # which is the same as DRACUT_ISODIR, making it hard for _setup_NFS # to detect that it is already mounted. _options, host, path = util.parseNfsUrl('nfs:%s' % iso_device_path) if path and path in iso_device_path: need_mount = False path = DRACUT_ISODIR if need_mount: # 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"): nfs_dir = os.path.dirname(method.dir) else: nfs_dir = method.dir self._setup_NFS(INSTALL_TREE, method.server, nfs_dir, 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 util.execWithRedirect("mount", ["--make-rprivate", "/"]) util.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 elif os.path.isdir(path): # Fall back to the mount path instead of a mounted iso url = "file://" + path else: # Do not try to use iso as source if it is not valid source raise PayloadSetupError("Not a valid ISO image!") return url
def _setup_nfs_device(self, storage, method, isodev, device): # 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/or device are None # 4. The repo may not contain an iso, in that case use it as is url = None path = None if isodev and device: path = util.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 need_mount = True if device: _options, host, path = util.parseNfsUrl('nfs:%s' % device) if method.server and method.server == host and \ method.dir and method.dir == path: need_mount = False path = DRACUT_REPODIR elif isodev: # isodev with no device can happen when options on an existing # nfs mount have changed. It is already mounted, but on INSTALL_TREE # which is the same as DRACUT_ISODIR, making it hard for _setup_NFS # to detect that it is already mounted. _options, host, path = util.parseNfsUrl('nfs:%s' % isodev) if path and path in isodev: need_mount = False path = DRACUT_ISODIR if need_mount: # 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"): nfs_dir = os.path.dirname(method.dir) else: nfs_dir = method.dir self._setup_NFS(INSTALL_TREE, method.server, nfs_dir, 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 util.execWithRedirect("mount", ["--make-rprivate", "/"]) util.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 elif os.path.isdir(path): # Fall back to the mount path instead of a mounted iso url = "file://" + path else: # Do not try to use iso as source if it is not valid source raise PayloadSetupError("Not a valid ISO image!") return url