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
|
2021-08-31 10:54:15 +00:00
|
|
|
from subiquity.common.types import WSLConfigurationAdvanced
|
2021-07-13 06:15:09 +00:00
|
|
|
from subiquity.server.controller import SubiquityController
|
|
|
|
|
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
|
|
|
|
2021-08-31 11:26:49 +00:00
|
|
|
log = logging.getLogger(
|
2021-09-27 12:36:25 +00:00
|
|
|
'system_setup.server.controllers.wsl_configuration_advanced')
|
2021-08-31 11:26:49 +00:00
|
|
|
|
2021-07-13 06:15:09 +00:00
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
class WSLConfigurationAdvancedController(SubiquityController):
|
2021-07-13 06:15:09 +00:00
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
endpoint = API.wslconfadvanced
|
2021-07-13 06:15:09 +00:00
|
|
|
|
2021-08-31 10:54:15 +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'},
|
2021-10-04 10:55:25 +00:00
|
|
|
'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
|
2021-10-05 01:38:10 +00:00
|
|
|
data = default_loader(is_advanced=True)
|
2021-09-28 16:37:26 +00:00
|
|
|
|
2021-07-22 16:49:12 +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()}
|
|
|
|
reconf_data = WSLConfigurationAdvanced(**proc_data)
|
2021-09-28 12:48:30 +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:
|
2021-10-05 01:38:10 +00:00
|
|
|
reconf_data = WSLConfigurationAdvanced(**data)
|
2021-09-28 12:48:30 +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):
|
2021-08-31 10:54:15 +00:00
|
|
|
r = attr.asdict(self.model.wslconfadvanced)
|
2021-07-13 06:15:09 +00:00
|
|
|
return r
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
async def GET(self) -> WSLConfigurationAdvanced:
|
|
|
|
data = WSLConfigurationAdvanced()
|
|
|
|
if self.model.wslconfadvanced is not None:
|
2021-10-04 10:55:25 +00:00
|
|
|
data.interop_enabled = \
|
|
|
|
self.model.wslconfadvanced.interop_enabled
|
2021-08-12 14:31:27 +00:00
|
|
|
data.interop_appendwindowspath = \
|
2021-08-31 10:54:15 +00:00
|
|
|
self.model.wslconfadvanced.interop_appendwindowspath
|
2021-10-04 10:55:25 +00:00
|
|
|
data.gui_theme = \
|
|
|
|
self.model.wslconfadvanced.gui_theme
|
2021-08-31 11:26:49 +00:00
|
|
|
data.gui_followwintheme = \
|
|
|
|
self.model.wslconfadvanced.gui_followwintheme
|
2021-10-04 10:55:25 +00:00
|
|
|
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
|
|
|
|
|
2021-08-31 10:54:15 +00:00
|
|
|
async def POST(self, data: WSLConfigurationAdvanced):
|
2021-09-28 12:48:30 +00:00
|
|
|
self.model.apply_settings(data)
|
2021-09-28 12:50:34 +00:00
|
|
|
await self.configured()
|