2021-07-02 08:26:21 +00:00
|
|
|
|
# Copyright 2021 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/>.
|
|
|
|
|
|
2021-10-26 18:27:19 +00:00
|
|
|
|
import logging
|
2021-08-31 10:03:01 +00:00
|
|
|
|
import os
|
2023-07-25 21:26:25 +00:00
|
|
|
|
|
2021-10-26 18:27:19 +00:00
|
|
|
|
import yaml
|
2022-06-06 19:59:14 +00:00
|
|
|
|
from aiohttp import web
|
|
|
|
|
|
2021-09-27 12:36:25 +00:00
|
|
|
|
from subiquity.models.subiquity import ModelNames
|
2021-08-31 10:03:01 +00:00
|
|
|
|
from subiquity.server.server import SubiquityServer
|
2021-09-27 12:36:25 +00:00
|
|
|
|
from system_setup.common.wsl_utils import is_reconfigure
|
2021-09-01 08:50:56 +00:00
|
|
|
|
from system_setup.models.system_setup import SystemSetupModel
|
|
|
|
|
|
2021-10-26 18:27:19 +00:00
|
|
|
|
log = logging.getLogger("system_setup.server.server")
|
2021-08-19 15:42:06 +00:00
|
|
|
|
|
2021-09-01 08:50:56 +00:00
|
|
|
|
INSTALL_MODEL_NAMES = ModelNames(
|
|
|
|
|
{
|
|
|
|
|
"locale",
|
|
|
|
|
},
|
|
|
|
|
wsl_setup={
|
|
|
|
|
"identity",
|
|
|
|
|
},
|
|
|
|
|
wsl_configuration={
|
2022-12-16 11:56:36 +00:00
|
|
|
|
"wslconfbase",
|
2021-09-01 08:50:56 +00:00
|
|
|
|
"wslconfadvanced",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2021-09-03 07:39:32 +00:00
|
|
|
|
POSTINSTALL_MODEL_NAMES = ModelNames(set())
|
2021-09-01 08:50:56 +00:00
|
|
|
|
|
2022-06-06 20:57:00 +00:00
|
|
|
|
LOCALHOST_ADDR = "127.0.0.1"
|
|
|
|
|
|
2021-09-01 08:50:56 +00:00
|
|
|
|
|
2021-08-31 10:03:01 +00:00
|
|
|
|
class SystemSetupServer(SubiquityServer):
|
2021-10-29 15:43:25 +00:00
|
|
|
|
prefillInfo = None
|
2021-08-19 15:42:06 +00:00
|
|
|
|
|
2021-07-02 08:26:21 +00:00
|
|
|
|
from system_setup.server import controllers as controllers_mod
|
2023-07-25 21:26:25 +00:00
|
|
|
|
|
2021-07-02 08:26:21 +00:00
|
|
|
|
controllers = [
|
2021-09-08 15:54:34 +00:00
|
|
|
|
"Early",
|
2021-07-02 08:26:21 +00:00
|
|
|
|
"Reporting",
|
|
|
|
|
"Error",
|
2021-10-29 15:43:25 +00:00
|
|
|
|
"WSLLocale",
|
2022-08-19 18:38:39 +00:00
|
|
|
|
"WSLSetupOptions",
|
2021-09-08 15:44:50 +00:00
|
|
|
|
"WSLIdentity",
|
2021-08-31 10:54:15 +00:00
|
|
|
|
"WSLConfigurationBase",
|
|
|
|
|
"WSLConfigurationAdvanced",
|
2021-08-31 10:07:20 +00:00
|
|
|
|
"Configure",
|
|
|
|
|
"Late",
|
2021-08-31 13:43:35 +00:00
|
|
|
|
"SetupShutdown",
|
2021-07-22 16:49:12 +00:00
|
|
|
|
]
|
|
|
|
|
|
2021-09-01 08:44:37 +00:00
|
|
|
|
supported_variants = ["wsl_setup", "wsl_configuration"]
|
|
|
|
|
|
2021-09-20 06:37:55 +00:00
|
|
|
|
def __init__(self, opts, block_log_dir):
|
|
|
|
|
super().__init__(opts, block_log_dir)
|
2021-10-04 20:09:24 +00:00
|
|
|
|
self.event_syslog_id = ""
|
|
|
|
|
self.log_syslog_id = ""
|
2022-04-21 11:51:06 +00:00
|
|
|
|
self.echo_syslog_id = ""
|
2021-09-20 06:37:55 +00:00
|
|
|
|
if is_reconfigure(opts.dry_run):
|
|
|
|
|
self.set_source_variant("wsl_configuration")
|
2021-10-29 15:43:25 +00:00
|
|
|
|
if self.opts.prefill:
|
|
|
|
|
with open(self.opts.prefill, "r") as stream:
|
|
|
|
|
try:
|
|
|
|
|
# Shared with controllers thru self.app.
|
|
|
|
|
self.prefillInfo = yaml.safe_load(stream)
|
|
|
|
|
except yaml.YAMLError as exc:
|
|
|
|
|
log.error(
|
|
|
|
|
"Exception while parsing prefill file: {}."
|
|
|
|
|
" Ignoring file.".format(self.opts.prefill)
|
2023-07-25 21:26:25 +00:00
|
|
|
|
)
|
2021-10-29 15:43:25 +00:00
|
|
|
|
log.error(exc)
|
|
|
|
|
self.prefillInfo = None
|
2021-09-20 06:37:55 +00:00
|
|
|
|
|
2021-07-02 08:26:21 +00:00
|
|
|
|
def make_model(self):
|
|
|
|
|
root = "/"
|
|
|
|
|
if self.opts.dry_run:
|
2022-01-25 21:10:40 +00:00
|
|
|
|
root = os.path.abspath(self.opts.output_base)
|
2021-11-11 12:22:10 +00:00
|
|
|
|
model = SystemSetupModel(
|
|
|
|
|
root, self.hub, INSTALL_MODEL_NAMES, POSTINSTALL_MODEL_NAMES
|
|
|
|
|
)
|
|
|
|
|
model.set_source_variant(self.variant)
|
|
|
|
|
return model
|
2021-09-20 17:30:36 +00:00
|
|
|
|
|
|
|
|
|
# We don’t have cloudinit in system_setup.
|
|
|
|
|
async def wait_for_cloudinit(self):
|
|
|
|
|
self.cloud_init_ok = True
|
|
|
|
|
return
|
2022-06-06 19:59:14 +00:00
|
|
|
|
|
|
|
|
|
async def start_site(self, runner: web.AppRunner):
|
|
|
|
|
port = self.opts.tcp_port
|
|
|
|
|
if port is None:
|
|
|
|
|
return await super().start_site(runner)
|
|
|
|
|
|
2022-06-07 16:27:15 +00:00
|
|
|
|
# Subiquity runs with root privileges, that's why we don't want
|
|
|
|
|
# outsiders to connect to it. Only localhost loopback is allowed.
|
2022-06-06 19:59:14 +00:00
|
|
|
|
site = web.TCPSite(runner, host=LOCALHOST_ADDR, port=port)
|
|
|
|
|
await site.start()
|