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/>.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import attr
|
|
|
|
|
|
|
|
from subiquity.common.apidef import API
|
2021-08-31 10:54:15 +00:00
|
|
|
from subiquity.common.types import WSLConfigurationBase
|
2021-07-02 08:26:21 +00:00
|
|
|
from subiquity.server.controller import SubiquityController
|
|
|
|
from subiquitycore.context import with_context
|
2021-09-30 16:00:32 +00:00
|
|
|
from system_setup.common.wsl_conf import default_loader
|
2021-10-05 01:38:10 +00:00
|
|
|
from system_setup.common.wsl_utils import convert_if_bool
|
2021-09-27 12:36:25 +00:00
|
|
|
|
2022-02-25 10:31:06 +00:00
|
|
|
log = logging.getLogger("system_setup.server.controllers.wslconfbase")
|
2021-07-02 08:26:21 +00:00
|
|
|
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
class WSLConfigurationBaseController(SubiquityController):
|
|
|
|
endpoint = API.wslconfbase
|
2021-07-02 08:26:21 +00:00
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
autoinstall_key = model_name = "wslconfbase"
|
2021-07-02 08:26:21 +00:00
|
|
|
autoinstall_schema = {
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
2021-10-04 10:55:25 +00:00
|
|
|
"automount_root": {"type": "string"},
|
|
|
|
"automount_options": {"type": "string"},
|
|
|
|
"network_generatehosts": {"type": "boolean"},
|
|
|
|
"network_generateresolvconf": {"type": "boolean"},
|
2021-07-02 08:26:21 +00:00
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:36:25 +00:00
|
|
|
def __init__(self, app):
|
|
|
|
super().__init__(app)
|
|
|
|
|
|
|
|
# load the config file
|
2022-09-15 19:08:35 +00:00
|
|
|
root_dir = self.app.base_model.root
|
|
|
|
data = default_loader(root_dir)
|
2021-09-28 16:37:26 +00:00
|
|
|
|
2021-09-27 12:36:25 +00:00
|
|
|
if data:
|
2021-10-05 01:38:10 +00:00
|
|
|
proc_data = {key: convert_if_bool(value) for (key, value) in data.items()}
|
|
|
|
conf_data = WSLConfigurationBase(**proc_data)
|
2021-09-28 12:48:30 +00:00
|
|
|
self.model.apply_settings(conf_data)
|
2021-09-27 12:36:25 +00:00
|
|
|
|
2021-07-02 08:26:21 +00:00
|
|
|
def load_autoinstall_data(self, data):
|
|
|
|
if data is not None:
|
2021-10-05 01:38:10 +00:00
|
|
|
identity_data = WSLConfigurationBase(**data)
|
2021-09-28 12:48:30 +00:00
|
|
|
self.model.apply_settings(identity_data)
|
2021-07-02 08:26:21 +00:00
|
|
|
|
|
|
|
@with_context()
|
|
|
|
async def apply_autoinstall_config(self, context=None):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def make_autoinstall(self):
|
2021-08-31 10:54:15 +00:00
|
|
|
r = attr.asdict(self.model.wslconfbase)
|
2021-07-02 08:26:21 +00:00
|
|
|
return r
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
async def GET(self) -> WSLConfigurationBase:
|
|
|
|
data = WSLConfigurationBase()
|
|
|
|
if self.model.wslconfbase is not None:
|
2021-10-04 10:55:25 +00:00
|
|
|
data.automount_root = self.model.wslconfbase.automount_root
|
|
|
|
data.automount_options = self.model.wslconfbase.automount_options
|
|
|
|
data.network_generatehosts = self.model.wslconfbase.network_generatehosts
|
|
|
|
data.network_generateresolvconf = (
|
|
|
|
self.model.wslconfbase.network_generateresolvconf
|
2023-07-25 21:26:25 +00:00
|
|
|
)
|
2021-07-02 08:26:21 +00:00
|
|
|
return data
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
async def POST(self, data: WSLConfigurationBase):
|
2021-09-28 12:48:30 +00:00
|
|
|
self.model.apply_settings(data)
|
2021-09-28 12:50:34 +00:00
|
|
|
await self.configured()
|