Exemplo n.º 1
0
 def __init__(self, *args):
     NormalSpoke.__init__(self, *args)
     GUISpokeInputCheckHandler.__init__(self)
     self._users_module = USERS.get_proxy()
     self._services_module = SERVICES.get_proxy()
     self._refresh_running = False
     self._manually_locked = False
Exemplo n.º 2
0
    def should_run(cls, environment, data):
        """This method is responsible for beginning Spoke initialization
           in the firstboot environment (even before __init__).

           It should return True if the spoke is to be shown
           and False if it should be skipped.

           It might be called multiple times, with or without (None)
           the data argument.
        """

        if environment == ANACONDA_ENVIRON:
            return True

        if environment == FIRSTBOOT_ENVIRON:
            # cannot decide, stay in the game and let another call with data
            # available (will come) decide
            if data is None:
                return True

            # generally run spokes in firstboot only if doing reconfig, spokes
            # that should run even if not doing reconfig should override this
            # method
            services_proxy = SERVICES.get_proxy()
            return services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG

        return False
Exemplo n.º 3
0
    def _set_default_boot_target(self):
        """Set the default systemd target for the system."""
        if not os.path.exists(util.getSysroot() + "/etc/systemd/system"):
            log.error("systemd is not installed -- can't set default target")
            return

        # If the target was already set, we don't have to continue.
        services_proxy = SERVICES.get_proxy()
        if services_proxy.DefaultTarget:
            log.debug("The default target is already set.")
            return

        try:
            import rpm
        except ImportError:
            log.info("failed to import rpm -- not adjusting default runlevel")
        else:
            ts = rpm.TransactionSet(util.getSysroot())

            # XXX one day this might need to account for anaconda's display mode
            if ts.dbMatch("provides", 'service(graphical-login)').count() and \
               not flags.usevnc:
                # We only manipulate the ksdata.  The symlink is made later
                # during the config write out.
                services_proxy.SetDefaultTarget(GRAPHICAL_TARGET)
            else:
                services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)
Exemplo n.º 4
0
    def setup(self, ksdata):
        timezone_proxy = TIMEZONE.get_proxy()
        services_proxy = SERVICES.get_proxy()

        enabled_services = services_proxy.EnabledServices
        disabled_services = services_proxy.DisabledServices

        # do not install and use NTP package
        if not timezone_proxy.NTPEnabled or NTP_PACKAGE in ksdata.packages.excludedList:
            if util.service_running(
                    NTP_SERVICE) and conf.system.can_set_time_synchronization:
                ret = util.stop_service(NTP_SERVICE)
                if ret != 0:
                    timezone_log.error("Failed to stop NTP service")

            if NTP_SERVICE not in disabled_services:
                disabled_services.append(NTP_SERVICE)
                services_proxy.SetDisabledServices(disabled_services)
        # install and use NTP package
        else:
            if not util.service_running(
                    NTP_SERVICE) and conf.system.can_set_time_synchronization:
                ret = util.start_service(NTP_SERVICE)
                if ret != 0:
                    timezone_log.error("Failed to start NTP service")

            self.packages.append(NTP_PACKAGE)

            if not NTP_SERVICE in enabled_services and \
                    not NTP_SERVICE in disabled_services:
                enabled_services.append(NTP_SERVICE)
                services_proxy.SetEnabledServices(enabled_services)
Exemplo n.º 5
0
    def should_run(cls, environment, data):
        """This method is responsible for beginning Spoke initialization
           in the firstboot environment (even before __init__).

           It should return True if the spoke is to be shown
           and False if it should be skipped.

           It might be called multiple times, with or without (None)
           the data argument.
        """

        if environment == ANACONDA_ENVIRON:
            return True

        if environment == FIRSTBOOT_ENVIRON:
            # cannot decide, stay in the game and let another call with data
            # available (will come) decide
            if data is None:
                return True

            # generally run spokes in firstboot only if doing reconfig, spokes
            # that should run even if not doing reconfig should override this
            # method
            services_proxy = SERVICES.get_proxy()
            return services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG

        return False
Exemplo n.º 6
0
    def execute(self):
        unit_name = "initial-setup.service"
        services_proxy = SERVICES.get_proxy()
        setup_on_boot = services_proxy.SetupOnBoot

        if setup_on_boot == SETUP_ON_BOOT_DISABLED:
            log.debug("The %s service will be disabled.", unit_name)
            util.disable_service(unit_name)
            # Also tell the screen access manager, so that the fact that post installation tools
            # should be disabled propagates to the user interaction config file.
            screen_access.sam.post_install_tools_disabled = True
            return

        if not os.path.exists(os.path.join(util.getSysroot(), "lib/systemd/system/", unit_name)):
            log.debug("The %s service will not be started on first boot, because "
                      "it's unit file is not installed.", unit_name)
            return

        if setup_on_boot == SETUP_ON_BOOT_RECONFIG:
            log.debug("The %s service will run in the reconfiguration mode.", unit_name)
            # write the reconfig trigger file
            f = open(os.path.join(util.getSysroot(), "etc/reconfigSys"), "w+")
            f.close()

        log.debug("The %s service will be enabled.", unit_name)
        util.enable_service(unit_name)
Exemplo n.º 7
0
    def execute(self):
        unit_name = "initial-setup.service"
        services_proxy = SERVICES.get_proxy()
        setup_on_boot = services_proxy.SetupOnBoot

        if setup_on_boot == SETUP_ON_BOOT_DISABLED:
            log.debug("The %s service will be disabled.", unit_name)
            util.disable_service(unit_name)
            # Also tell the screen access manager, so that the fact that post installation tools
            # should be disabled propagates to the user interaction config file.
            screen_access.sam.post_install_tools_disabled = True
            return

        if not os.path.exists(
                os.path.join(util.getSysroot(), "lib/systemd/system/",
                             unit_name)):
            log.debug(
                "The %s service will not be started on first boot, because "
                "it's unit file is not installed.", unit_name)
            return

        if setup_on_boot == SETUP_ON_BOOT_RECONFIG:
            log.debug("The %s service will run in the reconfiguration mode.",
                      unit_name)
            # write the reconfig trigger file
            f = open(os.path.join(util.getSysroot(), "etc/reconfigSys"), "w+")
            f.close()

        log.debug("The %s service will be enabled.", unit_name)
        util.enable_service(unit_name)
Exemplo n.º 8
0
    def _set_default_boot_target(self):
        """Set the default systemd target for the system."""
        if not os.path.exists(util.getSysroot() + "/etc/systemd/system"):
            log.error("systemd is not installed -- can't set default target")
            return

        # If the target was already set, we don't have to continue.
        services_proxy = SERVICES.get_proxy()
        if services_proxy.DefaultTarget:
            log.debug("The default target is already set.")
            return

        try:
            import rpm
        except ImportError:
            log.info("failed to import rpm -- not adjusting default runlevel")
        else:
            ts = rpm.TransactionSet(util.getSysroot())

            # XXX one day this might need to account for anaconda's display mode
            if ts.dbMatch("provides", 'service(graphical-login)').count() and \
               not flags.usevnc:
                # We only manipulate the ksdata.  The symlink is made later
                # during the config write out.
                services_proxy.SetDefaultTarget(GRAPHICAL_TARGET)
            else:
                services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)
Exemplo n.º 9
0
    def setup(self, ksdata):
        timezone_proxy = TIMEZONE.get_proxy()
        services_proxy = SERVICES.get_proxy()

        enabled_services = services_proxy.EnabledServices
        disabled_services = services_proxy.DisabledServices

        # do not install and use NTP package
        if not timezone_proxy.NTPEnabled or NTP_PACKAGE in ksdata.packages.excludedList:
            if util.service_running(NTP_SERVICE) and conf.system.can_set_time_synchronization:
                ret = util.stop_service(NTP_SERVICE)
                if ret != 0:
                    timezone_log.error("Failed to stop NTP service")

            if NTP_SERVICE not in disabled_services:
                disabled_services.append(NTP_SERVICE)
                services_proxy.SetDisabledServices(disabled_services)
        # install and use NTP package
        else:
            if not util.service_running(NTP_SERVICE) and conf.system.can_set_time_synchronization:
                ret = util.start_service(NTP_SERVICE)
                if ret != 0:
                    timezone_log.error("Failed to start NTP service")

            self.packages.append(NTP_PACKAGE)

            if not NTP_SERVICE in enabled_services and \
                    not NTP_SERVICE in disabled_services:
                enabled_services.append(NTP_SERVICE)
                services_proxy.SetEnabledServices(enabled_services)
Exemplo n.º 10
0
    def __init__(self, *args):
        NormalSpoke.__init__(self, *args)
        GUISpokeInputCheckHandler.__init__(self)

        self._users_module = USERS.get_observer()
        self._users_module.connect()

        self._services_module = SERVICES.get_observer()
        self._services_module.connect()
Exemplo n.º 11
0
    def __init__(self, *args):
        NormalSpoke.__init__(self, *args)
        GUISpokeInputCheckHandler.__init__(self)

        self._users_module = USERS.get_observer()
        self._users_module.connect()

        self._services_module = SERVICES.get_observer()
        self._services_module.connect()
Exemplo n.º 12
0
    def execute(self):
        services_proxy = SERVICES.get_proxy()

        for svc in services_proxy.DisabledServices:
            log.debug("Disabling the service %s.", svc)
            util.disable_service(svc)

        for svc in services_proxy.EnabledServices:
            log.debug("Enabling the service %s.", svc)
            util.enable_service(svc)
Exemplo n.º 13
0
    def execute(self):
        services_proxy = SERVICES.get_proxy()

        for svc in services_proxy.DisabledServices:
            log.debug("Disabling the service %s.", svc)
            util.disable_service(svc)

        for svc in services_proxy.EnabledServices:
            log.debug("Enabling the service %s.", svc)
            util.enable_service(svc)
Exemplo n.º 14
0
def is_reconfiguration_mode():
    """Check if we are running in Initial Setup reconfig mode.

    :return: True or False
    """
    if not is_module_available(SERVICES):
        return False

    services_module = SERVICES.get_proxy()
    return services_module.SetupOnBoot == SETUP_ON_BOOT_RECONFIG
Exemplo n.º 15
0
def initialize_first_boot_action():
    """Initialize the setup on boot action."""
    if not is_module_available(SERVICES):
        return

    services_proxy = SERVICES.get_proxy()

    if services_proxy.SetupOnBoot == SETUP_ON_BOOT_DEFAULT:
        if not flags.automatedInstall:
            # Enable by default for interactive installations.
            services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_ENABLED)
Exemplo n.º 16
0
    def update_config_file_state(self):
        """Synchornize user interaction config file state.

        At the moment this means simply checking if post installation setup tools should
        be enabled/disabled based on kickstart and state of the Services module.

        It is assumed this method will be called at an appropriate time before the config
        file is written out to the target system.
        """
        services_proxy = SERVICES.get_proxy()
        if services_proxy.SetupOnBoot == SETUP_ON_BOOT_DISABLED:
            self.post_install_tools_disabled = True
Exemplo n.º 17
0
    def run(self):
        services_proxy = SERVICES.get_proxy()
        enabled_services = services_proxy.EnabledServices
        disabled_services = services_proxy.DisabledServices

        if self._ntp_enabled and not self._ntp_excluded:
            if NTP_SERVICE not in enabled_services and NTP_SERVICE not in disabled_services:
                enabled_services.append(NTP_SERVICE)
                services_proxy.SetEnabledServices(enabled_services)
        else:
            if NTP_SERVICE not in disabled_services:
                disabled_services.append(NTP_SERVICE)
                services_proxy.SetDisabledServices(disabled_services)
Exemplo n.º 18
0
    def __init__(self, data, storage, payload):
        NormalTUISpoke.__init__(self, data, storage, payload)
        self.initialize_start()
        self.title = N_("Root password")
        self.input_required = False

        self._policy = self.data.anaconda.pwpolicy.get_policy("root", fallback_to_default=True)
        self._password = None

        self._users_module = USERS.get_proxy()
        self._services_module = SERVICES.get_proxy()

        self.initialize_done()
Exemplo n.º 19
0
    def _load_kickstart(self):
        """Load the kickstart"""
        from pyanaconda import kickstart

        # Construct a commandMap with only the supported Anaconda's commands
        commandMap = dict(
            (k, kickstart.commandMap[k]) for k in SUPPORTED_KICKSTART_COMMANDS)

        # Prepare new data object
        self.data = kickstart.AnacondaKSHandler(self._addon_module_paths["ks"],
                                                commandUpdates=commandMap)

        kickstart_path = INPUT_KICKSTART_PATH
        if os.path.exists(OUTPUT_KICKSTART_PATH):
            log.info("using kickstart from previous run for input")
            kickstart_path = OUTPUT_KICKSTART_PATH

        log.info("parsing input kickstart %s", kickstart_path)
        try:
            # Read the installed kickstart
            parser = kickstart.AnacondaKSParser(self.data)
            parser.readKickstart(kickstart_path)
            log.info("kickstart parsing done")
        except pykickstart.errors.KickstartError as kserr:
            log.critical("kickstart parsing failed: %s", kserr)
            log.critical(
                "Initial Setup startup failed due to invalid kickstart file")
            raise InitialSetupError

        # if we got this far the kickstart should be valid, so send it to Boss as well
        boss = BOSS.get_proxy()
        report = KickstartReport.from_structure(
            boss.ReadKickstartFile(kickstart_path))

        if not report.is_valid():
            message = "\n\n".join(map(str, report.error_messages))
            raise InitialSetupError(message)

        if self.external_reconfig:
            # set the reconfig flag in kickstart so that
            # relevant spokes show up
            services_proxy = SERVICES.get_proxy()
            services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_RECONFIG)

        # Record if groups, users or root password has been set before Initial Setup
        # has been started, so that we don't trample over existing configuration.
        users_proxy = USERS.get_proxy()
        self._groups_already_configured = bool(users_proxy.Groups)
        self._users_already_configured = bool(users_proxy.Users)
        self._root_password_already_configured = users_proxy.IsRootPasswordSet
Exemplo n.º 20
0
    def execute(self):
        desktop = Desktop()
        services_proxy = SERVICES.get_proxy()
        default_target = services_proxy.DefaultTarget
        default_desktop = services_proxy.DefaultDesktop

        if default_target:
            log.debug("Using the default target %s.", default_target)
            desktop.default_target = default_target

        if default_desktop:
            log.debug("Using the default desktop %s.", default_desktop)
            desktop.desktop = default_desktop

        desktop.write()
Exemplo n.º 21
0
    def execute(self):
        desktop = Desktop()
        services_proxy = SERVICES.get_proxy()
        default_target = services_proxy.DefaultTarget
        default_desktop = services_proxy.DefaultDesktop

        if default_target:
            log.debug("Using the default target %s.", default_target)
            desktop.default_target = default_target

        if default_desktop:
            log.debug("Using the default desktop %s.", default_desktop)
            desktop.desktop = default_desktop

        desktop.write()
Exemplo n.º 22
0
    def __init__(self, data, storage, payload):
        NormalTUISpoke.__init__(self, data, storage, payload)
        self.initialize_start()
        self.title = N_("Root password")
        self.input_required = False

        self._policy = self.data.anaconda.pwpolicy.get_policy("root", fallback_to_default=True)
        self._password = None

        self._users_module = USERS.get_observer()
        self._users_module.connect()

        self._services_module = SERVICES.get_observer()
        self._services_module.connect()

        self.initialize_done()
Exemplo n.º 23
0
    def _load_kickstart(self):
        """Load the kickstart"""
        from pyanaconda import kickstart

        # Construct a commandMap with only the supported Anaconda's commands
        commandMap = dict(
            (k, kickstart.commandMap[k]) for k in SUPPORTED_KICKSTART_COMMANDS)

        # Prepare new data object
        self.data = kickstart.AnacondaKSHandler(self._addon_module_paths["ks"],
                                                commandUpdates=commandMap)

        kickstart_path = INPUT_KICKSTART_PATH
        if os.path.exists(OUTPUT_KICKSTART_PATH):
            log.info("using kickstart from previous run for input")
            kickstart_path = OUTPUT_KICKSTART_PATH

        log.info("parsing input kickstart %s", kickstart_path)
        try:
            # Read the installed kickstart
            parser = kickstart.AnacondaKSParser(self.data)
            parser.readKickstart(kickstart_path)
            log.info("kickstart parsing done")
        except pykickstart.errors.KickstartError as kserr:
            log.critical("kickstart parsing failed: %s", kserr)
            log.critical(
                "Initial Setup startup failed due to invalid kickstart file")
            raise InitialSetupError

        # if we got this far the kickstart should be valid, so send it to Boss as well
        boss = BOSS.get_proxy()

        boss.SplitKickstart(kickstart_path)
        errors = boss.DistributeKickstart()

        if errors:
            message = "\n\n".join("{error_message}".format_map(e)
                                  for e in errors)
            raise InitialSetupError(message)

        if self.external_reconfig:
            # set the reconfig flag in kickstart so that
            # relevant spokes show up
            services_proxy = SERVICES.get_proxy()
            services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_RECONFIG)
Exemplo n.º 24
0
def initialize_default_systemd_target(text_mode):
    """Initialize the default systemd target.

    If we're in text mode, the resulting system should be too
    unless the kickstart specified otherwise.

    NOTE:

        Installation controlled via VNC is considered to be
        a text mode installation, as the installation run itself
        is effectively headless.

    :param text_mode: does the installer run in the text mode?
    """
    if not is_module_available(SERVICES):
        return

    services_proxy = SERVICES.get_proxy()

    if not services_proxy.DefaultTarget and (text_mode or flags.usevnc):
        log.debug("no default systemd target set & in text/vnc mode - setting multi-user.target.")
        services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)
Exemplo n.º 25
0
    # we now know in which mode we are going to run so store the information
    from pykickstart import constants as pykickstart_constants
    display_mode_coversion_table = {
        constants.DisplayModes.GUI:
        pykickstart_constants.DISPLAY_MODE_GRAPHICAL,
        constants.DisplayModes.TUI: pykickstart_constants.DISPLAY_MODE_TEXT
    }
    ksdata.displaymode.displayMode = display_mode_coversion_table[
        anaconda.display_mode]
    ksdata.displaymode.nonInteractive = not anaconda.interactive_mode

    # if we're in text mode, the resulting system should be too
    # ...unless the kickstart specified otherwise
    from pyanaconda.modules.common.constants.services import SERVICES
    from pyanaconda.core.constants import TEXT_ONLY_TARGET
    services_proxy = SERVICES.get_proxy()

    if not services_proxy.DefaultTarget and anaconda.tui_mode:
        services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)

    # Set flag to prompt for missing ks data
    if not anaconda.interactive_mode:
        flags.ksprompt = False

    # Set minimal ram size to the storage checker.
    if anaconda.display_mode == constants.DisplayModes.GUI:
        min_ram = isys.MIN_GUI_RAM
    else:
        min_ram = isys.MIN_RAM

    from pyanaconda.storage.checker import storage_checker
Exemplo n.º 26
0
def _prepare_configuration(payload, ksdata):
    """Configure the installed system."""

    configuration_queue = TaskQueue("Configuration queue")
    # connect progress reporting
    configuration_queue.queue_started.connect(
        lambda x: progress_message(x.status_message))
    configuration_queue.task_completed.connect(lambda x: progress_step(x.name))

    # schedule the execute methods of ksdata that require an installed system to be present
    os_config = TaskQueue("Installed system configuration",
                          N_("Configuring installed system"))

    # add installation tasks for the Security DBus module
    security_proxy = SECURITY.get_proxy()
    security_dbus_tasks = security_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(SECURITY, security_dbus_tasks)

    # add installation tasks for the Services DBus module
    services_proxy = SERVICES.get_proxy()
    services_dbus_tasks = services_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(SERVICES, services_dbus_tasks)

    # add installation tasks for the Timezone DBus module
    timezone_proxy = TIMEZONE.get_proxy()
    timezone_dbus_tasks = timezone_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(TIMEZONE, timezone_dbus_tasks)

    # add installation tasks for the Localization DBus module
    localization_proxy = LOCALIZATION.get_proxy()
    localization_dbus_tasks = localization_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(LOCALIZATION, localization_dbus_tasks)

    # add the Firewall configuration task
    firewall_proxy = NETWORK.get_proxy(FIREWALL)
    firewall_dbus_task = firewall_proxy.InstallWithTask()
    os_config.append_dbus_tasks(NETWORK, [firewall_dbus_task])

    configuration_queue.append(os_config)

    # schedule network configuration (if required)
    if conf.system.provides_network_config:
        overwrite = isinstance(payload, LiveImagePayload)
        network_config = TaskQueue("Network configuration",
                                   N_("Writing network configuration"))
        network_config.append(
            Task("Network configuration", network.write_configuration,
                 (overwrite, )))
        configuration_queue.append(network_config)

    # add installation tasks for the Users DBus module
    user_config = TaskQueue("User creation", N_("Creating users"))
    users_proxy = USERS.get_proxy()
    users_dbus_tasks = users_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(USERS, users_dbus_tasks)
    configuration_queue.append(user_config)

    # Anaconda addon configuration
    addon_config = TaskQueue("Anaconda addon configuration",
                             N_("Configuring addons"))

    # there is no longer a User class & addons should no longer need it
    # FIXME: drop user class parameter from the API & all known addons
    addon_config.append(
        Task("Configure Anaconda addons", ksdata.addons.execute,
             (None, ksdata, None, payload)))

    boss_proxy = BOSS.get_proxy()
    addon_config.append_dbus_tasks(BOSS, [boss_proxy.InstallSystemWithTask()])

    configuration_queue.append(addon_config)

    # Initramfs generation
    generate_initramfs = TaskQueue("Initramfs generation",
                                   N_("Generating initramfs"))
    generate_initramfs.append(
        Task("Generate initramfs", payload.recreate_initrds))

    # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is
    # recreated after the first writeBootLoader call. This reruns it after the new initrd has
    # been created, fixing the kernel root and subvol args and adding the missing initrd entry.
    bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)

    if isinstance(payload, LiveImagePayload):
        btrfs_task = bootloader_proxy.FixBTRFSWithTask(
            payload.kernel_version_list)
        generate_initramfs.append_dbus_tasks(STORAGE, [btrfs_task])

    # Invoking zipl should be the last thing done on a s390x installation (see #1652727).
    zipl_task = bootloader_proxy.FixZIPLWithTask()
    generate_initramfs.append_dbus_tasks(STORAGE, [zipl_task])
    configuration_queue.append(generate_initramfs)

    # realm join
    # - this can run only after network is configured in the target system chroot
    configuration_queue.append_dbus_tasks(SECURITY,
                                          [security_proxy.JoinRealmWithTask()])

    post_scripts = TaskQueue("Post installation scripts",
                             N_("Running post-installation scripts"))
    post_scripts.append(
        Task("Run post installation scripts", runPostScripts,
             (ksdata.scripts, )))
    configuration_queue.append(post_scripts)

    # setup kexec reboot if requested
    if flags.flags.kexec:
        kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec"))
        kexec_setup.append(Task("Setup kexec", setup_kexec))
        configuration_queue.append(kexec_setup)

    # write anaconda related configs & kickstarts
    write_configs = TaskQueue("Write configs and kickstarts",
                              N_("Storing configuration files and kickstarts"))

    # Write the kickstart file to the installed system (or, copy the input
    # kickstart file over if one exists).
    if flags.flags.nosave_output_ks:
        # don't write the kickstart file to the installed system if this has
        # been disabled by the nosave option
        log.warning(
            "Writing of the output kickstart to installed system has been disabled"
            " by the nosave option.")
    else:
        # write anaconda related configs & kickstarts
        write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, )))

    # only add write_configs to the main queue if we actually store some kickstarts/configs
    if write_configs.task_count:
        configuration_queue.append(write_configs)

    return configuration_queue
Exemplo n.º 27
0
    def _apply(self):
        # Do not execute sections that were part of the original
        # anaconda kickstart file (== have .seen flag set)

        log.info("applying changes")

        sections = [self.data.keyboard, self.data.lang, self.data.timezone]

        # data.selinux
        # data.firewall

        localization_proxy = LOCALIZATION.get_proxy()
        self.data.keyboard.seen = localization_proxy.KeyboardKickstarted
        self.data.lang.seen = localization_proxy.LanguageKickstarted

        timezone_proxy = TIMEZONE.get_proxy()
        self.data.timezone.seen = timezone_proxy.Kickstarted

        log.info("executing kickstart")
        for section in sections:
            section_msg = "%s on line %d" % (repr(section), section.lineno)
            if section.seen:
                log.debug("skipping %s", section_msg)
                continue
            log.debug("executing %s", section_msg)
            section.execute(None, self.data, None)

        # Prepare the user database tools
        u = Users()

        sections = [self.data.group, self.data.user, self.data.rootpw]

        user_proxy = USER.get_proxy()
        self.data.rootpw.seen = user_proxy.IsRootpwKickstarted

        for section in sections:
            section_msg = "%s on line %d" % (repr(section), section.lineno)
            if section.seen:
                log.debug("skipping %s", section_msg)
                continue
            log.debug("executing %s", section_msg)
            section.execute(None, self.data, None, u)

        # Configure all addons
        log.info("executing addons")
        self.data.addons.execute(None, self.data, None, u, None)

        if self.external_reconfig:
            # prevent the reconfig flag from being written out
            # to kickstart if neither /etc/reconfigSys or /.unconfigured
            # are present
            services_proxy = SERVICES.get_proxy()
            services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_DEFAULT)

        # Write the kickstart data to file
        log.info("writing the Initial Setup kickstart file %s", OUTPUT_KICKSTART_PATH)
        with open(OUTPUT_KICKSTART_PATH, "w") as f:
            f.write(str(self.data))
        log.info("finished writing the Initial Setup kickstart file")

        # Remove the reconfig files, if any - otherwise the reconfig mode
        # would start again next time the Initial Setup service is enabled.
        if self.external_reconfig:
            for reconfig_file in RECONFIG_FILES:
                if os.path.exists(reconfig_file):
                    log.debug("removing reconfig trigger file: %s" % reconfig_file)
                    os.remove(reconfig_file)

        # and we are done with applying changes
        log.info("all changes have been applied")
Exemplo n.º 28
0
        localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=anaconda.tui_mode)

    # we now know in which mode we are going to run so store the information
    from pykickstart import constants as pykickstart_constants
    display_mode_coversion_table = {
        constants.DisplayModes.GUI: pykickstart_constants.DISPLAY_MODE_GRAPHICAL,
        constants.DisplayModes.TUI: pykickstart_constants.DISPLAY_MODE_TEXT
    }
    ksdata.displaymode.displayMode = display_mode_coversion_table[anaconda.display_mode]
    ksdata.displaymode.nonInteractive = not anaconda.interactive_mode

    # if we're in text mode, the resulting system should be too
    # ...unless the kickstart specified otherwise
    from pyanaconda.modules.common.constants.services import SERVICES
    from pyanaconda.core.constants import TEXT_ONLY_TARGET
    services_proxy = SERVICES.get_proxy()

    if not services_proxy.DefaultTarget and anaconda.tui_mode:
        services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)

    # Set flag to prompt for missing ks data
    if not anaconda.interactive_mode:
        flags.ksprompt = False

    # Set minimal ram size to the storage checker.
    if anaconda.display_mode == constants.DisplayModes.GUI:
        min_ram = isys.MIN_GUI_RAM
    else:
        min_ram = isys.MIN_RAM

    from pyanaconda.storage_utils import storage_checker
Exemplo n.º 29
0
def doConfiguration(storage, payload, ksdata):
    """Configure the installed system."""

    configuration_queue = TaskQueue("Configuration queue")
    # connect progress reporting
    configuration_queue.queue_started.connect(
        lambda x: progress_message(x.status_message))
    configuration_queue.task_completed.connect(lambda x: progress_step(x.name))

    # schedule the execute methods of ksdata that require an installed system to be present
    os_config = TaskQueue("Installed system configuration",
                          N_("Configuring installed system"))
    os_config.append(Task("Configure authselect", ksdata.authselect.execute))

    security_proxy = SECURITY.get_proxy()
    security_dbus_tasks = security_proxy.InstallWithTasks(util.getSysroot())
    # add one Task instance per DBUS task
    for dbus_task in security_dbus_tasks:
        task_proxy = SECURITY.get_proxy(dbus_task)
        os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, )))

    services_proxy = SERVICES.get_proxy()
    services_dbus_tasks = services_proxy.InstallWithTasks(util.getSysroot())
    # add one Task instance per DBUS task
    for dbus_task in services_dbus_tasks:
        task_proxy = SERVICES.get_proxy(dbus_task)
        os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, )))

    os_config.append(Task("Configure keyboard", ksdata.keyboard.execute))
    os_config.append(Task("Configure timezone", ksdata.timezone.execute))

    localization_proxy = LOCALIZATION.get_proxy()
    localization_dbus_tasks = localization_proxy.InstallWithTasks(
        util.getSysroot())
    # add one Task instance per DBUS task
    for dbus_task in localization_dbus_tasks:
        task_proxy = LOCALIZATION.get_proxy(dbus_task)
        os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, )))

    firewall_proxy = NETWORK.get_proxy(FIREWALL)
    firewall_dbus_task = firewall_proxy.InstallWithTask(util.getSysroot())
    task_proxy = NETWORK.get_proxy(firewall_dbus_task)
    os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, )))

    configuration_queue.append(os_config)

    # schedule network configuration (if required)
    if conf.system.provides_network_config:
        network_config = TaskQueue("Network configuration",
                                   N_("Writing network configuration"))
        network_config.append(
            Task("Network configuration", ksdata.network.execute, (payload, )))
        configuration_queue.append(network_config)

    # creating users and groups requires some pre-configuration.
    user_config = TaskQueue("User creation", N_("Creating users"))

    users_proxy = USERS.get_proxy()
    users_dbus_tasks = users_proxy.InstallWithTasks(util.getSysroot())
    # add one Task instance per DBUS task
    for dbus_task in users_dbus_tasks:
        task_proxy = USERS.get_proxy(dbus_task)
        user_config.append(Task(task_proxy.Name, sync_run_task,
                                (task_proxy, )))
    configuration_queue.append(user_config)

    # Anaconda addon configuration
    addon_config = TaskQueue("Anaconda addon configuration",
                             N_("Configuring addons"))
    # there is no longer a User class & addons should no longer need it
    # FIXME: drop user class parameter from the API & all known addons
    addon_config.append(
        Task("Configure Anaconda addons", ksdata.addons.execute,
             (storage, ksdata, None, payload)))
    configuration_queue.append(addon_config)

    # Initramfs generation
    generate_initramfs = TaskQueue("Initramfs generation",
                                   N_("Generating initramfs"))
    generate_initramfs.append(
        Task("Generate initramfs", payload.recreate_initrds))

    # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is
    # recreated after the first writeBootLoader call. This reruns it after the new initrd has
    # been created, fixing the kernel root and subvol args and adding the missing initrd entry.
    boot_on_btrfs = isinstance(storage.mountpoints.get("/"), BTRFSDevice)

    bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
    bootloader_enabled = bootloader_proxy.BootloaderMode != BOOTLOADER_DISABLED

    if isinstance(payload,
                  LiveImagePayload) and boot_on_btrfs and bootloader_enabled:
        generate_initramfs.append(
            Task("Write BTRFS bootloader fix", write_boot_loader,
                 (storage, payload)))

    # Invoking zipl should be the last thing done on a s390x installation (see #1652727).
    if arch.is_s390() and not conf.target.is_directory and bootloader_enabled:
        generate_initramfs.append(
            Task("Rerun zipl", lambda: util.execInSysroot("zipl", [])))

    configuration_queue.append(generate_initramfs)

    # join a realm (if required)
    if ksdata.realm.discovered:
        join_realm = TaskQueue(
            "Realm join",
            N_("Joining realm: %s") % ksdata.realm.discovered)
        join_realm.append(Task("Join a realm", ksdata.realm.execute))
        configuration_queue.append(join_realm)

    post_scripts = TaskQueue("Post installation scripts",
                             N_("Running post-installation scripts"))
    post_scripts.append(
        Task("Run post installation scripts", runPostScripts,
             (ksdata.scripts, )))
    configuration_queue.append(post_scripts)

    # setup kexec reboot if requested
    if flags.flags.kexec:
        kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec"))
        kexec_setup.append(Task("Setup kexec", setup_kexec))
        configuration_queue.append(kexec_setup)

    # write anaconda related configs & kickstarts
    write_configs = TaskQueue("Write configs and kickstarts",
                              N_("Storing configuration files and kickstarts"))

    # Write the kickstart file to the installed system (or, copy the input
    # kickstart file over if one exists).
    if flags.flags.nosave_output_ks:
        # don't write the kickstart file to the installed system if this has
        # been disabled by the nosave option
        log.warning(
            "Writing of the output kickstart to installed system has been disabled"
            " by the nosave option.")
    else:
        # write anaconda related configs & kickstarts
        write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, )))

    # only add write_configs to the main queue if we actually store some kickstarts/configs
    if write_configs.task_count:
        configuration_queue.append(write_configs)

    # notify progress tracking about the number of steps
    progress_init(configuration_queue.task_count)
    # log contents of the main task queue
    log.info(configuration_queue.summary)

    # log tasks and queues when they are started
    # - note that we are using generators to add the counter
    queue_counter = util.item_counter(configuration_queue.queue_count)
    task_started_counter = util.item_counter(configuration_queue.task_count)
    task_completed_counter = util.item_counter(configuration_queue.task_count)
    configuration_queue.queue_started.connect(lambda x: log.info(
        "Queue started: %s (%s)", x.name, next(queue_counter)))
    configuration_queue.task_started.connect(lambda x: log.info(
        "Task started: %s (%s)", x.name, next(task_started_counter)))
    configuration_queue.task_completed.connect(
        lambda x: log.debug("Task completed: %s (%s) (%1.1f s)", x.name,
                            next(task_completed_counter), x.elapsed_time))
    # start the task queue
    configuration_queue.start()
    # done
    progress_complete()
Exemplo n.º 30
0
 def __str__(self):
     services_proxy = SERVICES.get_proxy()
     return services_proxy.GenerateKickstart()
Exemplo n.º 31
0
    def _apply(self):
        # Do not execute sections that were part of the original
        # anaconda kickstart file (== have .seen flag set)

        log.info("applying changes")

        services_proxy = SERVICES.get_proxy()
        reconfig_mode = services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG

        # data.selinux
        # data.firewall

        # Configure the timezone.
        timezone_proxy = TIMEZONE.get_proxy()
        for task_path in timezone_proxy.InstallWithTasks():
            task_proxy = TIMEZONE.get_proxy(task_path)
            sync_run_task(task_proxy)

        # Configure the localization.
        localization_proxy = LOCALIZATION.get_proxy()
        for task_path in localization_proxy.InstallWithTasks():
            task_proxy = LOCALIZATION.get_proxy(task_path)
            sync_run_task(task_proxy)

        # Configure persistent hostname
        network_proxy = NETWORK.get_proxy()
        network_task = network_proxy.ConfigureHostnameWithTask(True)
        task_proxy = NETWORK.get_proxy(network_task)
        sync_run_task(task_proxy)
        # Set current hostname
        network_proxy.SetCurrentHostname(network_proxy.Hostname)

        # Configure groups, users & root account
        #
        # NOTE: We only configure groups, users & root account if the respective
        #       kickstart commands are *not* seen in the input kickstart.
        #       This basically means that we will configure only what was
        #       set in the Initial Setup UI and will not attempt to configure
        #       anything that looks like it was configured previously in
        #       the Anaconda UI or installation kickstart.
        users_proxy = USERS.get_proxy()

        if self._groups_already_configured and not reconfig_mode:
            log.debug("skipping user group configuration - already configured")
        elif users_proxy.Groups:  # only run of there are some groups to create
            groups_task = users_proxy.ConfigureGroupsWithTask()
            task_proxy = USERS.get_proxy(groups_task)
            log.debug("configuring user groups via %s task", task_proxy.Name)
            sync_run_task(task_proxy)

        if self._users_already_configured and not reconfig_mode:
            log.debug("skipping user configuration - already configured")
        elif users_proxy.Users:  # only run if there are some users to create
            users_task = users_proxy.ConfigureUsersWithTask()
            task_proxy = USERS.get_proxy(users_task)
            log.debug("configuring users via %s task", task_proxy.Name)
            sync_run_task(task_proxy)

        if self._root_password_already_configured and not reconfig_mode:
            log.debug(
                "skipping root password configuration - already configured")
        else:
            root_task = users_proxy.SetRootPasswordWithTask()
            task_proxy = USERS.get_proxy(root_task)
            log.debug("configuring root password via %s task", task_proxy.Name)
            sync_run_task(task_proxy)

        # Configure all addons
        log.info("executing addons")
        self.data.addons.execute(storage=None,
                                 ksdata=self.data,
                                 users=None,
                                 payload=None)

        boss_proxy = BOSS.get_proxy()
        task_path = boss_proxy.InstallSystemWithTask()
        task_proxy = BOSS.get_proxy(task_path)
        sync_run_task(task_proxy)

        if self.external_reconfig:
            # prevent the reconfig flag from being written out
            # to kickstart if neither /etc/reconfigSys or /.unconfigured
            # are present
            services_proxy = SERVICES.get_proxy()
            services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_DEFAULT)

        # Write the kickstart data to file
        log.info("writing the Initial Setup kickstart file %s",
                 OUTPUT_KICKSTART_PATH)
        with open(OUTPUT_KICKSTART_PATH, "w") as f:
            f.write(str(self.data))
        log.info("finished writing the Initial Setup kickstart file")

        # Remove the reconfig files, if any - otherwise the reconfig mode
        # would start again next time the Initial Setup service is enabled.
        if self.external_reconfig:
            for reconfig_file in RECONFIG_FILES:
                if os.path.exists(reconfig_file):
                    log.debug("removing reconfig trigger file: %s" %
                              reconfig_file)
                    os.remove(reconfig_file)

        # and we are done with applying changes
        log.info("all changes have been applied")
Exemplo n.º 32
0
def _prepare_configuration(payload, ksdata):
    """Configure the installed system."""

    configuration_queue = TaskQueue("Configuration queue")
    # connect progress reporting
    configuration_queue.queue_started.connect(
        lambda x: progress_message(x.status_message))
    configuration_queue.task_completed.connect(lambda x: progress_step(x.name))

    # add installation tasks for the Subscription DBus module
    if is_module_available(SUBSCRIPTION):
        # we only run the tasks if the Subscription module is available
        subscription_config = TaskQueue("Subscription configuration",
                                        N_("Configuring Red Hat subscription"))
        subscription_proxy = SUBSCRIPTION.get_proxy()
        subscription_dbus_tasks = subscription_proxy.InstallWithTasks()
        subscription_config.append_dbus_tasks(SUBSCRIPTION,
                                              subscription_dbus_tasks)
        configuration_queue.append(subscription_config)

    # schedule the execute methods of ksdata that require an installed system to be present
    os_config = TaskQueue("Installed system configuration",
                          N_("Configuring installed system"))

    # add installation tasks for the Security DBus module
    security_proxy = SECURITY.get_proxy()
    security_dbus_tasks = security_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(SECURITY, security_dbus_tasks)

    # add installation tasks for the Timezone DBus module
    # run these tasks before tasks of the Services module
    if is_module_available(TIMEZONE):
        timezone_proxy = TIMEZONE.get_proxy()
        timezone_dbus_tasks = timezone_proxy.InstallWithTasks()
        os_config.append_dbus_tasks(TIMEZONE, timezone_dbus_tasks)

    # add installation tasks for the Services DBus module
    services_proxy = SERVICES.get_proxy()
    services_dbus_tasks = services_proxy.InstallWithTasks()
    os_config.append_dbus_tasks(SERVICES, services_dbus_tasks)

    # add installation tasks for the Localization DBus module
    if is_module_available(LOCALIZATION):
        localization_proxy = LOCALIZATION.get_proxy()
        localization_dbus_tasks = localization_proxy.InstallWithTasks()
        os_config.append_dbus_tasks(LOCALIZATION, localization_dbus_tasks)

    # add the Firewall configuration task
    if conf.target.can_configure_network:
        firewall_proxy = NETWORK.get_proxy(FIREWALL)
        firewall_dbus_task = firewall_proxy.InstallWithTask()
        os_config.append_dbus_tasks(NETWORK, [firewall_dbus_task])

    configuration_queue.append(os_config)

    # schedule network configuration (if required)
    if conf.target.can_configure_network and conf.system.provides_network_config:
        overwrite = payload.type in PAYLOAD_LIVE_TYPES
        network_config = TaskQueue("Network configuration",
                                   N_("Writing network configuration"))
        network_config.append(
            Task("Network configuration", network.write_configuration,
                 (overwrite, )))
        configuration_queue.append(network_config)

    # add installation tasks for the Users DBus module
    if is_module_available(USERS):
        user_config = TaskQueue("User creation", N_("Creating users"))
        users_proxy = USERS.get_proxy()
        users_dbus_tasks = users_proxy.InstallWithTasks()
        user_config.append_dbus_tasks(USERS, users_dbus_tasks)
        configuration_queue.append(user_config)

    # Anaconda addon configuration
    addon_config = TaskQueue("Anaconda addon configuration",
                             N_("Configuring addons"))

    # there is no longer a User class & addons should no longer need it
    # FIXME: drop user class parameter from the API & all known addons
    addon_config.append(
        Task("Configure Anaconda addons", ksdata.addons.execute,
             (None, ksdata, None, payload)))

    boss_proxy = BOSS.get_proxy()
    addon_config.append_dbus_tasks(BOSS, [boss_proxy.InstallSystemWithTask()])

    configuration_queue.append(addon_config)

    # Initramfs generation
    generate_initramfs = TaskQueue("Initramfs generation",
                                   N_("Generating initramfs"))
    bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)

    def run_generate_initramfs():
        tasks = bootloader_proxy.GenerateInitramfsWithTasks(
            payload.type, payload.kernel_version_list)

        for task in tasks:
            sync_run_task(STORAGE.get_proxy(task))

    generate_initramfs.append(
        Task("Generate initramfs", run_generate_initramfs))
    configuration_queue.append(generate_initramfs)

    # Configure FIPS.
    configuration_queue.append_dbus_tasks(
        SECURITY, [security_proxy.ConfigureFIPSWithTask()])

    # realm join
    # - this can run only after network is configured in the target system chroot
    configuration_queue.append_dbus_tasks(SECURITY,
                                          [security_proxy.JoinRealmWithTask()])

    post_scripts = TaskQueue("Post installation scripts",
                             N_("Running post-installation scripts"))
    post_scripts.append(
        Task("Run post installation scripts", runPostScripts,
             (ksdata.scripts, )))
    configuration_queue.append(post_scripts)

    # setup kexec reboot if requested
    if flags.flags.kexec:
        kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec"))
        kexec_setup.append(Task("Setup kexec", setup_kexec))
        configuration_queue.append(kexec_setup)

    # write anaconda related configs & kickstarts
    write_configs = TaskQueue("Write configs and kickstarts",
                              N_("Storing configuration files and kickstarts"))

    # Write the kickstart file to the installed system (or, copy the input
    # kickstart file over if one exists).
    if flags.flags.nosave_output_ks:
        # don't write the kickstart file to the installed system if this has
        # been disabled by the nosave option
        log.warning(
            "Writing of the output kickstart to installed system has been disabled"
            " by the nosave option.")
    else:
        # write anaconda related configs & kickstarts
        write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, )))

    # only add write_configs to the main queue if we actually store some kickstarts/configs
    if write_configs.task_count:
        configuration_queue.append(write_configs)

    return configuration_queue
Exemplo n.º 33
0
 def __str__(self):
     services_proxy = SERVICES.get_proxy()
     return services_proxy.GenerateKickstart()