subiquity/system_setup/server/controllers/wslconfadvanced.py

135 lines
5.5 KiB
Python
Raw Normal View History

2021-07-13 06:15:09 +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 subiquitycore.context import with_context
from subiquity.common.apidef import API
from subiquity.common.types import WSLConfigurationAdvanced
2021-07-13 06:15:09 +00:00
from subiquity.server.controller import SubiquityController
from system_setup.common.wsl_conf import default_loader
2021-08-31 11:26:49 +00:00
log = logging.getLogger(
'system_setup.server.controllers.wsl_configuration_advanced')
2021-08-31 11:26:49 +00:00
2021-07-13 06:15:09 +00:00
class WSLConfigurationAdvancedController(SubiquityController):
2021-07-13 06:15:09 +00:00
endpoint = API.wslconfadvanced
2021-07-13 06:15:09 +00:00
autoinstall_key = model_name = "wslconfadvanced"
2021-07-13 06:15:09 +00:00
autoinstall_schema = {
'type': 'object',
'properties': {
'interop_enabled': {'type': 'boolean'},
'interop_appendwindowspath': {'type': 'boolean'},
'gui_theme': {'type': 'string'},
'gui_followwintheme': {'type': 'boolean'},
'interop_guiintegration': {'type': 'boolean'},
'interop_audiointegration': {'type': 'boolean'},
'interop_advancedipdetection': {'type': 'boolean'},
'motd_wslnewsenabled': {'type': 'boolean'},
'automount_enabled': {'type': 'boolean'},
'automount_mountfstab': {'type': 'boolean'}
2021-07-22 16:49:12 +00:00
},
2021-07-13 06:15:09 +00:00
'additionalProperties': False,
2021-07-22 16:49:12 +00:00
}
def __init__(self, app):
super().__init__(app)
# load the config file
data = default_loader(True)
2021-07-22 16:49:12 +00:00
if data:
2021-08-12 14:31:27 +00:00
def bool_converter(x):
return x.lower() == 'true'
reconf_data = WSLConfigurationAdvanced(
2021-08-12 14:31:27 +00:00
interop_enabled=bool_converter(data['interop_enabled']),
interop_appendwindowspath=bool_converter(
data['interop_appendwindowspath']),
2021-07-22 16:49:12 +00:00
gui_theme=data['gui_theme'],
2021-08-12 14:31:27 +00:00
gui_followwintheme=bool_converter(data['gui_followwintheme']),
interop_guiintegration=bool_converter(
data['interop_guiintegration']),
interop_audiointegration=bool_converter(
data['interop_audiointegration']),
interop_advancedipdetection=bool_converter(
data['interop_advancedipdetection']),
motd_wslnewsenabled=bool_converter(
data['motd_wslnewsenabled']),
automount_enabled=bool_converter(data['automount_enabled']),
automount_mountfstab=bool_converter(
data['automount_mountfstab']),
2021-07-22 16:49:12 +00:00
)
self.model.apply_settings(reconf_data)
2021-07-13 06:15:09 +00:00
def load_autoinstall_data(self, data):
if data is not None:
reconf_data = WSLConfigurationAdvanced(
2021-07-13 06:15:09 +00:00
interop_enabled=data['interop_enabled'],
interop_appendwindowspath=data['interop_appendwindowspath'],
gui_theme=data['gui_theme'],
gui_followwintheme=data['gui_followwintheme'],
interop_guiintegration=data['interop_guiintegration'],
interop_audiointegration=data['interop_audiointegration'],
interop_advancedipdetection=data[
'interop_advancedipdetection'],
motd_wslnewsenabled=data['motd_wslnewsenabled'],
automount_enabled=data['automount_enabled'],
automount_mountfstab=data['automount_mountfstab']
2021-07-13 06:15:09 +00:00
)
self.model.apply_settings(reconf_data)
2021-07-13 06:15:09 +00:00
@with_context()
async def apply_autoinstall_config(self, context=None):
pass
def make_autoinstall(self):
r = attr.asdict(self.model.wslconfadvanced)
2021-07-13 06:15:09 +00:00
return r
async def GET(self) -> WSLConfigurationAdvanced:
data = WSLConfigurationAdvanced()
if self.model.wslconfadvanced is not None:
data.interop_enabled = \
self.model.wslconfadvanced.interop_enabled
2021-08-12 14:31:27 +00:00
data.interop_appendwindowspath = \
self.model.wslconfadvanced.interop_appendwindowspath
data.gui_theme = \
self.model.wslconfadvanced.gui_theme
2021-08-31 11:26:49 +00:00
data.gui_followwintheme = \
self.model.wslconfadvanced.gui_followwintheme
data.interop_guiintegration = \
self.model.wslconfadvanced.interop_guiintegration
data.interop_audiointegration = \
self.model.wslconfadvanced.interop_audiointegration
data.interop_advancedipdetection = \
self.model.wslconfadvanced.interop_advancedipdetection
data.motd_wslnewsenabled = \
self.model.wslconfadvanced.motd_wslnewsenabled
data.automount_enabled = \
self.model.wslconfadvanced.automount_enabled
data.automount_mountfstab = \
self.model.wslconfadvanced.automount_mountfstab
2021-07-13 06:15:09 +00:00
return data
async def POST(self, data: WSLConfigurationAdvanced):
self.model.apply_settings(data)
await self.configured()