SystemSetupModel handles 'prefill' data

- Init method changed to accept that data, which could be None.
- If valid, user Identity and Locale are prepopulated.
- Server parses the YAML and send valid info (or None) to the Model.
This commit is contained in:
Carlos Nihelton 2021-10-26 15:27:19 -03:00
parent 41a2a554ef
commit 168a5c13a0
2 changed files with 33 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import functools
import logging
from subiquity.models.subiquity import SubiquityModel
from subiquity.common.types import IdentityData
from subiquity.models.locale import LocaleModel
from subiquity.models.identity import IdentityModel
from subiquity.server.types import InstallerChannels
@ -47,7 +48,7 @@ class SystemSetupModel(SubiquityModel):
target = '/'
def __init__(self, root, hub, install_model_names,
postinstall_model_names):
postinstall_model_names, prefillInfo):
# Parent class init is not called to not load models we don't need.
self.root = root
if root != '/':
@ -61,6 +62,24 @@ class SystemSetupModel(SubiquityModel):
self.wslconfbase = WSLConfigurationBaseModel()
self.wslconfadvanced = WSLConfigurationAdvancedModel()
if prefillInfo:
welcome = prefillInfo.get('Welcome',{'lang': None})
if welcome != None and welcome.get('lang') is not None:
self.locale.selected_language = welcome['lang']
log.debug('Prefill Language: {}'
.format(self.locale.selected_language))
identity = prefillInfo.get('WSLIdentity', None)
if identity:
idata = IdentityData()
idata.realname = identity.get('realname', '')
idata.username = identity.get('username', '')
idata.hostname = ''
idata.crypted_password = ''
self.identity.add_user(idata)
log.debug('Prefill Identity: {}'.format(self.identity.user))
self._confirmation = asyncio.Event()
self._confirmation_task = None

View File

@ -18,8 +18,11 @@ from subiquity.server.server import SubiquityServer
from system_setup.models.system_setup import SystemSetupModel
from subiquity.models.subiquity import ModelNames
import logging
import yaml
import os
log = logging.getLogger('system_setup.server.server')
INSTALL_MODEL_NAMES = ModelNames({
"locale",
@ -63,10 +66,19 @@ class SystemSetupServer(SubiquityServer):
def make_model(self):
root = '/'
prefillInfo = None
if self.opts.dry_run:
root = os.path.abspath('.subiquity')
if self.opts.prefill:
with open(self.opts.prefill, 'r') as stream:
try:
prefillInfo = yaml.safe_load(stream)
except yaml.YAMLError as exc:
log.error('Exception while parsing prefill file: {}.'
' Ignoring file.'.format(exc))
prefillInfo = None
return SystemSetupModel(root, self.hub, INSTALL_MODEL_NAMES,
POSTINSTALL_MODEL_NAMES)
POSTINSTALL_MODEL_NAMES, prefillInfo)
# We dont have cloudinit in system_setup.
async def wait_for_cloudinit(self):