コード例 #1
0
def find_and_mount_device(device_spec, mount_point):
    """Resolve what device to mount and do so, read-only.

    Assumes that the device is directly mountable without any preparations or dependencies.

    :param str device_spec: specification of the device
    :param str mount_point: where to mount the device

    :return: success or not
    :rtype: bool
    """
    matches = device_matches(device_spec)
    if not matches:
        log.error("Device spec %s does not resolve to anything", device_spec)
        return False

    device_path = "/dev/" + matches[0]

    try:
        # FIXME: Add back RO mounting. This was removed because we can't mount one source
        # RW and RO at the same time. This source is also mounted by IsoChooser dialog in the
        # SourceSpoke.
        mount(device_path, mount_point, "auto")
        return True
    except OSError as e:
        log.error("Mount of device failed: %s", e)
        return False
コード例 #2
0
def find_and_mount_device(device_spec, mount_point):
    """Resolve what device to mount and do so, read-only.

    Assumes that the device is directly mountable without any preparations or dependencies.

    :param str device_spec: specification of the device
    :param str mount_point: where to mount the device

    :return: success or not
    :rtype: bool
    """
    matches = device_matches(device_spec)
    if not matches:
        log.error("Device spec %s does not resolve to anything", device_spec)
        return False

    device_path = "/dev/" + matches[0]

    try:
        mount(device=device_path,
              mountpoint=mount_point,
              fstype="auto",
              options="defaults,ro")
        return True
    except OSError as e:
        log.error("Mount of device failed: %s", e)
        return False
コード例 #3
0
ファイル: root.py プロジェクト: VladimirSlavik/anaconda
def mount_existing_system(storage, root_device, read_only=None):
    """Mount filesystems specified in root_device's /etc/fstab file."""
    root_path = conf.target.physical_root
    read_only = "ro" if read_only else ""

    # Mount the root device.
    if root_device.protected and os.path.ismount("/mnt/install/isodir"):
        blivet_util.mount("/mnt/install/isodir",
                          root_path,
                          fstype=root_device.format.type,
                          options="bind")
    else:
        root_device.setup()
        root_device.format.mount(chroot=root_path,
                                 mountpoint="/",
                                 options="%s,%s" % (root_device.format.options, read_only))

    # Set up the sysroot.
    set_system_root(root_path)

    # Mount the filesystems.
    storage.fsset.parse_fstab(chroot=root_path)
    storage.fsset.mount_filesystems(root_path=root_path, read_only=read_only, skip_root=True)

    # Turn on swap.
    if not conf.target.is_image or not read_only:
        try:
            storage.fsset.turn_on_swap(root_path=root_path)
        except StorageError as e:
            log.error("Error enabling swap: %s", str(e))

    # Generate mtab.
    if not read_only:
        storage.make_mtab(chroot=root_path)
コード例 #4
0
def mount_iso_image(image_path, mount_point):
    """Mount ISO image.

    :param str image_path: where the image ISO file is
    :param str mount_point: where to mount the image

    :return: success or not
    :rtype: bool
    """
    try:
        mount(image_path, mount_point, fstype='iso9660', options="ro")
        return True
    except OSError as e:
        log.error("Mount of ISO file failed: %s", e)
        return False
コード例 #5
0
ファイル: root.py プロジェクト: rvykydal/anaconda
def mount_existing_system(fsset, root_device, read_only=None):
    """Mount filesystems specified in root_device's /etc/fstab file."""
    root_path = util.getSysroot()
    read_only = "ro" if read_only else ""

    if root_device.protected and os.path.ismount("/mnt/install/isodir"):
        blivet_util.mount("/mnt/install/isodir",
                          root_path,
                          fstype=root_device.format.type,
                          options="bind")
    else:
        root_device.setup()
        root_device.format.mount(chroot=root_path,
                                 mountpoint="/",
                                 options="%s,%s" % (root_device.format.options, read_only))

    fsset.parse_fstab()
    fsset.mount_filesystems(root_path=root_path, read_only=read_only, skip_root=True)
コード例 #6
0
ファイル: utils.py プロジェクト: yugart/anaconda
def find_and_mount_iso_image(image_location, mount_point):
    """Find a ISO image in a location and mount it.

    :param str image_location: where the image ISO file is
    :param str mount_point: where to mount the image

    :return: success or not
    :rtype: bool
    """
    image_filename = find_first_iso_image(image_location)
    if not image_filename:
        return False
    full_image_path = join_paths(image_location, image_filename)
    try:
        mount(full_image_path, mount_point, fstype='iso9660', options="ro")
        return True
    except OSError as e:
        log.error("Mount of ISO file failed: %s", e)
        return False
コード例 #7
0
def mount_existing_system(fsset, root_device, read_only=None):
    """Mount filesystems specified in root_device's /etc/fstab file."""
    root_path = util.getSysroot()
    read_only = "ro" if read_only else ""

    if root_device.protected and os.path.ismount("/mnt/install/isodir"):
        blivet_util.mount("/mnt/install/isodir",
                          root_path,
                          fstype=root_device.format.type,
                          options="bind")
    else:
        root_device.setup()
        root_device.format.mount(chroot=root_path,
                                 mountpoint="/",
                                 options="%s,%s" %
                                 (root_device.format.options, read_only))

    fsset.parse_fstab()
    fsset.mount_filesystems(root_path=root_path,
                            read_only=read_only,
                            skip_root=True)
コード例 #8
0
    def execute(self, storage, ksdata, instclass, users):
        """
        Post install activities, first copy the answer file
        from location given in kickstart. Second copy cirrios
        image and rabbitmq public key (both needed for offline packstack run)
        """
        # Create Answers file from given URL TODO:Copy the answer file to host
        if self.state == "True" and self.env == "anaconda":
            os.mkdir(ROOT_PATH + ADDON_DIRECTORY)
            # if (self.lines is not None) and not (self.lines == "") :
            #     answer_file = os.path.normpath(ROOT_PATH + ADDON_DIRECTORY + "answer-file.txt")
            #     with open(answer_file, "w") as fobj:
            #         fobj.write("%s\n" % self.lines)

            # Copying repodata, cirrios image & rabbitmq public key to Host system from media
            tmpdirectory = tempfile.mkdtemp()
            util.mount(device="/dev/disk/by-label/CentOS\\x207\\x20x86_64", mountpoint=tmpdirectory, fstype="auto")
            copy_tree(tmpdirectory + "/Packages/RDO", os.path.normcase(ROOT_PATH + ADDON_DIRECTORY))
            util.umount(tmpdirectory)
            shutil.rmtree(tmpdirectory)
            with open(ROOT_PATH + '/etc/hosts', 'a') as file:
                file.write('127.0.0.1 www.rabbitmq.com\n')
            file.close()
            # Copy Addon itself to /usr/share/anaconda/addons
            #TODO: Once Packaged remove this step
            if os.path.exists(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"):
                os.mkdir(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud")
            shutil.copytree("/usr/share/anaconda/addons/org_centos_cloud",
                            os.path.normcase(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"))

            # Enabling initial-setup-text service,
            # TODO: Check if Graphical OR Text Service to Enable
            #initial-setup-text.service: Adding $HOME=/root ENV Variable & Enabling
            for line in fileinput.input(ROOT_PATH + '/usr/lib/systemd/system/initial-setup-text.service', inplace=1):
                if line.startswith('Type'):
                    print 'Environment=HOME=/root'
                print line,
            rc = iutil.execInSysroot("ln", ["-s", "usr/lib/systemd/system/initial-setup-text.service",
                                            "etc/systemd/system/multi-user.target.wants/initial-setup-text.service"])
            if rc:
                msg = "Initializing initial-setup-text service failed"
                raise KickstartValueError(msg)
            # NetworkManager: Disable
            rc = iutil.execInSysroot("rm", ["-rf", "etc/systemd/system/multi-user.target.wants/NetworkManager.service",
                                            "etc/systemd/system/dbus-org.freedesktop.NetworkManager.service",
                                            "etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service"])
            if rc:
                msg = "Disabling Network Failed"
                raise KickstartValueError(msg)

        elif (self.env == "firstboot") and (self.state == "True"):

            rc = iutil._run_systemctl("enable", "network")
            if rc:
                print ("Network start failed")
            ret = self.run_packstack()
            if ret:
                if (self.cleanup()):
                    raw_input("OpenStack Successfully Setup! Press Any Key To Continue...")
                else:
                    raw_input(
                        "Warning! OpenStack Successfully Setup But System Cleanup failed. Press Any Key To Continue...")
        else:
            pass
コード例 #9
0
    def execute(self, storage, ksdata, instclass, users):
        """
        Post install activities, first copy the answer file
        from location given in kickstart. Second copy cirrios
        image and rabbitmq public key (both needed for offline packstack run)
        """
        # Create Answers file from given URL TODO:Copy the answer file to host
        if self.state == "True" and self.env == "anaconda":
            os.mkdir(ROOT_PATH + ADDON_DIRECTORY)
            # if (self.lines is not None) and not (self.lines == "") :
            #     answer_file = os.path.normpath(ROOT_PATH + ADDON_DIRECTORY + "answer-file.txt")
            #     with open(answer_file, "w") as fobj:
            #         fobj.write("%s\n" % self.lines)

            # Copying repodata, cirrios image & rabbitmq public key to Host system from media
            tmpdirectory = tempfile.mkdtemp()
            util.mount(device="/dev/disk/by-label/CentOS\\x207\\x20x86_64",
                       mountpoint=tmpdirectory,
                       fstype="auto")
            copy_tree(tmpdirectory + "/Packages/RDO",
                      os.path.normcase(ROOT_PATH + ADDON_DIRECTORY))
            util.umount(tmpdirectory)
            shutil.rmtree(tmpdirectory)
            with open(ROOT_PATH + '/etc/hosts', 'a') as file:
                file.write('127.0.0.1 www.rabbitmq.com\n')
            file.close()
            # Copy Addon itself to /usr/share/anaconda/addons
            #TODO: Once Packaged remove this step
            if os.path.exists(ROOT_PATH +
                              "/usr/share/anaconda/addons/org_centos_cloud"):
                os.mkdir(ROOT_PATH +
                         "/usr/share/anaconda/addons/org_centos_cloud")
            shutil.copytree(
                "/usr/share/anaconda/addons/org_centos_cloud",
                os.path.normcase(
                    ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"))

            # Enabling initial-setup-text service,
            # TODO: Check if Graphical OR Text Service to Enable
            #initial-setup-text.service: Adding $HOME=/root ENV Variable & Enabling
            for line in fileinput.input(
                    ROOT_PATH +
                    '/usr/lib/systemd/system/initial-setup-text.service',
                    inplace=1):
                if line.startswith('Type'):
                    print 'Environment=HOME=/root'
                print line,
            rc = iutil.execInSysroot("ln", [
                "-s", "usr/lib/systemd/system/initial-setup-text.service",
                "etc/systemd/system/multi-user.target.wants/initial-setup-text.service"
            ])
            if rc:
                msg = "Initializing initial-setup-text service failed"
                raise KickstartValueError(msg)
            # NetworkManager: Disable
            rc = iutil.execInSysroot("rm", [
                "-rf",
                "etc/systemd/system/multi-user.target.wants/NetworkManager.service",
                "etc/systemd/system/dbus-org.freedesktop.NetworkManager.service",
                "etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service"
            ])
            if rc:
                msg = "Disabling Network Failed"
                raise KickstartValueError(msg)

        elif (self.env == "firstboot") and (self.state == "True"):

            rc = iutil._run_systemctl("enable", "network")
            if rc:
                print("Network start failed")
            ret = self.run_packstack()
            if ret:
                if (self.cleanup()):
                    raw_input(
                        "OpenStack Successfully Setup! Press Any Key To Continue..."
                    )
                else:
                    raw_input(
                        "Warning! OpenStack Successfully Setup But System Cleanup failed. Press Any Key To Continue..."
                    )
        else:
            pass