diff --git a/subiquity/controllers/__init__.py b/subiquity/controllers/__init__.py index 5ca8c12e..8ad7030c 100644 --- a/subiquity/controllers/__init__.py +++ b/subiquity/controllers/__init__.py @@ -29,6 +29,7 @@ from ..controller import RepeatedController from .reporting import ReportingController from .snaplist import SnapListController from .ssh import SSHController +from .userdata import UserdataController from .welcome import WelcomeController from .zdev import ZdevController __all__ = [ @@ -49,6 +50,7 @@ __all__ = [ 'ReportingController', 'SnapListController', 'SSHController', + 'UserdataController', 'WelcomeController', 'ZdevController', ] diff --git a/subiquity/controllers/userdata.py b/subiquity/controllers/userdata.py new file mode 100644 index 00000000..b781508a --- /dev/null +++ b/subiquity/controllers/userdata.py @@ -0,0 +1,33 @@ +# Copyright 2020 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 . + +from subiquity.controller import NoUIController + + +class UserdataController(NoUIController): + + model_name = 'userdata' + autoinstall_key = "user-data" + autoinstall_default = {} + autoinstall_schema = { + 'type': 'object', + } + + def load_autoinstall_data(self, data): + self.model.clear() + self.model.update(data) + + def make_autoinstall(self): + return self.app.base_model.userdata diff --git a/subiquity/core.py b/subiquity/core.py index d38586bc..ddbdbede 100644 --- a/subiquity/core.py +++ b/subiquity/core.py @@ -99,6 +99,7 @@ class Subiquity(Application): "Early", "Reporting", "Error", + "Userdata", "Package", "Debconf", "Welcome", diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index 3c52e113..edbd023f 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import asyncio +import copy from collections import OrderedDict import logging import os @@ -79,6 +80,7 @@ POSTINSTALL_MODEL_NAMES = [ "packages", "snaplist", "ssh", + "userdata", ] ALL_MODEL_NAMES = INSTALL_MODEL_NAMES + POSTINSTALL_MODEL_NAMES @@ -114,6 +116,7 @@ class SubiquityModel: self.proxy = ProxyModel() self.snaplist = SnapListModel() self.ssh = SSHModel() + self.userdata = {} self._events = { name: asyncio.Event() for name in ALL_MODEL_NAMES @@ -184,7 +187,9 @@ class SubiquityModel: config['snap'] = { 'commands': cmds, } - return config + userdata = copy.deepcopy(self.userdata) + merge_config(userdata, config) + return userdata def _cloud_init_files(self): # TODO, this should be moved to the in-target cloud-config seed so on