summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-01 00:19:55 -0500
committerScott Moser <smoser@ubuntu.com>2016-03-01 00:19:55 -0500
commit14915526ca67bbf7842028d48170015b85f87469 (patch)
treeb355f852bc8a585513eb7651f58ccbf54dd64460 /cloudinit
parentb7a6e92274bb0d146c4637a78128bc771f2612e9 (diff)
downloadvyos-cloud-init-14915526ca67bbf7842028d48170015b85f87469.tar.gz
vyos-cloud-init-14915526ca67bbf7842028d48170015b85f87469.zip
lxd: general fix after testing
A few changes: a.) change to using '--name=value' rather than '--name' 'value' b.) make sure only strings are passed to command (useful for storage_create_loop: which is likely an integer) c.) document simple working example d.) support installing zfs if not present and storage_backedn has it.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_lxd.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py
index aaafb643..84eec7a5 100644
--- a/cloudinit/config/cc_lxd.py
+++ b/cloudinit/config/cc_lxd.py
@@ -38,16 +38,36 @@ from cloudinit import util
def handle(name, cfg, cloud, log, args):
# Get config
lxd_cfg = cfg.get('lxd')
- if not lxd_cfg and isinstance(lxd_cfg, dict):
+ if not lxd_cfg:
log.debug("Skipping module named %s, not present or disabled by cfg")
return
+ if not isinstance(lxd_cfg, dict):
+ log.warn("lxd config must be a dictionary. found a '%s'",
+ type(lxd_cfg))
+ return
+
+ init_cfg = lxd_cfg.get('init')
+ if not init_cfg:
+ init_cfg = {}
+
+ if not isinstance(init_cfg, dict):
+ log.warn("lxd/init config must be a dictionary. found a '%s'",
+ type(init_cfg))
+ init_cfg = {}
+
+ packages = []
+ if (init_cfg.get("storage_backend") == "zfs" and not util.which('zfs')):
+ packages.append('zfs')
# Ensure lxd is installed
if not util.which("lxd"):
+ packages.append('lxd')
+
+ if len(packages):
try:
- cloud.distro.install_packages(("lxd",))
+ cloud.distro.install_packages(packages)
except util.ProcessExecutionError as e:
- log.warn("no lxd executable and could not install lxd:", e)
+ log.warn("failed to install packages %s: %s", packages, e)
return
# Set up lxd if init config is given
@@ -55,14 +75,11 @@ def handle(name, cfg, cloud, log, args):
'network_address', 'network_port', 'storage_backend',
'storage_create_device', 'storage_create_loop',
'storage_pool', 'trust_password')
- init_cfg = lxd_cfg.get('init')
+
if init_cfg:
- if not isinstance(init_cfg, dict):
- log.warn("lxd/init config must be a dictionary. found a '%s'",
- type(f))
- return
cmd = ['lxd', 'init', '--auto']
for k in init_keys:
if init_cfg.get(k):
- cmd.extend(["--%s" % k.replace('_', '-'), init_cfg[k]])
+ cmd.extend(["--%s=%s" %
+ (k.replace('_', '-'), str(init_cfg[k]))])
util.subp(cmd)