2021-07-02 08:26:21 +00:00
|
|
|
# Copyright 2015 Canonical, Ltd.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import asyncio
|
2021-09-03 01:57:58 +00:00
|
|
|
import functools
|
2021-07-02 08:26:21 +00:00
|
|
|
import logging
|
|
|
|
|
2021-09-01 09:02:25 +00:00
|
|
|
from subiquity.models.subiquity import SubiquityModel
|
2021-07-02 08:26:21 +00:00
|
|
|
from subiquity.models.locale import LocaleModel
|
|
|
|
from subiquity.models.identity import IdentityModel
|
2021-09-03 01:57:58 +00:00
|
|
|
from subiquity.server.types import InstallerChannels
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
from .wslconfbase import WSLConfigurationBaseModel
|
|
|
|
from .wslconfadvanced import WSLConfigurationAdvancedModel
|
2021-07-02 08:26:21 +00:00
|
|
|
|
|
|
|
|
2022-02-25 10:31:06 +00:00
|
|
|
log = logging.getLogger('system_setup.models.system_setup')
|
2021-07-02 08:26:21 +00:00
|
|
|
|
|
|
|
HOSTS_CONTENT = """\
|
|
|
|
127.0.0.1 localhost
|
|
|
|
127.0.1.1 {hostname}
|
|
|
|
|
|
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
|
|
::1 ip6-localhost ip6-loopback
|
|
|
|
fe00::0 ip6-localnet
|
|
|
|
ff00::0 ip6-mcastprefix
|
|
|
|
ff02::1 ip6-allnodes
|
|
|
|
ff02::2 ip6-allrouters
|
|
|
|
"""
|
|
|
|
|
2021-08-12 14:31:27 +00:00
|
|
|
|
2021-07-02 08:26:21 +00:00
|
|
|
class SystemSetupModel(SubiquityModel):
|
|
|
|
"""The overall model for subiquity."""
|
|
|
|
|
|
|
|
target = '/'
|
|
|
|
|
2021-09-03 01:57:58 +00:00
|
|
|
def __init__(self, root, hub, install_model_names,
|
|
|
|
postinstall_model_names):
|
2021-07-02 08:26:21 +00:00
|
|
|
# Parent class init is not called to not load models we don't need.
|
|
|
|
self.root = root
|
2021-09-01 08:50:56 +00:00
|
|
|
if root != '/':
|
|
|
|
self.target = root
|
2021-09-29 22:54:36 +00:00
|
|
|
self.chroot_prefix = []
|
2021-07-02 08:26:21 +00:00
|
|
|
|
|
|
|
self.packages = []
|
|
|
|
self.userdata = {}
|
2021-09-29 22:54:36 +00:00
|
|
|
self.locale = LocaleModel(self.chroot_prefix)
|
2021-07-02 08:26:21 +00:00
|
|
|
self.identity = IdentityModel()
|
2022-05-24 16:58:13 +00:00
|
|
|
self.network = None
|
2021-08-31 10:54:15 +00:00
|
|
|
self.wslconfbase = WSLConfigurationBaseModel()
|
|
|
|
self.wslconfadvanced = WSLConfigurationAdvancedModel()
|
2021-07-02 08:26:21 +00:00
|
|
|
|
2021-08-25 02:56:07 +00:00
|
|
|
self._confirmation = asyncio.Event()
|
|
|
|
self._confirmation_task = None
|
2021-07-02 08:26:21 +00:00
|
|
|
|
2021-08-17 09:50:29 +00:00
|
|
|
self._configured_names = set()
|
2021-09-01 08:50:56 +00:00
|
|
|
self._install_model_names = install_model_names
|
|
|
|
self._postinstall_model_names = postinstall_model_names
|
|
|
|
self._cur_install_model_names = install_model_names.default_names
|
|
|
|
self._cur_postinstall_model_names = \
|
|
|
|
postinstall_model_names.default_names
|
2021-08-25 02:56:07 +00:00
|
|
|
self._install_event = asyncio.Event()
|
|
|
|
self._postinstall_event = asyncio.Event()
|
2021-09-03 01:57:58 +00:00
|
|
|
all_names = set()
|
|
|
|
all_names.update(install_model_names.all())
|
|
|
|
all_names.update(postinstall_model_names.all())
|
|
|
|
for name in all_names:
|
|
|
|
hub.subscribe(
|
|
|
|
(InstallerChannels.CONFIGURED, name),
|
|
|
|
functools.partial(self._configured, name))
|