make_cloudconfig - start moving cloud config generation to models (#975)
Add make_cloudconfig as a function that models should offer that allows for generation of the cloud-config snippet. Move snaplist and locale to this mechanism. Add a test for snaplist output.
This commit is contained in:
parent
2a6b5d1a48
commit
21058464fd
|
@ -191,7 +191,9 @@ classes live in `subiquity.models`. An instance of each model class is
|
||||||
attached as an attribute to the `SubiquityModel` class and the name of the
|
attached as an attribute to the `SubiquityModel` class and the name of the
|
||||||
attribute added to `INSTALL_MODEL_NAMES` or `POSTINSTALL_MODEL_NAMES` as
|
attribute added to `INSTALL_MODEL_NAMES` or `POSTINSTALL_MODEL_NAMES` as
|
||||||
appropriate. Models that go into `INSTALL_MODEL_NAMES` need to define a
|
appropriate. Models that go into `INSTALL_MODEL_NAMES` need to define a
|
||||||
render() method that returns a fragment of curtin config.
|
render() method that returns a fragment of curtin config. POSTINSTALL models
|
||||||
|
that contribute to cloud-config should define a make_cloudconfig() method that
|
||||||
|
returns a cloud config fragment.
|
||||||
|
|
||||||
#### Defining the API
|
#### Defining the API
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,9 @@ identity:
|
||||||
username: ubuntu
|
username: ubuntu
|
||||||
password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'
|
password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'
|
||||||
hostname: ubuntu
|
hostname: ubuntu
|
||||||
|
snaps:
|
||||||
|
- name: etcd
|
||||||
|
channel: 3.2/stable
|
||||||
updates: all
|
updates: all
|
||||||
storage:
|
storage:
|
||||||
config:
|
config:
|
||||||
|
|
|
@ -21,6 +21,7 @@ clean () {
|
||||||
rm -f .subiquity/subiquity-*.log
|
rm -f .subiquity/subiquity-*.log
|
||||||
rm -f "$testschema"
|
rm -f "$testschema"
|
||||||
rm -rf .subiquity/run/
|
rm -rf .subiquity/run/
|
||||||
|
rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
tty=$(tty) || tty=/dev/console
|
tty=$(tty) || tty=/dev/console
|
||||||
|
@ -53,7 +54,8 @@ python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \
|
||||||
python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \
|
python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \
|
||||||
storage.config[-1].options='"errors=remount-ro"'
|
storage.config[-1].options='"errors=remount-ro"'
|
||||||
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \
|
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \
|
||||||
locale='"en_GB.UTF-8"'
|
locale='"en_GB.UTF-8"' \
|
||||||
|
'snap.commands=[snap install --channel=3.2/stable etcd]'
|
||||||
grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \
|
grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \
|
||||||
.subiquity/subiquity-server-debug.log
|
.subiquity/subiquity-server-debug.log
|
||||||
grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \
|
grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \
|
||||||
|
|
|
@ -31,3 +31,11 @@ class LocaleModel(object):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Selected: {}>".format(self.selected_language)
|
return "<Selected: {}>".format(self.selected_language)
|
||||||
|
|
||||||
|
def make_cloudconfig(self):
|
||||||
|
if not self.selected_language:
|
||||||
|
return {}
|
||||||
|
locale = self.selected_language
|
||||||
|
if '.' not in locale and '_' in locale:
|
||||||
|
locale += '.UTF-8'
|
||||||
|
return {'locale': locale}
|
||||||
|
|
|
@ -93,3 +93,15 @@ class SnapListModel:
|
||||||
for selection in selections:
|
for selection in selections:
|
||||||
self._snap_for_name(selection.name)
|
self._snap_for_name(selection.name)
|
||||||
self.selections = selections
|
self.selections = selections
|
||||||
|
|
||||||
|
def make_cloudconfig(self):
|
||||||
|
if not self.selections:
|
||||||
|
return {}
|
||||||
|
cmds = []
|
||||||
|
for selection in self.selections:
|
||||||
|
cmd = ['snap', 'install', '--channel=' + selection.channel]
|
||||||
|
if selection.is_classic:
|
||||||
|
cmd.append('--classic')
|
||||||
|
cmd.append(selection.name)
|
||||||
|
cmds.append(' '.join(cmd))
|
||||||
|
return {'snap': {'commands': cmds}}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger("subiquity.models.ssh")
|
log = logging.getLogger("subiquity.models.ssh")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -175,14 +175,10 @@ class SubiquityModel:
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
def _cloud_init_config(self):
|
def _cloud_init_config(self):
|
||||||
locale = self.locale.selected_language
|
|
||||||
if '.' not in locale and '_' in locale:
|
|
||||||
locale += '.UTF-8'
|
|
||||||
config = {
|
config = {
|
||||||
'growpart': {
|
'growpart': {
|
||||||
'mode': 'off',
|
'mode': 'off',
|
||||||
},
|
},
|
||||||
'locale': locale,
|
|
||||||
'resize_rootfs': False,
|
'resize_rootfs': False,
|
||||||
}
|
}
|
||||||
if self.identity.hostname is not None:
|
if self.identity.hostname is not None:
|
||||||
|
@ -215,17 +211,10 @@ class SubiquityModel:
|
||||||
config['ssh_authorized_keys'] = self.ssh.authorized_keys
|
config['ssh_authorized_keys'] = self.ssh.authorized_keys
|
||||||
if self.ssh.install_server:
|
if self.ssh.install_server:
|
||||||
config['ssh_pwauth'] = self.ssh.pwauth
|
config['ssh_pwauth'] = self.ssh.pwauth
|
||||||
if self.snaplist.selections:
|
for model_name in POSTINSTALL_MODEL_NAMES:
|
||||||
cmds = []
|
model = getattr(self, model_name)
|
||||||
for selection in self.snaplist.selections:
|
if getattr(model, 'make_cloudconfig', None):
|
||||||
cmd = ['snap', 'install', '--channel=' + selection.channel]
|
merge_config(config, model.make_cloudconfig())
|
||||||
if selection.is_classic:
|
|
||||||
cmd.append('--classic')
|
|
||||||
cmd.append(selection.name)
|
|
||||||
cmds.append(' '.join(cmd))
|
|
||||||
config['snap'] = {
|
|
||||||
'commands': cmds,
|
|
||||||
}
|
|
||||||
userdata = copy.deepcopy(self.userdata)
|
userdata = copy.deepcopy(self.userdata)
|
||||||
merge_config(userdata, config)
|
merge_config(userdata, config)
|
||||||
return userdata
|
return userdata
|
||||||
|
|
Loading…
Reference in New Issue