Merge pull request #629 from mwhudson/autoinstall-write-config
write autoinstall config at end of install
This commit is contained in:
commit
04e1034ae3
|
@ -74,6 +74,9 @@ class SubiquityController(BaseController):
|
|||
def deserialize(self, state):
|
||||
self.configured()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return {}
|
||||
|
||||
|
||||
class NoUIController(SubiquityController):
|
||||
|
||||
|
@ -101,3 +104,6 @@ class RepeatedController(RepeatedController):
|
|||
|
||||
def interactive(self):
|
||||
return self.orig.interactive()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return {}
|
||||
|
|
|
@ -695,3 +695,13 @@ class FilesystemController(SubiquityController):
|
|||
fstype="ext4",
|
||||
mount="/",
|
||||
))
|
||||
|
||||
def make_autoinstall(self):
|
||||
rendered = self.model.render()
|
||||
r = {
|
||||
'config': rendered['storage']['config']
|
||||
}
|
||||
for k in 'swap', 'grub':
|
||||
if k in rendered:
|
||||
r[k] = rendered[k]
|
||||
return r
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
import logging
|
||||
|
||||
import attr
|
||||
|
||||
from subiquity.controller import SubiquityController
|
||||
from subiquity.ui.views import IdentityView
|
||||
|
||||
|
@ -57,3 +59,8 @@ class IdentityController(SubiquityController):
|
|||
self.model.add_user(user_spec)
|
||||
self.configured()
|
||||
self.app.next_screen()
|
||||
|
||||
def make_autoinstall(self):
|
||||
r = attr.asdict(self.model.user)
|
||||
r['hostname'] = self.model.hostname
|
||||
return r
|
||||
|
|
|
@ -29,6 +29,7 @@ from curtin.commands.install import (
|
|||
ERROR_TARFILE,
|
||||
INSTALL_LOG,
|
||||
)
|
||||
from curtin.util import write_file
|
||||
|
||||
from systemd import journal
|
||||
|
||||
|
@ -323,6 +324,11 @@ class InstallProgressController(SubiquityController):
|
|||
@install_step(
|
||||
"final system configuration", level="INFO", childlevel="DEBUG")
|
||||
async def postinstall(self, context):
|
||||
autoinstall_path = os.path.join(
|
||||
self.app.root, 'var/log/installer/autoinstall-user-data')
|
||||
autoinstall_config = "#cloud-config\n" + yaml.dump(
|
||||
{"autoinstall": self.app.make_autoinstall()})
|
||||
write_file(autoinstall_path, autoinstall_config, mode=0o600)
|
||||
await self.configure_cloud_init(context)
|
||||
if self.model.ssh.install_server:
|
||||
await self.install_openssh(context)
|
||||
|
@ -401,17 +407,19 @@ class InstallProgressController(SubiquityController):
|
|||
|
||||
@install_step("copying logs to installed system")
|
||||
async def copy_logs_to_target(self, context):
|
||||
if self.opts.dry_run:
|
||||
if 'copy-logs-fail' in self.app.debug_flags:
|
||||
raise PermissionError()
|
||||
return
|
||||
if self.opts.dry_run and 'copy-logs-fail' in self.app.debug_flags:
|
||||
raise PermissionError()
|
||||
target_logs = self.tpath('var/log/installer')
|
||||
await arun_command(['cp', '-aT', '/var/log/installer', target_logs])
|
||||
if self.opts.dry_run:
|
||||
os.makedirs(target_logs, exist_ok=True)
|
||||
else:
|
||||
await arun_command(
|
||||
['cp', '-aT', '/var/log/installer', target_logs])
|
||||
journal_txt = os.path.join(target_logs, 'installer-journal.txt')
|
||||
try:
|
||||
with open(os.path.join(target_logs,
|
||||
'installer-journal.txt'), 'w') as output:
|
||||
with open(journal_txt, 'w') as output:
|
||||
await arun_command(
|
||||
['journalctl'],
|
||||
['journalctl', '-b'],
|
||||
stdout=output, stderr=subprocess.STDOUT)
|
||||
except Exception:
|
||||
log.exception("saving journal failed")
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
import logging
|
||||
|
||||
import attr
|
||||
|
||||
from subiquitycore.async_helpers import schedule_task
|
||||
|
||||
from subiquity.controller import SubiquityController
|
||||
|
@ -68,3 +70,6 @@ class KeyboardController(SubiquityController):
|
|||
|
||||
def cancel(self):
|
||||
self.app.prev_screen()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return attr.asdict(self.model.setting)
|
||||
|
|
|
@ -133,3 +133,8 @@ class MirrorController(SubiquityController):
|
|||
self.model.set_mirror(mirror)
|
||||
self.configured()
|
||||
self.app.next_screen()
|
||||
|
||||
def make_autoinstall(self):
|
||||
r = self.model.render()['apt']
|
||||
r['geoip'] = self.geoip_enabled
|
||||
return r
|
||||
|
|
|
@ -25,3 +25,6 @@ class NetworkController(NetworkController, SubiquityController):
|
|||
def done(self):
|
||||
self.configured()
|
||||
super().done()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return self.model.render()['network']
|
||||
|
|
|
@ -64,3 +64,6 @@ class ProxyController(SubiquityController):
|
|||
self.signal.emit_signal('network-proxy-set')
|
||||
self.configured()
|
||||
self.app.next_screen()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return self.model.proxy
|
||||
|
|
|
@ -126,3 +126,10 @@ class SSHController(SubiquityController):
|
|||
self.model.ssh_import_id = result.get('ssh_import_id', None)
|
||||
self.configured()
|
||||
self.app.next_screen()
|
||||
|
||||
def make_autoinstall(self):
|
||||
return {
|
||||
'install-server': self.model.install_server,
|
||||
'authorized-keys': self.model.authorized_keys,
|
||||
'allow-pw': self.model.pwauth,
|
||||
}
|
||||
|
|
|
@ -64,3 +64,6 @@ class WelcomeController(SubiquityController):
|
|||
def deserialize(self, data):
|
||||
super().deserialize(data)
|
||||
self.model.switch_language(data)
|
||||
|
||||
def make_autoinstall(self):
|
||||
return self.model.selected_language
|
||||
|
|
|
@ -308,3 +308,11 @@ class Subiquity(Application):
|
|||
return
|
||||
self.ui.body.show_stretchy_overlay(
|
||||
ErrorReportStretchy(self, self.ui.body, report))
|
||||
|
||||
def make_autoinstall(self):
|
||||
config = {}
|
||||
for controller in self.controllers.instances:
|
||||
controller_conf = controller.make_autoinstall()
|
||||
if controller_conf:
|
||||
config[controller.autoinstall_key] = controller_conf
|
||||
return config
|
||||
|
|
Loading…
Reference in New Issue