summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-01 00:22:20 -0500
committerScott Moser <smoser@ubuntu.com>2016-03-01 00:22:20 -0500
commitc430ef68db729657f0ba9531301d63f31ac6c54c (patch)
tree387daf14689f29d4e2465de2b6e94aabb4cc299d
parentaf5d2a102c029da4b853a3bc42a6e23ce3a40fe6 (diff)
parent14915526ca67bbf7842028d48170015b85f87469 (diff)
downloadvyos-cloud-init-c430ef68db729657f0ba9531301d63f31ac6c54c.tar.gz
vyos-cloud-init-c430ef68db729657f0ba9531301d63f31ac6c54c.zip
merge with trunk
-rw-r--r--cloudinit/config/cc_lxd.py35
-rw-r--r--doc/examples/cloud-config-lxd.txt7
-rw-r--r--tests/unittests/test_handler/test_handler_lxd.py9
3 files changed, 38 insertions, 13 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)
diff --git a/doc/examples/cloud-config-lxd.txt b/doc/examples/cloud-config-lxd.txt
index f66da4c3..b9bb4aa5 100644
--- a/doc/examples/cloud-config-lxd.txt
+++ b/doc/examples/cloud-config-lxd.txt
@@ -19,3 +19,10 @@ lxd:
network_port: 8443
storage_backend: zfs
storage_pool: datapool
+ storage_create_loop: 10
+
+
+# The simplist working configuration is
+# lxd:
+# init:
+# storage_backend: dir
diff --git a/tests/unittests/test_handler/test_handler_lxd.py b/tests/unittests/test_handler/test_handler_lxd.py
index 4d858b8f..65794a41 100644
--- a/tests/unittests/test_handler/test_handler_lxd.py
+++ b/tests/unittests/test_handler/test_handler_lxd.py
@@ -43,9 +43,10 @@ class TestLxd(t_help.TestCase):
self.assertTrue(mock_util.which.called)
init_call = mock_util.subp.call_args_list[0][0][0]
self.assertEquals(init_call,
- ['lxd', 'init', '--auto', '--network-address',
- '0.0.0.0', '--storage-backend', 'zfs',
- '--storage-pool', 'poolname'])
+ ['lxd', 'init', '--auto',
+ '--network-address=0.0.0.0',
+ '--storage-backend=zfs',
+ '--storage-pool=poolname'])
@mock.patch("cloudinit.config.cc_lxd.util")
def test_lxd_install(self, mock_util):
@@ -55,4 +56,4 @@ class TestLxd(t_help.TestCase):
cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, [])
self.assertTrue(cc.distro.install_packages.called)
install_pkg = cc.distro.install_packages.call_args_list[0][0][0]
- self.assertEquals(install_pkg, ('lxd',))
+ self.assertEquals(sorted(install_pkg), ['lxd', 'zfs'])