Beispiel #1
0
    def __init__(self, data, storage, payload):
        super().__init__(data, storage, payload)
        self.title = N_("Partitioning Options")
        self._container = None
        self._part_type_list = sorted(PARTTYPES.keys())

        # remember the original values so that we can detect a change
        self._disk_init_proxy = STORAGE.get_proxy(DISK_INITIALIZATION)
        self._orig_init_mode = self._disk_init_proxy.InitializationMode
        self._manual_part_proxy = STORAGE.get_proxy(MANUAL_PARTITIONING)
        self._orig_mount_assign = self._manual_part_proxy.Enabled

        # Create the auto partitioning proxy
        self._auto_part_proxy = STORAGE.get_proxy(AUTO_PARTITIONING)

        # default to mount point assignment if it is already (partially)
        # configured
        self._do_mount_assign = self._orig_mount_assign
        if not self._do_mount_assign:
            self._init_mode = self._disk_init_proxy.InitializationMode
        else:
            self._init_mode = CLEAR_PARTITIONS_NONE
Beispiel #2
0
    def __init__(self, data, storage, payload, partitioning):
        super().__init__(data, storage, payload)
        self.title = N_("Partition Scheme Options")
        self._container = None
        self._part_schemes = OrderedDict()
        self._partitioning = partitioning
        self._request = PartitioningRequest.from_structure(
            self._partitioning.Request
        )

        supported_choices = get_supported_autopart_choices()

        if supported_choices:
            # Fallback value (eg when default is not supported)
            self._selected_scheme_value = supported_choices[0][1]

        selected_choice = self._request.partitioning_scheme

        for item in supported_choices:
            self._part_schemes[item[0]] = item[1]
            if item[1] == selected_choice:
                self._selected_scheme_value = item[1]
Beispiel #3
0
    def __init__(self, data, storage, payload, storage_module, partitioning):
        super().__init__(data, storage, payload)
        self.title = N_("Partitioning Options")
        self._container = None

        # Choose the initialization mode.
        self._disk_init_proxy = STORAGE.get_proxy(DISK_INITIALIZATION)
        self._orig_init_mode = self._disk_init_proxy.InitializationMode
        self._init_mode = self._orig_init_mode
        self._init_mode_list = sorted(INIT_MODES.keys())

        if self._init_mode == CLEAR_PARTITIONS_DEFAULT:
            self._init_mode = CLEAR_PARTITIONS_ALL

        # Choose the partitioning method.
        self._storage_module = storage_module
        self._partitioning = partitioning
        self._orig_part_method = self._partitioning.PartitioningMethod
        self._part_method = self._orig_part_method

        if self._part_method == PARTITIONING_METHOD_MANUAL:
            self._init_mode = CLEAR_PARTITIONS_NONE
    def __init__(self, data, storage, payload):
        super().__init__(data, storage, payload)
        self.title = N_("Software selection")
        self._container = None
        self.errors = []
        self._tx_id = None
        self._selected_environment = None
        self.environment = None
        self._addons_selection = set()
        self.addons = set()

        # for detecting later whether any changes have been made
        self._orig_env = None
        self._orig_addons = set()

        # are we taking values (package list) from a kickstart file?
        self._kickstarted = flags.automatedInstall and self.data.packages.seen

        # Register event listeners to update our status on payload events
        payloadMgr.add_listener(PayloadState.STARTED, self._payload_start)
        payloadMgr.add_listener(PayloadState.FINISHED, self._payload_finished)
        payloadMgr.add_listener(PayloadState.ERROR, self._payload_error)
Beispiel #5
0
    def __init__(self, data, storage, payload):
        FirstbootSpokeMixIn.__init__(self)
        NormalTUISpoke.__init__(self, data, storage, payload)

        self.initialize_start()

        # connect to the Users DBus module
        self._users_module = USERS.get_proxy()

        self.title = N_("User creation")
        self._container = None

        # was user creation requested by the Users DBus module
        # - at the moment this basically means user creation was
        #   requested via kickstart
        # - note that this does not currently update when user
        #   list is changed via DBus
        self._user_requested = False
        self._user_cleared = False

        # should a user be created ?
        self._create_user = False

        self._user_list = get_user_list(self._users_module, add_default=True)
        # if user has a name, it's an actual user that has been requested,
        # rather than a default user added by us
        if self.user.name:
            self._user_requested = True
            self._create_user = True

        self._use_password = self.user.is_crypted or self.user.password
        self._groups = ""
        self._is_admin = False
        self.errors = []

        self._users_module = USERS.get_proxy()

        self.initialize_done()
Beispiel #6
0
class SpokeCategory(object):
    """A SpokeCategory is an object used to group multiple related Spokes
       together on a hub.  It consists of a title displayed above, and then
       a two-column grid of SpokeSelectors.  Each SpokeSelector is associated
       with a Spoke subclass.  A SpokeCategory will only display those Spokes
       with a matching category attribute.

       Class attributes:

       displayOnHubGUI  -- The GUI Hub subclass to display this Category on.
                           If None, this Category will be skipped.
       displayOnHubTUI  -- The TUI Hub subclass to display this Category on.
                           If None, this Category will be skipped.
       sortOrder     -- A number indicating the order in which this Category
                        will be displayed.  A lower number indicates display
                        higher up in the Hub.
       title         -- The title of this SpokeCategory, to be displayed above
                        the grid.
    """
    displayOnHubGUI = None
    displayOnHubTUI = None
    sortOrder = 1000
    title = N_("DEFAULT TITLE")
Beispiel #7
0
    def __init__(self, data, storage, payload, instclass):
        NormalTUISpoke.__init__(self, data, storage, payload, instclass)

        self.title = N_("Timezone settings")
        self._container = None
        # it's stupid to call get_all_regions_and_timezones twice, but regions
        # needs to be unsorted in order to display in the same order as the GUI
        # so whatever
        self._regions = list(timezone.get_all_regions_and_timezones().keys())
        self._timezones = dict(
            (k, sorted(v))
            for k, v in timezone.get_all_regions_and_timezones().items())
        self._lower_regions = [r.lower() for r in self._regions]

        self._zones = [
            "%s/%s" % (region, z) for region in self._timezones
            for z in self._timezones[region]
        ]
        # for lowercase lookup
        self._lower_zones = [
            z.lower().replace("_", " ") for region in self._timezones
            for z in self._timezones[region]
        ]
        self._selection = ""
Beispiel #8
0
    def __init__(self, data, storage, payload):
        super().__init__(data, storage, payload)
        self.title = N_("Installation Destination")
        self._container = None
        self._ready = False
        self._select_all = False

        self._storage_module = STORAGE.get_proxy()
        self._device_tree = STORAGE.get_proxy(DEVICE_TREE)
        self._bootloader_module = STORAGE.get_proxy(BOOTLOADER)
        self._disk_init_module = STORAGE.get_proxy(DISK_INITIALIZATION)
        self._disk_select_module = STORAGE.get_proxy(DISK_SELECTION)

        self._available_disks = []
        self._selected_disks = []

        # Is the partitioning already configured?
        self._is_preconfigured = bool(self._storage_module.CreatedPartitioning)

        # Find a partitioning to use.
        self._partitioning = find_partitioning()

        self.errors = []
        self.warnings = []
Beispiel #9
0
def doInstall(storage, payload, ksdata):
    """Perform an installation.  This method takes the ksdata as prepared by
       the UI (the first hub, in graphical mode) and applies it to the disk.
       The two main tasks for this are putting filesystems onto disks and
       installing packages onto those filesystems.
    """
    bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
    bootloader_enabled = bootloader_proxy.BootloaderMode != BOOTLOADER_DISABLED
    can_install_bootloader = not conf.target.is_directory and bootloader_enabled

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

    # This should be the only thread running, wait for the others to finish if not.
    if threadMgr.running > 1:
        # it could be that the threads finish execution before the task is executed,
        # but that should not cause any issues

        def wait_for_all_treads():
            for message in ("Thread %s is running" % n
                            for n in threadMgr.names):
                log.debug(message)
            threadMgr.wait_all()

        # Use a queue with a single task as only TaskQueues have the status_message
        # property used for setting the progress status in the UI.
        wait_for_threads = TaskQueue(
            "Wait for threads to finish",
            N_("Waiting for %s threads to finish") % (threadMgr.running - 1))

        wait_for_threads.append(
            Task("Wait for all threads to finish", wait_for_all_treads))
        installation_queue.append(wait_for_threads)

    # Save system time to HW clock.
    # - this used to be before waiting on threads, but I don't think that's needed
    if conf.system.can_set_hardware_clock:
        # lets just do this as a top-level task - no
        save_hwclock = Task("Save system time to HW clock",
                            timezone.save_hw_clock)
        installation_queue.append(save_hwclock)

    # setup the installation environment
    setup_environment = TaskQueue(
        "Installation environment setup",
        N_("Setting up the installation environment"))
    setup_environment.append(
        Task("Setup addons", ksdata.addons.setup, (storage, ksdata, payload)))
    installation_queue.append(setup_environment)

    # Do partitioning.
    # Depending on current payload the storage might be apparently configured
    # either before or after package/payload installation.
    # So let's have two task queues - early storage & late storage.
    early_storage = TaskQueue("Early storage configuration",
                              N_("Configuring storage"))

    # put custom storage info into ksdata
    early_storage.append(
        Task("Insert custom storage to ksdata",
             task=update_storage_ksdata,
             task_args=(storage, ksdata)))

    # callbacks for blivet
    message_clbk = lambda clbk_data: progress_message(clbk_data.msg)
    entropy_wait_clbk = lambda clbk_data: wait_for_entropy(
        clbk_data.msg, clbk_data.min_entropy, ksdata)
    callbacks_reg = callbacks.create_new_callbacks_register(
        create_format_pre=message_clbk,
        resize_format_pre=message_clbk,
        wait_for_entropy=entropy_wait_clbk)
    if not conf.target.is_directory:
        early_storage.append(
            Task("Activate filesystems",
                 task=turn_on_filesystems,
                 task_args=(storage, ),
                 task_kwargs={"callbacks": callbacks_reg}))

    early_storage.append(
        Task("Mount filesystems", task=storage.mount_filesystems))

    if payload.needs_storage_configuration and not conf.target.is_directory:
        early_storage.append(
            Task("Write early storage",
                 task=write_storage_configuration,
                 task_args=(storage, )))

    installation_queue.append(early_storage)

    # Run %pre-install scripts with the filesystem mounted and no packages
    pre_install_scripts = TaskQueue("Pre-install scripts",
                                    N_("Running pre-installation scripts"))
    pre_install_scripts.append(
        Task("Run %pre-install scripts", runPreInstallScripts,
             (ksdata.scripts, )))
    installation_queue.append(pre_install_scripts)

    # Do packaging.

    # Discover information about realms to join to determine the need for additional packages.
    realm_discover = TaskQueue("Realm discover",
                               N_("Discovering realm to join"))
    realm_discover.append(Task("Discover realm to join", ksdata.realm.setup))
    installation_queue.append(realm_discover)

    # Check for other possibly needed additional packages.
    pre_install = TaskQueue("Pre install tasks",
                            N_("Running pre-installation tasks"))
    pre_install.append(Task("Setup authselect", ksdata.authselect.setup))
    pre_install.append(Task("Setup firewall", ksdata.firewall.setup))
    pre_install.append(Task("Setup network", ksdata.network.setup))
    # Setup timezone and add chrony as package if timezone was set in KS
    # and "-chrony" wasn't in packages section and/or --nontp wasn't set.
    pre_install.append(
        Task("Setup timezone", ksdata.timezone.setup, (ksdata, )))

    # make name resolution work for rpm scripts in chroot
    if conf.system.provides_resolver_config:
        # we use a custom Task subclass as the sysroot path has to be resolved
        # only when the task is actually started, not at task creation time
        pre_install.append(WriteResolvConfTask("Copy resolv.conf to sysroot"))

    def run_pre_install():
        """This means to gather what additional packages (if any) are needed & executing payload.pre_install()."""
        # anaconda requires storage packages in order to make sure the target
        # system is bootable and configurable, and some other packages in order
        # to finish setting up the system.
        payload.requirements.add_packages(storage.packages, reason="storage")
        payload.requirements.add_packages(ksdata.realm.packages,
                                          reason="realm")
        payload.requirements.add_packages(ksdata.authselect.packages,
                                          reason="authselect")
        payload.requirements.add_packages(ksdata.firewall.packages,
                                          reason="firewall")
        payload.requirements.add_packages(ksdata.network.packages,
                                          reason="network")
        payload.requirements.add_packages(ksdata.timezone.packages,
                                          reason="ntp",
                                          strong=False)

        if can_install_bootloader:
            payload.requirements.add_packages(storage.bootloader.packages,
                                              reason="bootloader")
        payload.requirements.add_groups(payload.language_groups(),
                                        reason="language groups")
        payload.requirements.add_packages(payload.langpacks(),
                                          reason="langpacks",
                                          strong=False)
        payload.pre_install()

    pre_install.append(
        Task("Find additional packages & run pre_install()", run_pre_install))
    installation_queue.append(pre_install)

    payload_install = TaskQueue("Payload installation", N_("Installing."))
    payload_install.append(Task("Install the payload", payload.install))
    installation_queue.append(payload_install)

    # for some payloads storage is configured after the payload is installed
    if not payload.needs_storage_configuration:
        late_storage = TaskQueue("Late storage configuration",
                                 N_("Configuring storage"))
        late_storage.append(
            Task("Prepare mount targets",
                 task=payload.prepare_mount_targets,
                 task_args=(storage, )))

        if not conf.target.is_directory:
            late_storage.append(
                Task("Write late storage",
                     task=write_storage_configuration,
                     task_args=(storage, )))

        installation_queue.append(late_storage)

    # Do bootloader.
    if can_install_bootloader:
        bootloader_install = TaskQueue("Bootloader installation",
                                       N_("Installing boot loader"))
        bootloader_install.append(
            Task("Install bootloader", write_boot_loader, (storage, payload)))
        installation_queue.append(bootloader_install)

    post_install = TaskQueue("Post-installation setup tasks",
                             (N_("Performing post-installation setup tasks")))
    post_install.append(
        Task("Run post-installation setup tasks", payload.post_install))
    installation_queue.append(post_install)

    # Create snapshot
    snapshot_proxy = STORAGE.get_proxy(SNAPSHOT)

    if snapshot_proxy.IsRequested(SNAPSHOT_WHEN_POST_INSTALL):
        snapshot_creation = TaskQueue("Creating post installation snapshots",
                                      N_("Creating snapshots"))
        snapshot_requests = ksdata.snapshot.get_requests(
            SNAPSHOT_WHEN_POST_INSTALL)
        snapshot_task = SnapshotCreateTask(storage, snapshot_requests,
                                           SNAPSHOT_WHEN_POST_INSTALL)
        snapshot_creation.append(
            Task("Create post-install snapshots", snapshot_task.run))
        installation_queue.append(snapshot_creation)

    # notify progress tracking about the number of steps
    progress_init(installation_queue.task_count)
    # log contents of the main task queue
    log.info(installation_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(installation_queue.queue_count)
    task_started_counter = util.item_counter(installation_queue.task_count)
    task_completed_counter = util.item_counter(installation_queue.task_count)
    installation_queue.queue_started.connect(lambda x: log.info(
        "Queue started: %s (%s)", x.name, next(queue_counter)))
    installation_queue.task_started.connect(lambda x: log.info(
        "Task started: %s (%s)", x.name, next(task_started_counter)))
    installation_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
    installation_queue.start()
    # done
    progress_complete()
Beispiel #10
0
class PowerNV(PPC):
    _boot_descriptions = {"partition": Platform._boot_partition_description}
    _boot_stage1_missing_error = N_(
        "You must include at least one disk as an install target.")
Beispiel #11
0
from pyanaconda.errors import errorHandler, ERROR_RAISE
from pyanaconda.modules.common.constants.services import NETWORK, STORAGE
from pyanaconda.modules.common.constants.objects import DISK_SELECTION, NVDIMM, DISK_INITIALIZATION

from pykickstart.constants import AUTOPART_TYPE_PLAIN, AUTOPART_TYPE_BTRFS
from pykickstart.constants import AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP

from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)

# TODO: all those constants and mappings should go to blivet
# Used for info about device with no more supported type (ie btrfs).
DEVICE_TYPE_UNSUPPORTED = -1

DEVICE_TEXT_MAP = {
    DEVICE_TYPE_UNSUPPORTED: N_("Unsupported"),
    DEVICE_TYPE_LVM: N_("LVM"),
    DEVICE_TYPE_MD: N_("RAID"),
    DEVICE_TYPE_PARTITION: N_("Standard Partition"),
    DEVICE_TYPE_BTRFS: N_("Btrfs"),
    DEVICE_TYPE_LVM_THINP: N_("LVM Thin Provisioning"),
    DEVICE_TYPE_DISK: N_("Disk")
}

PARTITION_ONLY_FORMAT_TYPES = ("macefi", "prepboot", "biosboot", "appleboot")

MOUNTPOINT_DESCRIPTIONS = {"Swap": N_("The 'swap' area on your computer is used by the operating\n"
                                      "system when running low on memory."),
                           "Boot": N_("The 'boot' area on your computer is where files needed\n"
                                      "to start the operating system are stored."),
                           "Root": N_("The 'root' area on your computer is where core system\n"
Beispiel #12
0
def _prepare_installation(payload, ksdata):
    """Perform an installation.  This method takes the ksdata as prepared by
       the UI (the first hub, in graphical mode) and applies it to the disk.
       The two main tasks for this are putting filesystems onto disks and
       installing packages onto those filesystems.
    """
    installation_queue = TaskQueue("Installation queue")
    # connect progress reporting
    installation_queue.queue_started.connect(
        lambda x: progress_message(x.status_message))
    installation_queue.task_completed.connect(lambda x: progress_step(x.name))

    # This should be the only thread running, wait for the others to finish if not.
    if threadMgr.running > 1:
        # it could be that the threads finish execution before the task is executed,
        # but that should not cause any issues

        def wait_for_all_treads():
            for message in ("Thread %s is running" % n
                            for n in threadMgr.names):
                log.debug(message)
            threadMgr.wait_all()

        # Use a queue with a single task as only TaskQueues have the status_message
        # property used for setting the progress status in the UI.
        wait_for_threads = TaskQueue(
            "Wait for threads to finish",
            N_("Waiting for %s threads to finish") % (threadMgr.running - 1))

        wait_for_threads.append(
            Task("Wait for all threads to finish", wait_for_all_treads))
        installation_queue.append(wait_for_threads)

    # Save system time to HW clock.
    # - this used to be before waiting on threads, but I don't think that's needed
    if conf.system.can_set_hardware_clock:
        # lets just do this as a top-level task - no
        save_hwclock = Task("Save system time to HW clock",
                            timezone.save_hw_clock)
        installation_queue.append(save_hwclock)

    # setup the installation environment
    setup_environment = TaskQueue(
        "Installation environment setup",
        N_("Setting up the installation environment"))
    setup_environment.append(
        Task("Setup addons", ksdata.addons.setup, (None, ksdata, payload)))

    boss_proxy = BOSS.get_proxy()
    setup_environment.append_dbus_tasks(
        BOSS, [boss_proxy.ConfigureRuntimeWithTask()])

    installation_queue.append(setup_environment)

    # Do partitioning.
    # Depending on current payload the storage might be apparently configured
    # either before or after package/payload installation.
    # So let's have two task queues - early storage & late storage.
    storage_proxy = STORAGE.get_proxy()
    early_storage = TaskQueue("Early storage configuration",
                              N_("Configuring storage"))
    early_storage.append_dbus_tasks(STORAGE, storage_proxy.InstallWithTasks())

    if payload.type == PAYLOAD_TYPE_DNF:
        conf_task = storage_proxy.WriteConfigurationWithTask()
        early_storage.append_dbus_tasks(STORAGE, [conf_task])

    installation_queue.append(early_storage)

    # Run %pre-install scripts with the filesystem mounted and no packages
    pre_install_scripts = TaskQueue("Pre-install scripts",
                                    N_("Running pre-installation scripts"))
    pre_install_scripts.append(
        Task("Run %pre-install scripts", runPreInstallScripts,
             (ksdata.scripts, )))
    installation_queue.append(pre_install_scripts)

    # Do various pre-installation tasks
    # - try to discover a realm (if any)
    # - check for possibly needed additional packages.
    pre_install = TaskQueue("Pre install tasks",
                            N_("Running pre-installation tasks"))

    # make name resolution work for rpm scripts in chroot
    if conf.system.provides_resolver_config:
        # we use a custom Task subclass as the sysroot path has to be resolved
        # only when the task is actually started, not at task creation time
        pre_install.append(WriteResolvConfTask("Copy resolv.conf to sysroot"))

    # realm discovery
    security_proxy = SECURITY.get_proxy()
    pre_install.append_dbus_tasks(SECURITY,
                                  [security_proxy.DiscoverRealmWithTask()])

    # Set up FIPS for the payload installation.
    fips_task = security_proxy.PreconfigureFIPSWithTask(payload.type)
    pre_install.append_dbus_tasks(SECURITY, [fips_task])

    # Install the payload.
    pre_install.append(
        Task("Find additional packages & run pre_install()",
             payload.pre_install))
    installation_queue.append(pre_install)

    payload_install = TaskQueue("Payload installation", N_("Installing."))
    payload_install.append(Task("Install the payload", payload.install))
    installation_queue.append(payload_install)

    # for some payloads storage is configured after the payload is installed
    if payload.type != PAYLOAD_TYPE_DNF:
        late_storage = TaskQueue("Late storage configuration",
                                 N_("Configuring storage"))
        conf_task = storage_proxy.WriteConfigurationWithTask()
        late_storage.append_dbus_tasks(STORAGE, [conf_task])
        installation_queue.append(late_storage)

    # Do bootloader.
    bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
    bootloader_install = TaskQueue("Bootloader installation",
                                   N_("Installing boot loader"))

    def run_install_bootloader():
        tasks = bootloader_proxy.InstallBootloaderWithTasks(
            payload.type, payload.kernel_version_list)

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

    bootloader_install.append(
        Task("Install bootloader", run_install_bootloader))
    installation_queue.append(bootloader_install)

    post_install = TaskQueue("Post-installation setup tasks",
                             (N_("Performing post-installation setup tasks")))
    post_install.append(
        Task("Run post-installation setup tasks", payload.post_install))
    installation_queue.append(post_install)

    # Create snapshot
    snapshot_proxy = STORAGE.get_proxy(SNAPSHOT)

    if snapshot_proxy.IsRequested(SNAPSHOT_WHEN_POST_INSTALL):
        snapshot_creation = TaskQueue("Creating post installation snapshots",
                                      N_("Creating snapshots"))
        snapshot_task = snapshot_proxy.CreateWithTask(
            SNAPSHOT_WHEN_POST_INSTALL)
        snapshot_creation.append_dbus_tasks(STORAGE, [snapshot_task])
        installation_queue.append(snapshot_creation)

    return installation_queue
Beispiel #13
0
    def install(self):
        progress_message(N_('Starting package installation process'))

        # Add the rpm macros to the global transaction environment
        for macro in self.rpmMacros:
            rpm.addMacro(macro[0], macro[1])

        if self.install_device:
            self._setupMedia(self.install_device)
        try:
            self.checkSoftwareSelection()
            self._download_location = self._pick_download_location()
        except payload.PayloadError as e:
            if errors.errorHandler.cb(e) == errors.ERROR_RAISE:
                log.error("Installation failed: %r", e)
                _failure_limbo()

        if os.path.exists(self._download_location):
            log.info("Removing existing package download location: %s",
                     self._download_location)
            shutil.rmtree(self._download_location)
        pkgs_to_download = self._base.transaction.install_set
        log.info('Downloading packages to %s.', self._download_location)
        progressQ.send_message(_('Downloading packages'))
        progress = DownloadProgress()
        try:
            self._base.download_packages(pkgs_to_download, progress)
        except dnf.exceptions.DownloadError as e:
            msg = 'Failed to download the following packages: %s' % str(e)
            exc = payload.PayloadInstallError(msg)
            if errors.errorHandler.cb(exc) == errors.ERROR_RAISE:
                log.error("Installation failed: %r", exc)
                _failure_limbo()

        log.info('Downloading packages finished.')

        pre_msg = (N_("Preparing transaction from installation source"))
        progress_message(pre_msg)

        queue_instance = multiprocessing.Queue()
        process = multiprocessing.Process(target=do_transaction,
                                          args=(self._base, queue_instance))
        process.start()
        (token, msg) = queue_instance.get()
        # When the installation works correctly it will get 'install' updates
        # followed by a 'post' message and then a 'quit' message.
        # If the installation fails it will send 'quit' without 'post'
        while token:
            if token == 'install':
                msg = _("Installing %s") % msg
                progressQ.send_message(msg)
            elif token == 'configure':
                msg = _("Configuring %s") % msg
                progressQ.send_message(msg)
            elif token == 'verify':
                msg = _("Verifying %s") % msg
                progressQ.send_message(msg)
            elif token == 'log':
                log.info(msg)
            elif token == 'post':
                msg = (N_("Performing post-installation setup tasks"))
                progressQ.send_message(msg)
            elif token == 'done':
                break  # Installation finished successfully
            elif token == 'quit':
                msg = (
                    "Payload error - DNF installation has ended up abruptly: %s"
                    % msg)
                raise payload.PayloadError(msg)
            elif token == 'error':
                exc = payload.PayloadInstallError("DNF error: %s" % msg)
                if errors.errorHandler.cb(exc) == errors.ERROR_RAISE:
                    log.error("Installation failed: %r", exc)
                    _failure_limbo()
            (token, msg) = queue_instance.get()

        process.join()
        self._base.close()
        if os.path.exists(self._download_location):
            log.info("Cleaning up downloaded packages: %s",
                     self._download_location)
            shutil.rmtree(self._download_location)
        else:
            # Some installation sources, such as NFS, don't need to download packages to
            # local storage, so the download location might not always exist. So for now
            # warn about this, at least until the RFE in bug 1193121 is implemented and
            # we don't have to care about clearing the download location ourselves.
            log.warning("Can't delete nonexistent download location: %s",
                        self._download_location)
Beispiel #14
0
class AskVNCSpoke(NormalTUISpoke):
    """
       .. inheritance-diagram:: AskVNCSpoke
          :parts: 3
    """
    title = N_("VNC")

    # This spoke is kinda standalone, not meant to be used with a hub
    # We pass in some fake data just to make our parents happy
    def __init__(self,
                 data,
                 storage=None,
                 payload=None,
                 instclass=None,
                 message=""):
        NormalTUISpoke.__init__(self, data, storage, payload, instclass)
        self.input_required = True
        self.initialize_start()
        self._container = None

        # The TUI hasn't been initialized with the message handlers yet. Add an
        # exception message handler so that the TUI exits if anything goes wrong
        # at this stage.
        loop = App.get_event_loop()
        loop.register_signal_handler(ExceptionSignal,
                                     exception_msg_handler_and_exit)
        self._message = message
        self._usevnc = False
        self.initialize_done()

    @property
    def indirect(self):
        return True

    def refresh(self, args=None):
        NormalTUISpoke.refresh(self, args)

        self.window.add_with_separator(TextWidget(self._message))

        self._container = ListColumnContainer(1, spacing=1)

        # choices are
        # USE VNC
        self._container.add(TextWidget(_(USEVNC)), self._use_vnc_callback)
        # USE TEXT
        self._container.add(TextWidget(_(USETEXT)), self._use_text_callback)

        self.window.add_with_separator(self._container)

    def _use_vnc_callback(self, data):
        self._usevnc = True
        new_spoke = VNCPassSpoke(self.data, self.storage, self.payload,
                                 self.instclass)
        ScreenHandler.push_screen_modal(new_spoke)

    def _use_text_callback(self, data):
        self._usevnc = False

    def input(self, args, key):
        """Override input so that we can launch the VNC password spoke"""
        if self._container.process_user_input(key):
            self.apply()
            self.close()
            return InputState.PROCESSED
        else:
            # TRANSLATORS: 'q' to quit
            if key.lower() == C_('TUI|Spoke Navigation', 'q'):
                d = YesNoDialog(_(u"Do you really want to quit?"))
                ScreenHandler.push_screen_modal(d)
                if d.answer:
                    ipmi_abort(scripts=self.data.scripts)
                    if can_touch_runtime_system("Quit and Reboot"):
                        execWithRedirect("systemctl", ["--no-wall", "reboot"])
                    else:
                        sys.exit(1)
            else:
                return super(AskVNCSpoke, self).input(args, key)

    def apply(self):
        self.data.vnc.enabled = self._usevnc
Beispiel #15
0
from pyanaconda.modules.common.constants.services import USERS
from pyanaconda.modules.common.util import is_module_available
from pyanaconda.ui.categories.user_settings import UserSettingsCategory
from pyanaconda.ui.common import FirstbootSpokeMixIn
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.ui.tui.tuiobject import Dialog, PasswordDialog, report_if_failed, report_check_func
from pyanaconda.ui.lib.users import get_user_list, set_user_list
from pyanaconda.core.users import guess_username, check_username, check_grouplist

from simpleline.render.screen import InputState
from simpleline.render.containers import ListColumnContainer
from simpleline.render.widgets import CheckboxWidget, EntryWidget

__all__ = ["UserSpoke"]

FULLNAME_ERROR_MSG = N_("Full name can't contain the ':' character")


class UserSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
    """
       .. inheritance-diagram:: UserSpoke
          :parts: 3
    """
    category = UserSettingsCategory

    @staticmethod
    def get_screen_id():
        """Return a unique id of this UI screen."""
        return "user-configuration"

    @classmethod
Beispiel #16
0
class PayloadManager(object):
    """Framework for starting and watching the payload thread.

    This class defines several states (PayloadState enum), and events can
    be triggered upon reaching a state. Depending on whether a state has
    already been reached when a listener is added, the event code may be
    run in either the calling thread or the payload thread. The event code
    will block the payload thread regardless, so try not to run anything
    that takes a long time.

    All states except ERROR are expected to happen linearly, and adding
    a listener for a state that has already been reached or passed will
    immediately trigger that listener. For example, if the payload thread is
    currently in DOWNLOADING_GROUP_METADATA, adding a listener for
    WAITING_NETWORK will immediately run the code being added
    for WAITING_NETWORK.

    The payload thread data should be accessed using the payloadMgr object,
    and the running thread can be accessed using threadMgr with the
    THREAD_PAYLOAD constant, if you need to wait for it or something. The
    thread should be started using payloadMgr.restart_thread.
    """
    # Error strings
    ERROR_SETUP = N_("Failed to set up installation source")
    ERROR_MD = N_("Error downloading package metadata")

    def __init__(self):
        self._event_lock = threading.Lock()
        self._event_listeners = {}
        self._thread_state = PayloadState.STARTED
        self._error = None

        # Initialize a list for each event state
        for _name, value in PayloadState.__members__.items():
            self._event_listeners[PayloadState(value)] = []

    @property
    def error(self):
        return _(self._error)

    def add_listener(self, event_id, func):
        """Add a listener for an event.

        :param int event_id: The event to listen for, one of the EVENT_* constants
        :param function func: An object to call when the event is reached
        """

        # Check that the event_id is valid
        assert isinstance(event_id, PayloadState)

        # Add the listener inside the lock in case we need to run immediately,
        # to make sure the listener isn't triggered twice
        with self._event_lock:
            self._event_listeners[event_id].append(func)

            # If an error event was requested, run it if currently in an error state
            if event_id == PayloadState.ERROR:
                if event_id == self._thread_state:
                    func()
            # Otherwise, run if the requested event has already occurred
            elif event_id <= self._thread_state:
                func()

    def restart_thread(self,
                       payload,
                       fallback=False,
                       checkmount=True,
                       onlyOnChange=False):
        """Start or restart the payload thread.

        This method starts a new thread to restart the payload thread, so
        this method's return is not blocked by waiting on the previous payload
        thread. If there is already a payload thread restart pending, this method
        has no effect.

        :param payload.Payload payload: The payload instance
        :param bool fallback: Whether to fall back to the default repo in case of error
        :param bool checkmount: Whether to check for valid mounted media
        :param bool onlyOnChange: Restart thread only if existing repositories changed.
                                  This won't restart thread even when a new repository was added!!
        """
        log.debug("Restarting payload thread")

        # If a restart thread is already running, don't start a new one
        if threadMgr.get(THREAD_PAYLOAD_RESTART):
            return

        # Launch a new thread so that this method can return immediately
        threadMgr.add(
            AnacondaThread(name=THREAD_PAYLOAD_RESTART,
                           target=self._restart_thread,
                           args=(payload, fallback, checkmount, onlyOnChange)))

    @property
    def running(self):
        """Is the payload thread running right now?"""
        return threadMgr.exists(THREAD_PAYLOAD_RESTART) or threadMgr.exists(
            THREAD_PAYLOAD)

    def _restart_thread(self, payload, fallback, checkmount, onlyOnChange):
        # Wait for the old thread to finish
        threadMgr.wait(THREAD_PAYLOAD)

        # Start a new payload thread
        threadMgr.add(
            AnacondaThread(name=THREAD_PAYLOAD,
                           target=self._run_thread,
                           args=(payload, fallback, checkmount, onlyOnChange)))

    def _set_state(self, event_id):
        # Update the current state
        log.debug("Updating payload thread state: %s", event_id.name)
        with self._event_lock:
            # Update the state within the lock to avoid a race with listeners
            # currently being added
            self._thread_state = event_id

            # Run any listeners for the new state
            for func in self._event_listeners[event_id]:
                func()

    def _run_thread(self, payload, fallback, checkmount, onlyOnChange):
        # This is the thread entry
        # Set the initial state
        self._error = None
        self._set_state(PayloadState.STARTED)

        # Wait for storage
        self._set_state(PayloadState.WAITING_STORAGE)
        threadMgr.wait(THREAD_STORAGE)

        # Wait for network
        self._set_state(PayloadState.WAITING_NETWORK)
        # FIXME: condition for cases where we don't want network
        # (set and use payload.needs_network ?)
        threadMgr.wait(THREAD_WAIT_FOR_CONNECTING_NM)

        # Wait for subscription
        threadMgr.wait(THREAD_SUBSCRIPTION)

        # Non-package payloads do everything in the setup method.
        # There is no UI support that could handle the error state,
        # so we need to handle or raise the error directly.
        try:
            payload.setup()
        except (DBusError, PayloadError) as e:
            # Handle an error.
            if errorHandler.cb(e) == ERROR_RAISE:
                raise

        # If this is a non-package Payload, we're done
        if payload.type != PAYLOAD_TYPE_DNF:
            self._set_state(PayloadState.FINISHED)
            return

        # Test if any repository changed from the last update
        if onlyOnChange:
            log.debug("Testing repositories availability")
            self._set_state(PayloadState.VERIFYING_AVAILABILITY)
            if payload.verify_available_repositories():
                log.debug(
                    "Payload isn't restarted, repositories are still available."
                )
                self._set_state(PayloadState.FINISHED)
                return

        # Keep setting up package-based repositories
        # Download package metadata
        self._set_state(PayloadState.DOWNLOADING_PKG_METADATA)
        try:
            payload.update_base_repo(fallback=fallback, checkmount=checkmount)
            payload.add_driver_repos()
        except (OSError, DBusError, PayloadError) as e:
            log.error("PayloadError: %s", e)
            self._error = self.ERROR_SETUP
            self._set_state(PayloadState.ERROR)
            payload.unsetup()
            return

        # Gather the group data
        self._set_state(PayloadState.DOWNLOADING_GROUP_METADATA)
        payload.gather_repo_metadata()

        # Check if that failed
        if not payload.base_repo:
            log.error("No base repo configured")
            self._error = self.ERROR_MD
            self._set_state(PayloadState.ERROR)
            payload.unsetup()
            return

        # run payload specific post configuration tasks
        payload.post_setup()

        self._set_state(PayloadState.FINISHED)
Beispiel #17
0
#example line:
#server 0.fedora.pool.ntp.org iburst
SRV_LINE_REGEXP = re.compile(
    r"^\s*(server|pool)\s*([-a-zA-Z.0-9]+)\s?([a-zA-Z0-9\s]*)$")
SRV_NOARG_OPTIONS = [
    "burst", "iburst", "nts", "prefer", "require", "trust", "noselect",
    "xleave"
]
SRV_ARG_OPTIONS = ["key", "minpoll", "maxpoll"]

#treat pools as four servers with the same name
SERVERS_PER_POOL = 4

# Description of an NTP server status.
NTP_SERVER_STATUS_DESCRIPTIONS = {
    NTP_SERVER_OK: N_("status: working"),
    NTP_SERVER_NOK: N_("status: not working"),
    NTP_SERVER_QUERY: N_("checking status")
}

log = get_module_logger(__name__)


class NTPconfigError(Exception):
    """Exception class for NTP related problems"""
    pass


def get_ntp_server_summary(server, states):
    """Generate a summary of an NTP server and its status.
Beispiel #18
0
 def __init__(self, rescue):
     super().__init__(data=None, storage=None, payload=None)
     self.title = N_("Rescue")
     self._container = None
     self._rescue = rescue
Beispiel #19
0
# NOTE: this should be LANG_TERRITORY.CODESET, e.g. en_US.UTF-8
DEFAULT_LANG = "en_US.UTF-8"

DEFAULT_VC_FONT = "eurlatgr"

DEFAULT_KEYBOARD = "us"

DRACUT_SHUTDOWN_EJECT = "/run/initramfs/usr/lib/dracut/hooks/shutdown/99anaconda-eject.sh"

# Help.
HELP_DIR = "/usr/share/anaconda/help"
HELP_MAIN_PAGE_GUI = "Installation_Guide.xml"
HELP_MAIN_PAGE_TUI = "Installation_Guide.txt"

# VNC questions
USEVNC = N_("Start VNC")
USETEXT = N_("Use text mode")

# Runlevel files
TEXT_ONLY_TARGET = 'multi-user.target'
GRAPHICAL_TARGET = 'graphical.target'

# Network
NETWORK_CONNECTION_TIMEOUT = 45  # in seconds
NETWORK_CONNECTED_CHECK_INTERVAL = 0.1  # in seconds

# DBus
DEFAULT_DBUS_TIMEOUT = -1       # use default

# Thread names
THREAD_EXECUTE_STORAGE = "AnaExecuteStorageThread"
Beispiel #20
0
 def __init__(self, rescue):
     super().__init__(data=None, storage=None, payload=None)
     self.title = N_("Rescue Shell")
     self._rescue = rescue
Beispiel #21
0
INSTALL_TREE = MOUNT_DIR + "/source"
BASE_REPO_NAME = "anaconda"
ANACONDA_BUS_ADDR_FILE = "/run/anaconda/bus.address"
ANACONDA_DATA_DIR = "/usr/share/anaconda"

# NOTE: this should be LANG_TERRITORY.CODESET, e.g. en_US.UTF-8
DEFAULT_LANG = "en_US.UTF-8"

DEFAULT_VC_FONT = "eurlatgr"

DEFAULT_KEYBOARD = "us"

DRACUT_SHUTDOWN_EJECT = "/run/initramfs/usr/lib/dracut/hooks/shutdown/99anaconda-eject.sh"

# VNC questions
USEVNC = N_("Start VNC")
USETEXT = N_("Use text mode")

# Runlevel files
TEXT_ONLY_TARGET = 'multi-user.target'
GRAPHICAL_TARGET = 'graphical.target'

# Network
NETWORK_CONNECTION_TIMEOUT = 45  # in seconds
NETWORK_CONNECTED_CHECK_INTERVAL = 0.1  # in seconds

# DBus
DEFAULT_DBUS_TIMEOUT = -1  # use default

# Thread names
THREAD_EXECUTE_STORAGE = "AnaExecuteStorageThread"
Beispiel #22
0
 def __init__(self, roots):
     super().__init__(data=None, storage=None, payload=None)
     self.title = N_("Root Selection")
     self._roots = roots
     self._selection = roots[0]
     self._container = None
Beispiel #23
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
Beispiel #24
0
class BootLoader(object):
    """A base class for boot loaders."""

    name = "Generic Bootloader"
    packages = []
    config_file = None
    config_file_mode = 0o600
    can_dual_boot = False
    keep_boot_order = False
    keep_mbr = False
    image_label_attr = "label"
    encryption_support = False
    stage2_is_valid_stage1 = False

    # requirements for stage2 devices
    stage2_device = None
    stage2_device_types = []
    stage2_raid_levels = []
    stage2_raid_metadata = []
    stage2_raid_member_types = []
    stage2_mountpoints = ["/boot", "/"]
    stage2_bootable = False
    stage2_must_be_primary = True
    stage2_description = N_("/boot file system")
    stage2_max_end = Size("2 TiB")

    @property
    def stage2_format_types(self):
        return ["ext4", "ext3", "ext2"]

    def __init__(self):
        super().__init__()
        self.boot_args = Arguments()
        self.dracut_args = Arguments()

        # the device the bootloader will be installed on
        self.stage1_device = None

        # the "boot disk", meaning the disk stage1 _will_ go on
        self.stage1_disk = None
        self.stage2_is_preferred_stage1 = False

        self.disks = []
        self._disk_order = []

        # timeout in seconds
        self._timeout = None
        self.password = None

        # console/serial stuff
        self.console = ""
        self.console_options = ""
        self._set_console()

        # list of BootLoaderImage instances representing bootable OSs
        self.linux_images = []
        self.chain_images = []

        # default image
        self._default_image = None
        self.skip_bootloader = False
        self.use_bls = True

        self.errors = []
        self.warnings = []

    def reset(self):
        """ Reset stage1 and stage2 values """
        self.stage1_device = None
        self.stage1_disk = None
        self.stage2_device = None
        self.stage2_is_preferred_stage1 = False
        self.disks = []

        self.errors = []
        self.warnings = []

    #
    # disk list access
    #
    @property
    def disk_order(self):
        """Potentially partial order for disks."""
        return self._disk_order

    @disk_order.setter
    def disk_order(self, order):
        log.debug("new disk order: %s", order)
        self._disk_order = order
        if self.disks:
            self._sort_disks()

    def _sort_disks(self):
        """Sort the internal disk list."""
        for name in reversed(self.disk_order):
            try:
                idx = [d.name for d in self.disks].index(name)
            except ValueError:
                log.error("bios order specified unknown disk %s", name)
                continue

            self.disks.insert(0, self.disks.pop(idx))

    def set_disk_list(self, disks):
        self.disks = disks[:]
        self._sort_disks()
        log.debug("new disk list: %s", self.disks)

    #
    # image list access
    #
    @property
    def default(self):
        """The default image."""
        if not self._default_image and self.linux_images:
            self._default_image = self.linux_images[0]

        return self._default_image

    @default.setter
    def default(self, image):
        if image not in self.images:
            raise ValueError("new default image not in image list")

        log.debug("new default image: %s", image)
        self._default_image = image

    @property
    def images(self):
        """ List of OS images that will be included in the configuration. """
        all_images = self.linux_images
        all_images.extend(i for i in self.chain_images if i.label)
        return all_images

    def clear_images(self):
        """Empty out the image list."""
        self.linux_images = []
        self.chain_images = []

    def add_image(self, image):
        """Add a BootLoaderImage instance to the image list."""
        if isinstance(image, LinuxBootLoaderImage):
            self.linux_images.append(image)
        else:
            self.chain_images.append(image)

    def image_label(self, image):
        """Return the appropriate image label for this bootloader."""
        return getattr(image, self.image_label_attr)

    #
    # platform-specific data access
    #
    @property
    def disklabel_types(self):
        return DiskLabel.get_platform_label_types()

    @property
    def device_descriptions(self):
        return platform.platform.boot_stage1_constraint_dict["descriptions"]

    #
    # constraint checking for target devices
    #
    def _is_valid_md(self,
                     device,
                     raid_levels=None,
                     metadata=None,
                     member_types=None,
                     desc=""):
        ret = True
        if device.type != "mdarray":
            return ret

        if raid_levels and device.level not in raid_levels:
            levels_str = ",".join("%s" % l for l in raid_levels)
            self.errors.append(
                _("RAID sets that contain '%(desc)s' must have one "
                  "of the following raid levels: %(raid_level)s.") % {
                      "desc": desc,
                      "raid_level": levels_str
                  })
            ret = False

        # new arrays will be created with an appropriate metadata format
        if device.exists and \
           metadata and device.metadata_version not in metadata:
            self.errors.append(
                _("RAID sets that contain '%(desc)s' must have one "
                  "of the following metadata versions: %(metadata_versions)s.")
                % {
                    "desc": desc,
                    "metadata_versions": ",".join(metadata)
                })
            ret = False

        if member_types:
            for member in device.members:
                if not self._device_type_match(member, member_types):
                    self.errors.append(
                        _("RAID sets that contain '%(desc)s' must "
                          "have one of the following device "
                          "types: %(types)s.") % {
                              "desc": desc,
                              "types": ",".join(member_types)
                          })
                    ret = False

        log.debug("_is_valid_md(%s) returning %s", device.name, ret)
        return ret

    def _is_valid_disklabel(self, device, disklabel_types=None):
        ret = True
        if self.disklabel_types:
            for disk in device.disks:
                label_type = getattr(disk.format, "label_type", None)
                if not label_type or label_type not in self.disklabel_types:
                    types_str = ",".join(disklabel_types)
                    self.errors.append(
                        _("%(name)s must have one of the following "
                          "disklabel types: %(types)s.") % {
                              "name": device.name,
                              "types": types_str
                          })
                    ret = False

        log.debug("_is_valid_disklabel(%s) returning %s", device.name, ret)
        return ret

    def _is_valid_format(self,
                         device,
                         format_types=None,
                         mountpoints=None,
                         desc=""):
        ret = True
        if format_types and device.format.type not in format_types:
            self.errors.append(
                _("%(desc)s cannot be of type %(type)s.") % {
                    "desc": desc,
                    "type": device.format.type
                })
            ret = False

        if mountpoints and hasattr(device.format, "mountpoint") \
           and device.format.mountpoint not in mountpoints:
            self.errors.append(
                _("%(desc)s must be mounted on one of %(mountpoints)s.") % {
                    "desc": desc,
                    "mountpoints": ", ".join(mountpoints)
                })
            ret = False

        log.debug("_is_valid_format(%s) returning %s", device.name, ret)
        return ret

    def _is_valid_size(self, device, desc=""):
        ret = True
        msg = None
        errors = []
        if device.format.min_size and device.format.max_size:
            msg = (
                _("%(desc)s must be between %(min)d and %(max)d MB in size") %
                {
                    "desc": desc,
                    "min": device.format.min_size,
                    "max": device.format.max_size
                })

        if device.format.min_size and device.size < device.format.min_size:
            if msg is None:
                errors.append(
                    _("%(desc)s must not be smaller than %(min)dMB.") % {
                        "desc": desc,
                        "min": device.format.min_size
                    })
            else:
                errors.append(msg)

            ret = False

        if device.format.max_size and device.size > device.format.max_size:
            if msg is None:
                errors.append(
                    _("%(desc)s must not be larger than %(max)dMB.") % {
                        "desc": desc,
                        "max": device.format.max_size
                    })
            elif msg not in errors:
                # don't add the same error string twice
                errors.append(msg)

            ret = False

        log.debug("_is_valid_size(%s) returning %s", device.name, ret)
        return ret

    def _is_valid_location(self, device, max_end=None, desc=""):
        ret = True
        if max_end and device.type == "partition" and device.parted_partition:
            end_sector = device.parted_partition.geometry.end
            sector_size = device.parted_partition.disk.device.sectorSize
            end = Size(sector_size * end_sector)
            if end > max_end:
                self.errors.append(
                    _("%(desc)s must be within the first %(max_end)s of "
                      "the disk.") % {
                          "desc": desc,
                          "max_end": max_end
                      })
                ret = False

        log.debug("_is_valid_location(%s) returning %s", device.name, ret)
        return ret

    def _is_valid_partition(self, device, primary=None, desc=""):
        ret = True
        if device.type == "partition" and primary and not device.is_primary:
            self.errors.append(_("%s must be on a primary partition.") % desc)
            ret = False

        log.debug("_is_valid_partition(%s) returning %s", device.name, ret)
        return ret

    #
    # target/stage1 device access
    #
    def _device_type_index(self, device, types):
        """ Return the index of the matching type in types to device's type.

            Return None if no match is found. """
        index = None
        try:
            index = types.index(device.type)
        except ValueError:
            if "disk" in types and device.is_disk:
                index = types.index("disk")

        return index

    def _device_type_match(self, device, types):
        """ Return True if device is of one of the types in the list types. """
        return self._device_type_index(device, types) is not None

    def device_description(self, device):
        device_types = list(self.device_descriptions.keys())
        idx = self._device_type_index(device, device_types)
        if idx is None:
            raise ValueError("No description available for %s" % device.type)

        # this looks unnecessarily complicated, but it handles the various
        # device types that we treat as disks
        return self.device_descriptions[device_types[idx]]

    def set_preferred_stage1_type(self, preferred):
        """ Set a preferred type of stage1 device. """
        if not self.stage2_is_valid_stage1:
            # "partition" means first sector of stage2 and is only meaningful
            # for bootloaders that can use stage2 as stage1
            return

        if preferred == "mbr":
            # "mbr" is already the default
            return

        # partition means "use the stage2 device for a stage1 device"
        self.stage2_is_preferred_stage1 = True

    def is_valid_stage1_device(self, device, early=False):
        """ Return True if the device is a valid stage1 target device.

            Also collect lists of errors and warnings.

            The criteria for being a valid stage1 target device vary from
            platform to platform. On some platforms a disk with an msdos
            disklabel is a valid stage1 target, while some platforms require
            a special device. Some examples of these special devices are EFI
            system partitions on EFI machines, PReP boot partitions on
            iSeries, and Apple bootstrap partitions on Mac.

            The 'early' keyword argument is a boolean flag indicating whether
            or not this check is being performed at a point where the mountpoint
            cannot be expected to be set for things like EFI system partitions.
        """
        self.errors = []
        self.warnings = []
        valid = True
        constraint = platform.platform.boot_stage1_constraint_dict

        if device is None:
            return False

        if not self._device_type_match(device, constraint["device_types"]):
            log.debug("stage1 device cannot be of type %s", device.type)
            return False

        if _is_on_sw_iscsi(device):
            if not _is_on_ibft(device):
                if conf.bootloader.nonibft_iscsi_boot:
                    log.debug("stage1 device on non-iBFT iSCSI disk allowed "
                              "by boot option inst.iscsi.nonibftboot")
                else:
                    log.debug(
                        "stage1 device cannot be on an non-iBFT iSCSI disk")
                    self.errors.append(
                        _("Boot loader stage1 device cannot be on "
                          "an iSCSI disk which is not configured in iBFT."))
                    return False

        description = self.device_description(device)

        if self.stage2_is_valid_stage1 and device == self.stage2_device:
            # special case
            valid = (self.stage2_is_preferred_stage1
                     and self.is_valid_stage2_device(device))

            # we'll be checking stage2 separately so don't duplicate messages
            self.warnings = []
            return valid

        if device.protected:
            valid = False

        if not self._is_valid_disklabel(device,
                                        disklabel_types=self.disklabel_types):
            valid = False

        if not self._is_valid_size(device, desc=description):
            valid = False

        if not self._is_valid_location(
                device, max_end=constraint["max_end"], desc=description):
            valid = False

        if not self._is_valid_md(device,
                                 raid_levels=constraint["raid_levels"],
                                 metadata=constraint["raid_metadata"],
                                 member_types=constraint["raid_member_types"],
                                 desc=description):
            valid = False

        if not self.stage2_bootable and not getattr(device, "bootable", True):
            log.warning("%s not bootable", device.name)

        # XXX does this need to be here?
        if getattr(device.format, "label", None) in ("ANACONDA", "LIVE"):
            log.info("ignoring anaconda boot disk")
            valid = False

        if early:
            mountpoints = []
        else:
            mountpoints = constraint["mountpoints"]

        if not self._is_valid_format(device,
                                     format_types=constraint["format_types"],
                                     mountpoints=mountpoints,
                                     desc=description):
            valid = False

        if not self.encryption_support and device.encrypted:
            self.errors.append(
                _("%s cannot be on an encrypted block "
                  "device.") % description)
            valid = False

        log.debug("is_valid_stage1_device(%s) returning %s", device.name,
                  valid)
        return valid

    def set_stage1_device(self, devices):
        self.stage1_device = None
        if not self.stage1_disk:
            self.reset()
            raise BootLoaderError("need stage1 disk to set stage1 device")

        if self.stage2_is_preferred_stage1:
            self.stage1_device = self.stage2_device
            return

        # Track the errors set by validity check in case no device would be found.
        errors = []
        for device in devices:
            if self.stage1_disk not in device.disks:
                continue

            if self.is_valid_stage1_device(device):
                if conf.target.is_image and device.is_disk:
                    # GRUB2 will install to /dev/loop0 but not to
                    # /dev/mapper/<image_name>
                    self.stage1_device = device.parents[0]
                else:
                    self.stage1_device = device

                break
            errors.extend(self.errors)

        if not self.stage1_device:
            self.reset()
            msg = "Failed to find a suitable stage1 device"
            if errors:
                msg = msg + ": " + "; ".join(errors)
            raise BootLoaderError(msg)

    #
    # boot/stage2 device access
    #

    def is_valid_stage2_device(self, device, linux=True, non_linux=False):
        """ Return True if the device is suitable as a stage2 target device.

            Also collect lists of errors and warnings.
        """
        self.errors = []
        self.warnings = []
        valid = True

        if device is None:
            return False

        if device.protected:
            valid = False

        if _is_on_sw_iscsi(device):
            if not _is_on_ibft(device):
                if conf.bootloader.nonibft_iscsi_boot:
                    log.info(
                        "%s on non-iBFT iSCSI disk allowed by boot option inst.nonibftiscsiboot",
                        self.stage2_description)
                else:
                    self.errors.append(
                        _("%(bootloader_stage2_description)s cannot be on "
                          "an iSCSI disk which is not configured in iBFT.") % {
                              "bootloader_stage2_description":
                              self.stage2_description
                          })
                    valid = False

        if not self._device_type_match(device, self.stage2_device_types):
            self.errors.append(
                _("%(desc)s cannot be of type %(type)s") % {
                    "desc": _(self.stage2_description),
                    "type": device.type
                })
            valid = False

        if not self._is_valid_disklabel(device,
                                        disklabel_types=self.disklabel_types):
            valid = False

        if not self._is_valid_size(device, desc=_(self.stage2_description)):
            valid = False

        if self.stage2_max_end and not self._is_valid_location(
                device,
                max_end=self.stage2_max_end,
                desc=_(self.stage2_description)):
            valid = False

        if not self._is_valid_partition(device,
                                        primary=self.stage2_must_be_primary):
            valid = False

        if not self._is_valid_md(device,
                                 raid_levels=self.stage2_raid_levels,
                                 metadata=self.stage2_raid_metadata,
                                 member_types=self.stage2_raid_member_types,
                                 desc=_(self.stage2_description)):
            valid = False

        if linux and \
           not self._is_valid_format(device,
                                     format_types=self.stage2_format_types,
                                     mountpoints=self.stage2_mountpoints,
                                     desc=_(self.stage2_description)):
            valid = False

        non_linux_format_types = platform.platform._non_linux_format_types
        if non_linux and \
           not self._is_valid_format(device,
                                     format_types=non_linux_format_types):
            valid = False

        if not self.encryption_support and device.encrypted:
            self.errors.append(
                _("%s cannot be on an encrypted block "
                  "device.") % _(self.stage2_description))
            valid = False

        log.debug("is_valid_stage2_device(%s) returning %s", device.name,
                  valid)
        return valid

    #
    # miscellaneous
    #

    def has_windows(self, devices):
        return False

    @property
    def timeout(self):
        """Bootloader timeout in seconds."""
        if self._timeout is not None:
            t = self._timeout
        else:
            t = 5

        return t

    def check(self):
        """ Run additional bootloader checks """
        return True

    @timeout.setter
    def timeout(self, seconds):
        self._timeout = seconds

    def set_boot_args(self, storage):
        """Set up the boot command line."""
        self._set_storage_boot_args(storage)
        self._preserve_some_boot_args()
        self._set_graphical_boot_args()

    def _set_storage_boot_args(self, storage):
        """Set the storage boot args."""
        fcoe_proxy = STORAGE.get_proxy(FCOE)
        iscsi_proxy = STORAGE.get_proxy(ISCSI)

        # FIPS
        boot_device = storage.mountpoints.get("/boot")
        if kernel_arguments.get("fips") == "1" and boot_device:
            self.boot_args.add("boot=%s" % self.stage2_device.fstab_spec)

        # Storage
        dracut_devices = [storage.root_device]
        if self.stage2_device != storage.root_device:
            dracut_devices.append(self.stage2_device)

        swap_devices = storage.fsset.swap_devices
        dracut_devices.extend(swap_devices)

        # Add resume= option to enable hibernation on x86.
        # Choose the largest swap device for that.
        if blivet.arch.is_x86() and swap_devices:
            resume_device = max(swap_devices, key=lambda x: x.size)
            self.boot_args.add("resume=%s" % resume_device.fstab_spec)

        # Does /usr have its own device? If so, we need to tell dracut
        usr_device = storage.mountpoints.get("/usr")
        if usr_device:
            dracut_devices.extend([usr_device])

        netdevs = [d for d in storage.devices \
                   if (getattr(d, "complete", True) and
                       isinstance(d, NetworkStorageDevice))]

        rootdev = storage.root_device
        if any(rootdev.depends_on(netdev) for netdev in netdevs):
            dracut_devices = set(dracut_devices)
            # By this time this thread should be the only one running, and also
            # mountpoints is a property function that returns a new dict every
            # time, so iterating over the values is safe.
            for dev in storage.mountpoints.values():
                if any(dev.depends_on(netdev) for netdev in netdevs):
                    dracut_devices.add(dev)

        done = []
        for device in dracut_devices:
            for dep in storage.devices:
                if dep in done:
                    continue

                if device != dep and not device.depends_on(dep):
                    continue

                if isinstance(dep, blivet.devices.FcoeDiskDevice):
                    setup_args = fcoe_proxy.GetDracutArguments(dep.nic)
                elif isinstance(dep, blivet.devices.iScsiDiskDevice):
                    # (partial) offload devices do not need setup in dracut
                    if not dep.offload:
                        node = _get_iscsi_node_from_device(dep)
                        setup_args = iscsi_proxy.GetDracutArguments(
                            Node.to_structure(node))
                else:
                    setup_args = dep.dracut_setup_args()

                if not setup_args:
                    continue

                self.boot_args.update(setup_args)
                self.dracut_args.update(setup_args)
                done.append(dep)

                # network configuration arguments
                if isinstance(dep, NetworkStorageDevice):
                    network_proxy = NETWORK.get_proxy()
                    network_args = []
                    ibft = False
                    nic = ""
                    if isinstance(dep, blivet.devices.iScsiDiskDevice):
                        if dep.iface == "default" or ":" in dep.iface:
                            node = _get_iscsi_node_from_device(dep)
                            if iscsi_proxy.IsNodeFromIbft(
                                    Node.to_structure(node)):
                                ibft = True
                            else:
                                nic = iface_for_host_ip(dep.host_address)
                        else:
                            nic = iscsi_proxy.GetInterface(dep.iface)
                    else:
                        nic = dep.nic
                    if nic or ibft:
                        network_args = network_proxy.GetDracutArguments(
                            nic, dep.host_address, "", ibft)

                    self.boot_args.update(network_args)
                    self.dracut_args.update(network_args)

        # This is needed for FCoE, bug #743784. The case:
        # We discover LUN on an iface which is part of multipath setup.
        # If the iface is disconnected after discovery anaconda doesn't
        # write dracut ifname argument for the disconnected iface path
        # (in NETWORK.GetDracutArguments).
        # Dracut needs the explicit ifname= because biosdevname
        # fails to rename the iface (because of BFS booting from it).
        for nic in fcoe_proxy.GetNics():
            hwaddr = get_interface_hw_address(nic)
            if hwaddr:
                self.boot_args.add("ifname=%s:%s" % (nic, hwaddr.lower()))

        # Add rd.iscsi.firmware to trigger dracut running iscsistart
        # See rhbz#1099603 and rhbz#1185792
        if len(glob("/sys/firmware/iscsi_boot*")) > 0:
            self.boot_args.add("rd.iscsi.firmware")

    def _preserve_some_boot_args(self):
        """Preserve some of the boot args."""
        for opt in conf.bootloader.preserved_arguments:
            if opt not in kernel_arguments:
                continue

            arg = kernel_arguments.get(opt)
            new_arg = opt
            if arg:
                new_arg += "=%s" % arg

            self.boot_args.add(new_arg)

    def _set_graphical_boot_args(self):
        """Set up the graphical boot."""
        args = []

        try:
            import rpm
        except ImportError:
            pass
        else:
            util.resetRpmDb()
            ts = rpm.TransactionSet(conf.target.system_root)

            # Only add "rhgb quiet" on non-s390, non-serial installs.
            if util.isConsoleOnVirtualTerminal() \
                    and (ts.dbMatch('provides', 'rhgb').count()
                         or ts.dbMatch('provides', 'plymouth').count()):

                args = ["rhgb", "quiet"]

        self.boot_args.update(args)
        self.dracut_args.update(args)

    #
    # configuration
    #

    @property
    def boot_prefix(self):
        """ Prefix, if any, to paths in /boot. """
        if self.stage2_device.format.mountpoint == "/":
            prefix = "/boot"
        else:
            prefix = ""

        return prefix

    def _set_console(self):
        """ Set console options based on boot arguments. """
        console = kernel_arguments.get("console", "")
        console = os.path.basename(console)
        self.console, _x, self.console_options = console.partition(",")

    def write_config_console(self, config):
        """Write console-related configuration lines."""
        pass

    def write_config_password(self, config):
        """Write password-related configuration lines."""
        pass

    def write_config_header(self, config):
        """Write global configuration lines."""
        self.write_config_console(config)
        self.write_config_password(config)

    def write_config_images(self, config):
        """Write image configuration entries."""
        raise NotImplementedError()

    def write_config_post(self):
        pass

    def write_config(self):
        """ Write the bootloader configuration. """
        if not self.config_file:
            raise BootLoaderError(
                "no config file defined for this boot loader")

        config_path = os.path.normpath(conf.target.system_root +
                                       self.config_file)
        if os.access(config_path, os.R_OK):
            os.rename(config_path, config_path + ".anacbak")

        config = util.open_with_perm(config_path, "w", self.config_file_mode)
        self.write_config_header(config)
        self.write_config_images(config)
        config.close()
        self.write_config_post()

    #
    # installation
    #
    def write(self):
        """ Write the bootloader configuration and install the bootloader. """
        if self.skip_bootloader:
            return

        self.write_config()
        os.sync()
        self.stage2_device.format.sync(root=conf.target.physical_root)
        self.install()

    def install(self, args=None):
        raise NotImplementedError()
Beispiel #25
0
from pyanaconda.core.i18n import N_, _
from pyanaconda.core.regexes import IPV4_PATTERN_WITH_ANCHORS, IPV4_NETMASK_WITH_ANCHORS, IPV4_OR_DHCP_PATTERN_WITH_ANCHORS
from pyanaconda.core.constants import ANACONDA_ENVIRON
from pyanaconda.anaconda_loggers import get_module_logger

from simpleline.render.containers import ListColumnContainer
from simpleline.render.prompt import Prompt
from simpleline.render.screen import InputState
from simpleline.render.screen_handler import ScreenHandler
from simpleline.render.widgets import TextWidget, CheckboxWidget, EntryWidget

log = get_module_logger(__name__)

# This will be used in decorators in ConfigureDeviceSpoke.
# The decorators are processed before the class is created so you can have this as a variable there.
IP_ERROR_MSG = N_("Bad format of the IP address")
NETMASK_ERROR_MSG = N_("Bad format of the netmask")

__all__ = ["NetworkSpoke"]


# TODO: use our own datastore?
class WiredTUIConfigurationData():
    """Holds tui input configuration data of wired device."""
    def __init__(self):
        self.ip = "dhcp"
        self.netmask = ""
        self.gateway = ""
        self.ipv6 = "auto"
        self.ipv6gateway = ""
        self.nameserver = ""
 def __init__(self, ksdata, storage, payload, instclass):
     self.initialize_start()
     StandaloneTUISpoke.__init__(self, ksdata, storage, payload, instclass)
     self.title = N_("Progress")
     self._stepped = False
     self.initialize_done()
Beispiel #27
0
class Platform(object):
    """Platform

       A class containing platform-specific information and methods for use
       during installation.  The intent is to eventually encapsulate all the
       architecture quirks in one place to avoid lots of platform checks
       throughout anaconda."""
    _packages = []

    # requirements for bootloader stage1 devices
    _boot_stage1_device_types = []
    _boot_stage1_format_types = []
    _boot_stage1_mountpoints = []
    _boot_stage1_max_end = None
    _boot_stage1_raid_levels = []
    _boot_stage1_raid_metadata = []
    _boot_stage1_raid_member_types = []
    _boot_stage1_description = N_("boot loader device")
    _boot_stage1_missing_error = ""
    _boot_raid_description = N_("RAID Device")
    _boot_partition_description = N_("First sector of boot partition")
    _boot_descriptions = {}

    _non_linux_format_types = []

    def __init__(self):
        """Creates a new Platform object.  This is basically an abstract class.
           You should instead use one of the platform-specific classes as
           returned by get_platform below.  Not all subclasses need to provide
           all the methods in this class."""

        self.update_from_flags()

    def update_from_flags(self):
        if conf.storage.gpt:
            disklabel_class = get_device_format_class("disklabel")
            disklabel_types = disklabel_class.get_platform_label_types()
            if "gpt" not in disklabel_types:
                log.warning(
                    "GPT is not a supported disklabel on this platform. Using default "
                    "disklabel %s instead.", disklabel_types[0])
            else:
                disklabel_class.set_default_label_type("gpt")

    def __call__(self):
        return self

    @property
    def boot_stage1_constraint_dict(self):
        d = {
            "device_types":
            self._boot_stage1_device_types,
            "format_types":
            self._boot_stage1_format_types,
            "mountpoints":
            self._boot_stage1_mountpoints,
            "max_end":
            self._boot_stage1_max_end,
            "raid_levels":
            self._boot_stage1_raid_levels,
            "raid_metadata":
            self._boot_stage1_raid_metadata,
            "raid_member_types":
            self._boot_stage1_raid_member_types,
            "descriptions":
            dict((k, _(v)) for k, v in self._boot_descriptions.items())
        }
        return d

    @property
    def packages(self):
        _packages = self._packages
        return _packages

    def set_platform_bootloader_reqs(self):
        """Return the required platform-specific bootloader partition
           information.  These are typically partitions that do not get mounted,
           like biosboot or prepboot, but may also include the /boot/efi
           partition."""
        return []

    def set_platform_boot_partition(self):
        """Return the default /boot partition for this platform."""
        return [PartSpec(mountpoint="/boot", size=Size("1GiB"))]

    def set_default_partitioning(self):
        """Return the default platform-specific partitioning information."""
        return self.set_platform_bootloader_reqs(
        ) + self.set_platform_boot_partition()

    @property
    def stage1_missing_error(self):
        """A platform-specific error message to be shown if stage1 target
           selection fails."""
        return self._boot_stage1_missing_error
Beispiel #28
0
    CLEAR_PARTITIONS_LIST, CLEAR_PARTITIONS_LINUX, CLEAR_PARTITIONS_DEFAULT, BOOTLOADER_DISABLED, \
    BOOTLOADER_ENABLED, BOOTLOADER_SKIPPED, ISCSI_INTERFACE_UNSET, ISCSI_INTERFACE_DEFAULT,\
    ISCSI_INTERFACE_IFACENAME
from pyanaconda.core.i18n import N_


INCONSISTENT_SECTOR_SIZES_SUGGESTIONS = N_(
    "Workarounds for manual installations:\n"
    "* Select only the disks with the same sector size during manual "
    "installation in graphical or text mode.\n"
    "* When disks with inconsistent sector size are selected for "
    "the installation, restrict each created LVM Volume Group to use "
    "Physical Volumes with the same sector size. This can only be "
    "done in graphical mode in the Custom partitioning spoke.\n"
    "\n"
    "Workarounds for kickstart installations:\n"
    "* Restrict what disks are used for the partitioning by specifying "
    "'ignoredisk --drives=..' or 'ignoredisk --only-use=..'.\n"
    "* Specify what disks should be used for each created LVM Physical "
    "Volume: 'partition pv.1 --ondisk=..'.\n"
    "\n"
    "General workarounds:\n"
    "* Plain partitioning scheme can be used instead of LVM.\n"
    "* Some drives support re-configuration of sector sizes, for example "
    "by running 'hdparm --set-sector-size=<SIZE> <DEVICE>'.\n"
)


@unique
class BootloaderMode(Enum):
    """The bootloader mode."""
    DISABLED = BOOTLOADER_DISABLED
Beispiel #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))
    os_config.append(Task("Configure SELinux", ksdata.selinux.execute))
    os_config.append(
        Task("Configure first boot tasks", ksdata.firstboot.execute))
    os_config.append(Task("Configure services", ksdata.services.execute))
    os_config.append(Task("Configure keyboard", ksdata.keyboard.execute))
    os_config.append(Task("Configure timezone", ksdata.timezone.execute))
    os_config.append(Task("Configure language", ksdata.lang.execute))
    os_config.append(Task("Configure firewall", ksdata.firewall.execute))
    os_config.append(Task("Configure X", ksdata.xconfig.execute))
    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.
    u = Users()
    user_config = TaskQueue("User creation", N_("Creating users"))
    user_config.append(
        Task("Configure root", ksdata.rootpw.execute, (storage, ksdata, u)))
    user_config.append(
        Task("Configure user groups", ksdata.group.execute,
             (storage, ksdata, u)))
    user_config.append(
        Task("Configure user", ksdata.user.execute, (storage, ksdata, u)))
    user_config.append(
        Task("Configure SSH key", ksdata.sshkey.execute, (storage, ksdata, u)))
    configuration_queue.append(user_config)

    # Anaconda addon configuration
    addon_config = TaskQueue("Anaconda addon configuration",
                             N_("Configuring addons"))
    addon_config.append(
        Task("Configure Anaconda addons", ksdata.addons.execute,
             (storage, ksdata, u, 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, )))

    # Write out the user interaction config file.
    #
    # But make sure it's not written out in the image and directory installation mode,
    # as that might result in spokes being inadvertently hidden when the actual installation
    # starts from the generate image or directory contents.
    if conf.target.is_image:
        log.info(
            "Not writing out user interaction config file due to image install mode."
        )
    elif conf.target.is_directory:
        log.info(
            "Not writing out user interaction config file due to directory install mode."
        )
    else:
        write_configs.append(
            Task("Store user interaction config",
                 screen_access.sam.write_out_config_file))

    # 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()
Beispiel #30
0
 def __init__(self, data, storage, payload):
     super().__init__(data, storage, payload)
     self.title = N_("Shell")