コード例 #1
0
    def recreateInitrds(self):
        """ Recreate the initrds by calling new-kernel-pkg

            This needs to be done after all configuration files have been
            written, since dracut depends on some of them.

            :returns: None
        """
        if not os.path.exists(iutil.getSysroot() + "/usr/sbin/new-kernel-pkg"):
            log.error(
                "new-kernel-pkg does not exist - grubby wasn't installed?  skipping"
            )
            return

        for kernel in self.kernelVersionList:
            log.info("recreating initrd for %s", kernel)
            if not flags.imageInstall:
                iutil.execInSysroot(
                    "new-kernel-pkg",
                    ["--mkinitrd", "--dracut", "--depmod", "--update", kernel])
            else:
                # hostonly is not sensible for disk image installations
                # using /dev/disk/by-uuid/ is necessary due to disk image naming
                iutil.execInSysroot("dracut", [
                    "-N", "--persistent-policy", "by-uuid", "-f",
                    "/boot/initramfs-%s.img" % kernel, kernel
                ])
コード例 #2
0
ファイル: __init__.py プロジェクト: NealSCarffery/anaconda
    def recreateInitrds(self):
        """ Recreate the initrds by calling new-kernel-pkg

            This needs to be done after all configuration files have been
            written, since dracut depends on some of them.

            :returns: None
        """
        if not os.path.exists(iutil.getSysroot() + "/usr/sbin/new-kernel-pkg"):
            log.error("new-kernel-pkg does not exist - grubby wasn't installed?  skipping")
            return

        for kernel in self.kernelVersionList:
            log.info("recreating initrd for %s", kernel)
            if not flags.imageInstall:
                iutil.execInSysroot("new-kernel-pkg",
                                    ["--mkinitrd", "--dracut",
                                    "--depmod", "--update", kernel])
            else:
                # hostonly is not sensible for disk image installations
                # using /dev/disk/by-uuid/ is necessary due to disk image naming
                iutil.execInSysroot("dracut",
                                    ["-N",
                                     "--persistent-policy", "by-uuid",
                                     "-f", "/boot/initramfs-%s.img" % kernel,
                                    kernel])
コード例 #3
0
ファイル: livepayload.py プロジェクト: evildesign/anaconda
    def postInstall(self):
        """ Perform post-installation tasks. """
        progressQ.send_message(_("Performing post-installation setup tasks"))
        blivet.util.umount(INSTALL_TREE)

        super(LiveImagePayload, self).postInstall()

        # Make sure the new system has a machine-id, it won't boot without it
        if not os.path.exists(iutil.getSysroot() + "/etc/machine-id"):
            iutil.execInSysroot("systemd-machine-id-setup", [])
コード例 #4
0
    def postInstall(self):
        """ Perform post-installation tasks. """
        progressQ.send_message(_("Performing post-installation setup tasks"))
        blivet.util.umount(INSTALL_TREE)

        super(LiveImagePayload, self).postInstall()

        # Make sure the new system has a machine-id, it won't boot without it
        if not os.path.exists(iutil.getSysroot()+"/etc/machine-id"):
            iutil.execInSysroot("systemd-machine-id-setup", [])
コード例 #5
0
ファイル: livepayload.py プロジェクト: evildesign/anaconda
    def install(self):
        """ Install the payload. """

        if self.source_size <= 0:
            raise PayloadInstallError("Nothing to install")

        self.pct_lock = Lock()
        self.pct = 0
        threadMgr.add(
            AnacondaThread(name=THREAD_LIVE_PROGRESS, target=self.progress))

        cmd = "rsync"
        # preserve: permissions, owners, groups, ACL's, xattrs, times,
        #           symlinks, hardlinks
        # go recursively, include devices and special files, don't cross
        # file system boundaries
        args = [
            "-pogAXtlHrDx", "--exclude", "/dev/", "--exclude", "/proc/",
            "--exclude", "/sys/", "--exclude", "/run/", "--exclude",
            "/boot/*rescue*", "--exclude", "/etc/machine-id",
            INSTALL_TREE + "/",
            iutil.getSysroot()
        ]
        try:
            rc = iutil.execWithRedirect(cmd, args)
        except (OSError, RuntimeError) as e:
            msg = None
            err = str(e)
            log.error(err)
        else:
            err = None
            msg = "%s exited with code %d" % (cmd, rc)
            log.info(msg)

        if err or rc == 12:
            exn = PayloadInstallError(err or msg)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Wait for progress thread to finish
        with self.pct_lock:
            self.pct = 100
        threadMgr.wait(THREAD_LIVE_PROGRESS)

        # Live needs to create the rescue image before bootloader is written
        if not os.path.exists(iutil.getSysroot() + "/usr/sbin/new-kernel-pkg"):
            log.error(
                "new-kernel-pkg does not exist - grubby wasn't installed?  skipping"
            )
            return

        for kernel in self.kernelVersionList:
            log.info("Generating rescue image for %s", kernel)
            iutil.execInSysroot("new-kernel-pkg", ["--rpmposttrans", kernel])
コード例 #6
0
ファイル: livepayload.py プロジェクト: evildesign/anaconda
    def install(self):
        """ Install the payload if it is a tar.
            Otherwise fall back to rsync of INSTALL_TREE
        """
        # If it doesn't look like a tarfile use the super's install()
        if not self.is_tarfile:
            super(LiveImageKSPayload, self).install()
            return

        # Use 2x the archive's size to estimate the size of the install
        # This is used to drive the progress display
        self.source_size = os.stat(self.image_path)[stat.ST_SIZE] * 2

        self.pct_lock = Lock()
        self.pct = 0
        threadMgr.add(
            AnacondaThread(name=THREAD_LIVE_PROGRESS, target=self.progress))

        cmd = "tar"
        # preserve: ACL's, xattrs, and SELinux context
        args = [
            "--selinux", "--acls", "--xattrs", "--xattrs-include", "*",
            "--exclude", "/dev/", "--exclude", "/proc/", "--exclude", "/sys/",
            "--exclude", "/run/", "--exclude", "/boot/*rescue*", "--exclude",
            "/etc/machine-id", "-xaf", self.image_path, "-C",
            iutil.getSysroot()
        ]
        try:
            rc = iutil.execWithRedirect(cmd, args)
        except (OSError, RuntimeError) as e:
            msg = None
            err = str(e)
            log.error(err)
        else:
            err = None
            msg = "%s exited with code %d" % (cmd, rc)
            log.info(msg)

        if err:
            exn = PayloadInstallError(err or msg)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Wait for progress thread to finish
        with self.pct_lock:
            self.pct = 100
        threadMgr.wait(THREAD_LIVE_PROGRESS)

        # Live needs to create the rescue image before bootloader is written
        for kernel in self.kernelVersionList:
            log.info("Generating rescue image for %s", kernel)
            iutil.execInSysroot("new-kernel-pkg", ["--rpmposttrans", kernel])
コード例 #7
0
    def install(self):
        """ Install the payload if it is a tar.
            Otherwise fall back to rsync of INSTALL_TREE
        """
        # If it doesn't look like a tarfile use the super's install()
        if not self.is_tarfile:
            super(LiveImageKSPayload, self).install()
            return

        # Use 2x the archive's size to estimate the size of the install
        # This is used to drive the progress display
        self.source_size = os.stat(self.image_path)[stat.ST_SIZE] * 2

        self.pct_lock = Lock()
        self.pct = 0
        threadMgr.add(AnacondaThread(name=THREAD_LIVE_PROGRESS,
                                     target=self.progress))

        cmd = "tar"
        # preserve: ACL's, xattrs, and SELinux context
        args = ["--selinux", "--acls", "--xattrs", "--xattrs-include", "*",
                "--exclude", "/dev/", "--exclude", "/proc/",
                "--exclude", "/sys/", "--exclude", "/run/", "--exclude", "/boot/*rescue*",
                "--exclude", "/etc/machine-id", "-xaf", self.image_path, "-C", iutil.getSysroot()]
        try:
            rc = iutil.execWithRedirect(cmd, args)
        except (OSError, RuntimeError) as e:
            msg = None
            err = str(e)
            log.error(err)
        else:
            err = None
            msg = "%s exited with code %d" % (cmd, rc)
            log.info(msg)

        if err:
            exn = PayloadInstallError(err or msg)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Wait for progress thread to finish
        with self.pct_lock:
            self.pct = 100
        threadMgr.wait(THREAD_LIVE_PROGRESS)

        # Live needs to create the rescue image before bootloader is written
        for kernel in self.kernelVersionList:
            log.info("Generating rescue image for %s", kernel)
            iutil.execInSysroot("new-kernel-pkg",
                                ["--rpmposttrans", kernel])
コード例 #8
0
    def install(self):
        """ Install the payload. """

        if self.source_size <= 0:
            raise PayloadInstallError("Nothing to install")

        self.pct_lock = Lock()
        self.pct = 0
        threadMgr.add(AnacondaThread(name=THREAD_LIVE_PROGRESS,
                                     target=self.progress))

        cmd = "rsync"
        # preserve: permissions, owners, groups, ACL's, xattrs, times,
        #           symlinks, hardlinks
        # go recursively, include devices and special files, don't cross
        # file system boundaries
        args = ["-pogAXtlHrDx", "--exclude", "/dev/", "--exclude", "/proc/",
                "--exclude", "/sys/", "--exclude", "/run/", "--exclude", "/boot/*rescue*",
                "--exclude", "/etc/machine-id", INSTALL_TREE+"/", iutil.getSysroot()]
        try:
            rc = iutil.execWithRedirect(cmd, args)
        except (OSError, RuntimeError) as e:
            msg = None
            err = str(e)
            log.error(err)
        else:
            err = None
            msg = "%s exited with code %d" % (cmd, rc)
            log.info(msg)

        if err or rc == 12:
            exn = PayloadInstallError(err or msg)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Wait for progress thread to finish
        with self.pct_lock:
            self.pct = 100
        threadMgr.wait(THREAD_LIVE_PROGRESS)

        # Live needs to create the rescue image before bootloader is written
        if not os.path.exists(iutil.getSysroot() + "/usr/sbin/new-kernel-pkg"):
            log.error("new-kernel-pkg does not exist - grubby wasn't installed?  skipping")
            return

        for kernel in self.kernelVersionList:
            log.info("Generating rescue image for %s", kernel)
            iutil.execInSysroot("new-kernel-pkg",
                                ["--rpmposttrans", kernel])
コード例 #9
0
    def recreateInitrds(self):
        """ Recreate the initrds by calling kernel-install

            This needs to be done after all configuration files have been
            written, since dracut depends on some of them.

            :returns: None
        """
        for kernel in self.kernelVersionList:
            log.info("recreating initrd for %s", kernel)
            if not flags.imageInstall:
                iutil.execInSysroot("kernel-install",
                                    ["add", kernel, "/boot/vmlinuz-%s" % kernel])
            else:
                # hostonly is not sensible for disk image installations
                # using /dev/disk/by-uuid/ is necessary due to disk image naming
                iutil.execInSysroot("dracut",
                                    ["-N",
                                     "--persistent-policy", "by-uuid",
                                     "-f", "/boot/initramfs-%s.img" % kernel,
                                    kernel])
コード例 #10
0
    def recreateInitrds(self):
        """ Recreate the initrds by calling kernel-install

            This needs to be done after all configuration files have been
            written, since dracut depends on some of them.

            :returns: None
        """
        for kernel in self.kernelVersionList:
            log.info("recreating initrd for %s", kernel)
            if not flags.imageInstall:
                iutil.execInSysroot(
                    "kernel-install",
                    ["add", kernel, "/boot/vmlinuz-%s" % kernel])
            else:
                # hostonly is not sensible for disk image installations
                # using /dev/disk/by-uuid/ is necessary due to disk image naming
                iutil.execInSysroot("dracut", [
                    "-N", "--persistent-policy", "by-uuid", "-f",
                    "/boot/initramfs-%s.img" % kernel, kernel
                ])
コード例 #11
0
    def execute(self, storage, ksdata, instclass, users, payload):
        """
        The execute method that should make changes to the installed system. It
        is called only once in the post-install setup phase.

        :see: setup
        :param users: information about created users
        :type users: pyanaconda.users.Users instance

        """

        if self.dry_run or not self.profile_id:
            # nothing more to be done in the dry-run mode or if no profile is
            # selected
            return

        target_content_dir = utils.join_paths(getSysroot(),
                                              common.TARGET_CONTENT_DIR)
        utils.ensure_dir_exists(target_content_dir)

        if self.content_type == "datastream":
            shutil.copy2(self.preinst_content_path, target_content_dir)
        elif self.content_type == "rpm":
            # copy the RPM to the target system
            shutil.copy2(self.raw_preinst_content_path, target_content_dir)

            # and install it with yum
            ret = iutil.execInSysroot(
                "yum",
                ["-y", "--nogpg", "install", self.raw_postinst_content_path])
            if ret != 0:
                raise common.ExtractionError("Failed to install content "
                                             "RPM to the target system")
        elif self.content_type == "scap-security-guide":
            # nothing needed
            pass
        else:
            utils.universal_copy(
                utils.join_paths(common.INSTALLATION_CONTENT_DIR, "*"),
                target_content_dir)
        if os.path.exists(self.preinst_tailoring_path):
            shutil.copy2(self.preinst_tailoring_path, target_content_dir)

        common.run_oscap_remediate(self.profile_id,
                                   self.postinst_content_path,
                                   self.datastream_id,
                                   self.xccdf_id,
                                   self.postinst_tailoring_path,
                                   chroot=getSysroot())
コード例 #12
0
ファイル: oscap.py プロジェクト: M4rtinK/oscap-anaconda-addon
    def execute(self, storage, ksdata, instclass, users):
        """
        The execute method that should make changes to the installed system. It
        is called only once in the post-install setup phase.

        :see: setup
        :param users: information about created users
        :type users: pyanaconda.users.Users instance

        """

        if self.dry_run:
            # nothing to be done in the dry-run mode
            return

        target_content_dir = utils.join_paths(getSysroot(),
                                              common.TARGET_CONTENT_DIR)
        utils.ensure_dir_exists(target_content_dir)

        if self.content_type == "datastream":
            shutil.copy2(self.preinst_content_path, target_content_dir)
        elif self.content_type == "rpm":
            # copy the RPM to the target system
            shutil.copy2(self.raw_preinst_content_path, target_content_dir)

            # and install it with yum
            ret = iutil.execInSysroot("yum", ["-y", "install",
                                              self.raw_postinst_content_path])
            if ret != 0:
                raise common.ExtractionError("Failed to install content "
                                             "RPM to the target system")
        elif self.content_type == "scap-security-guide":
            # nothing needed
            pass
        else:
            utils.universal_copy(utils.join_paths(common.INSTALLATION_CONTENT_DIR,
                                              "*"),
                                 target_content_dir)

        common.run_oscap_remediate(self.profile_id, self.postinst_content_path,
                                   self.datastream_id, self.xccdf_id,
                                   self.postinst_tailoring_path, chroot=getSysroot())
コード例 #13
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
コード例 #14
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