|
| 1 | +import logging |
| 2 | + |
| 3 | +from pyanaconda.core.constants import SETUP_ON_BOOT_RECONFIG, SETUP_ON_BOOT_DEFAULT |
| 4 | +from pyanaconda.core.dbus import DBus |
| 5 | +from pyanaconda.installation_tasks import TaskQueue, DBusTask |
| 6 | +from pyanaconda.modules.common.constants.services import SERVICES, TIMEZONE, LOCALIZATION, NETWORK, USERS, BOSS |
| 7 | +from pyanaconda.modules.common.task import Task, sync_run_task |
| 8 | +from pyanaconda.core.i18n import _ |
| 9 | + |
| 10 | +log = logging.getLogger("initial-setup") |
| 11 | + |
| 12 | + |
| 13 | +class InitialSetupTask(Task): |
| 14 | + def __init__(self, |
| 15 | + groups_already_configured=False, |
| 16 | + users_already_configured=False, |
| 17 | + root_password_already_configured=False): |
| 18 | + super().__init__() |
| 19 | + self._total_steps = 0 |
| 20 | + self._groups_already_configured = groups_already_configured |
| 21 | + self._users_already_configured = users_already_configured |
| 22 | + self._root_password_already_configured = root_password_already_configured |
| 23 | + |
| 24 | + @property |
| 25 | + def name(self): |
| 26 | + """Name of the task""" |
| 27 | + return "Run the initial setup queue." |
| 28 | + |
| 29 | + @property |
| 30 | + def steps(self): |
| 31 | + """Total number of steps.""" |
| 32 | + return self._total_steps |
| 33 | + |
| 34 | + def _queue_started_cb(self, task): |
| 35 | + """The installation queue was started.""" |
| 36 | + self.report_progress(task.status_message) |
| 37 | + |
| 38 | + def _task_completed_cb(self, task): |
| 39 | + """The installation task was completed.""" |
| 40 | + self.report_progress("", step_size=1) |
| 41 | + |
| 42 | + def _task_started_cb(self, task): |
| 43 | + """The installation task was completed.""" |
| 44 | + self.report_progress(task.name) |
| 45 | + |
| 46 | + def _progress_report_cb(self, step, message): |
| 47 | + """Handle a progress report of a task.""" |
| 48 | + self.report_progress(message) |
| 49 | + |
| 50 | + def run(self): |
| 51 | + """Run the task.""" |
| 52 | + log.info("applying changes") |
| 53 | + |
| 54 | + queue = TaskQueue("Initial Setup") |
| 55 | + |
| 56 | + # connect progress reporting |
| 57 | + queue.queue_started.connect(self._queue_started_cb) |
| 58 | + queue.task_completed.connect(self._task_completed_cb) |
| 59 | + queue.task_started.connect(self._task_started_cb) |
| 60 | + |
| 61 | + services_proxy = SERVICES.get_proxy() |
| 62 | + reconfig_mode = services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG |
| 63 | + |
| 64 | + # data.selinux |
| 65 | + # data.firewall |
| 66 | + |
| 67 | + # Configure the timezone. |
| 68 | + timezone_proxy = TIMEZONE.get_proxy() |
| 69 | + for task_path in timezone_proxy.InstallWithTasks(): |
| 70 | + task_proxy = TIMEZONE.get_proxy(task_path) |
| 71 | + queue.append(DBusTask(task_proxy)) |
| 72 | + |
| 73 | + # Configure the localization. |
| 74 | + localization_proxy = LOCALIZATION.get_proxy() |
| 75 | + for task_path in localization_proxy.InstallWithTasks(): |
| 76 | + task_proxy = LOCALIZATION.get_proxy(task_path) |
| 77 | + queue.append(DBusTask(task_proxy)) |
| 78 | + |
| 79 | + # Configure persistent hostname |
| 80 | + network_proxy = NETWORK.get_proxy() |
| 81 | + network_task = network_proxy.ConfigureHostnameWithTask(True) |
| 82 | + task_proxy = NETWORK.get_proxy(network_task) |
| 83 | + queue.append(DBusTask(task_proxy)) |
| 84 | + # Set current hostname |
| 85 | + network_proxy.SetCurrentHostname(network_proxy.Hostname) |
| 86 | + |
| 87 | + # Configure groups, users & root account |
| 88 | + # |
| 89 | + # NOTE: We only configure groups, users & root account if the respective |
| 90 | + # kickstart commands are *not* seen in the input kickstart. |
| 91 | + # This basically means that we will configure only what was |
| 92 | + # set in the Initial Setup UI and will not attempt to configure |
| 93 | + # anything that looks like it was configured previously in |
| 94 | + # the Anaconda UI or installation kickstart. |
| 95 | + users_proxy = USERS.get_proxy() |
| 96 | + |
| 97 | + if self._groups_already_configured and not reconfig_mode: |
| 98 | + log.debug("skipping user group configuration - already configured") |
| 99 | + elif users_proxy.Groups: # only run of there are some groups to create |
| 100 | + groups_task = users_proxy.ConfigureGroupsWithTask() |
| 101 | + task_proxy = USERS.get_proxy(groups_task) |
| 102 | + log.debug("configuring user groups via %s task", task_proxy.Name) |
| 103 | + queue.append(DBusTask(task_proxy)) |
| 104 | + |
| 105 | + if self._users_already_configured and not reconfig_mode: |
| 106 | + log.debug("skipping user configuration - already configured") |
| 107 | + elif users_proxy.Users: # only run if there are some users to create |
| 108 | + users_task = users_proxy.ConfigureUsersWithTask() |
| 109 | + task_proxy = USERS.get_proxy(users_task) |
| 110 | + log.debug("configuring users via %s task", task_proxy.Name) |
| 111 | + queue.append(DBusTask(task_proxy)) |
| 112 | + |
| 113 | + if self._root_password_already_configured and not reconfig_mode: |
| 114 | + log.debug("skipping root password configuration - already configured") |
| 115 | + else: |
| 116 | + root_task = users_proxy.SetRootPasswordWithTask() |
| 117 | + task_proxy = USERS.get_proxy(root_task) |
| 118 | + log.debug("configuring root password via %s task", task_proxy.Name) |
| 119 | + queue.append(DBusTask(task_proxy)) |
| 120 | + |
| 121 | + # Configure all addons |
| 122 | + log.info("executing addons") |
| 123 | + boss_proxy = BOSS.get_proxy() |
| 124 | + for service_name, object_path in boss_proxy.CollectInstallSystemTasks(): |
| 125 | + task_proxy = DBus.get_proxy(service_name, object_path) |
| 126 | + queue.append(DBusTask(task_proxy)) |
| 127 | + |
| 128 | + for item in queue.nested_items: |
| 129 | + if isinstance(item, DBusTask): |
| 130 | + item._progress_cb = self._progress_report_cb |
| 131 | + |
| 132 | + self._total_steps = queue.task_count |
| 133 | + |
| 134 | + # log contents of the main task queue |
| 135 | + log.info(queue.summary) |
| 136 | + |
| 137 | + # start the task queue |
| 138 | + queue.start() |
| 139 | + |
| 140 | + # done |
| 141 | + self.report_progress(_("Complete!"), step_number=self.steps) |
| 142 | + |
| 143 | + if self.external_reconfig: |
| 144 | + # prevent the reconfig flag from being written out |
| 145 | + # to kickstart if neither /etc/reconfigSys or /.unconfigured |
| 146 | + # are present |
| 147 | + services_proxy = SERVICES.get_proxy() |
| 148 | + services_proxy.SetupOnBoot = SETUP_ON_BOOT_DEFAULT |
0 commit comments