subiquity/system_setup/models/system_server.py

108 lines
3.1 KiB
Python
Raw Normal View History

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
import logging
from subiquity.models.subiquity import SubiquityModel
2021-08-12 14:31:27 +00:00
from subiquitycore.utils import is_wsl
2021-07-02 08:26:21 +00:00
from subiquity.models.locale import LocaleModel
from subiquity.models.identity import IdentityModel
from .wslconf1 import WSLConfiguration1Model
2021-07-13 06:15:09 +00:00
from .wslconf2 import WSLConfiguration2Model
2021-07-02 08:26:21 +00:00
log = logging.getLogger('system_setup.models.system_server')
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-08-06 17:14:26 +00:00
# Models that will be used in WSL system setup
ALL_MODEL_NAMES = [
"locale",
2021-08-13 15:05:38 +00:00
"identity",
2021-08-06 17:14:26 +00:00
"wslconf1",
]
def __init__(self, root, reconfigure=False):
if reconfigure:
self.ALL_MODEL_NAMES = [
"locale",
"wslconf2",
]
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
self.is_wsl = is_wsl()
self.debconf_selections = None
self.filesystem = None
self.kernel = None
self.keyboard = None
self.mirror = None
self.network = None
self.proxy = None
self.snaplist = None
self.ssh = None
self.updates = None
self.packages = []
self.userdata = {}
self.locale = LocaleModel()
self.identity = IdentityModel()
self.wslconf1 = WSLConfiguration1Model()
2021-07-13 06:15:09 +00:00
self.wslconf2 = WSLConfiguration2Model()
2021-07-02 08:26:21 +00:00
self.confirmation = asyncio.Event()
self._events = {
2021-08-06 17:14:26 +00:00
name: asyncio.Event() for name in self.ALL_MODEL_NAMES
}
2021-08-13 15:05:38 +00:00
self.install_events = {
2021-08-06 17:14:26 +00:00
self._events[name] for name in self.ALL_MODEL_NAMES
}
2021-07-02 08:26:21 +00:00
def configured(self, model_name):
2021-08-12 14:31:27 +00:00
# We need to override the parent class as
# *_MODEL_NAMES are global variables in server.py
2021-08-06 17:14:26 +00:00
if model_name not in self.ALL_MODEL_NAMES:
2021-07-02 08:26:21 +00:00
return
self._events[model_name].set()
2021-08-06 17:14:26 +00:00
stage = 'install'
2021-07-02 08:26:21 +00:00
unconfigured = {
2021-08-06 17:14:26 +00:00
mn for mn in self.ALL_MODEL_NAMES
2021-07-02 08:26:21 +00:00
if not self._events[mn].is_set()
2021-08-06 17:14:26 +00:00
}
2021-07-02 08:26:21 +00:00
log.debug(
"model %s for %s is configured, to go %s",
model_name, stage, unconfigured)