From d717375d9c9e6ffcf2a15c694c622ea87873ed7d Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 31 Mar 2020 15:58:18 +1300 Subject: [PATCH] apply network autoinstall config --- subiquity/controllers/network.py | 34 ++++++++++++++++++++++++++++ subiquitycore/controllers/network.py | 5 +++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/subiquity/controllers/network.py b/subiquity/controllers/network.py index 49ff04bb..b8a05c67 100644 --- a/subiquity/controllers/network.py +++ b/subiquity/controllers/network.py @@ -13,6 +13,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import asyncio + +from subiquitycore.async_helpers import schedule_task from subiquitycore.controllers.network import NetworkController from subiquity.controller import SubiquityController @@ -20,8 +23,39 @@ from subiquity.controller import SubiquityController class NetworkController(NetworkController, SubiquityController): + ai_data = None autoinstall_key = "network" + def load_autoinstall_data(self, data): + self.ai_data = data + + def start(self): + if self.ai_data is not None: + self.apply_config() + elif not self.interactive(): + self.initial_delay = schedule_task(self.delay()) + super().start() + + async def delay(self): + await asyncio.sleep(10) + + async def apply_autoinstall_config(self): + if self.ai_data is None: + await self.initial_delay + self.update_initial_configs() + self.apply_config() + await self.apply_config_task.wait() + + def render_config(self): + if self.ai_data is not None: + r = self.ai_data + if self.interactive(): + # If we're interactive, we want later renders to + # incorporate any changes from the UI. + self.ai_data = None + return r + return super().render_config() + def done(self): self.configured() super().done() diff --git a/subiquitycore/controllers/network.py b/subiquitycore/controllers/network.py index 55fab1f6..dad74208 100644 --- a/subiquitycore/controllers/network.py +++ b/subiquitycore/controllers/network.py @@ -330,8 +330,11 @@ class NetworkController(BaseController): except subprocess.CalledProcessError as cp: log.info("deleting %s failed with %r", dev.name, cp.stderr) + def render_config(self): + return self.model.render() + def _write_config(self): - config = self.model.render() + config = self.render_config() log.debug("network config: \n%s", yaml.dump(sanitize_config(config), default_flow_style=False))