コード例 #1
0
ファイル: __init__.py プロジェクト: skycastlelily2/anaconda
    def _find_and_mount_iso(self, device, device_mount_dir, iso_path,
                            iso_mount_dir):
        """Find and mount installation source from ISO on device.

        Return changed path to the iso to save looking for iso in the future call.
        """
        self._setup_device(device, mountpoint=device_mount_dir)

        # check for ISO images in the newly mounted dir
        path = device_mount_dir
        if iso_path:
            path = os.path.normpath("%s/%s" % (path, iso_path))

        # XXX it would be nice to streamline this when we're just setting
        #     things back up after storage activation instead of having to
        #     pretend we don't already know which ISO image we're going to
        #     use
        image = findFirstIsoImage(path)
        if not image:
            payload_utils.teardown_device(device)
            raise PayloadSetupError("failed to find valid iso image")

        if path.endswith(".iso"):
            path = os.path.dirname(path)

        # this could already be set up the first time through
        if not os.path.ismount(iso_mount_dir):
            # mount the ISO on a loop
            image = os.path.normpath("%s/%s" % (path, image))
            mountImage(image, iso_mount_dir)

        if not iso_path.endswith(".iso"):
            result_path = os.path.normpath("%s/%s" %
                                           (iso_path, os.path.basename(image)))
            while result_path.startswith("/"):
                # ridiculous
                result_path = result_path[1:]

            return result_path

        return iso_path
コード例 #2
0
ファイル: __init__.py プロジェクト: skycastlelily2/anaconda
    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