Commit 860d98bc authored by Scott Moser's avatar Scott Moser

minor cleanups

 - use util.del_file rather than os.remove
 - raise exception if debconf-communicate is not present
 - add a trailing newline into debconf-communicate input
parent 32340db1
......@@ -46,7 +46,6 @@ Example config:
"""
from cloudinit import util
import os
def handle(name, cfg, cloud, log, args):
......@@ -102,26 +101,29 @@ def handle(name, cfg, cloud, log, args):
util.subp(cmd)
# Set up lxd-bridge if bridge config is given
if bridge_cfg:
dconf_comm = "debconf-communicate"
if bridge_cfg and util.which(dconf_comm):
debconf = bridge_to_debconf(bridge_cfg)
# Update debconf database
try:
log.debug("Setting lxd debconf-set-selections")
log.debug("Setting lxd debconf via " + dconf_comm)
data = "\n".join(["set %s %s" % (k, v)
for k, v in debconf.items()])
for k, v in debconf.items()]) + "\n"
util.subp(['debconf-communicate'], data)
except:
util.logexc(log, "Failed to run debconf-communicate for lxd")
util.logexc(log, "Failed to run '%s' for lxd with" % dconf_comm)
# Remove the existing configuration file (forces re-generation)
if os.path.exists("/etc/default/lxd-bridge"):
os.remove("/etc/default/lxd-bridge")
util.del_file("/etc/default/lxd-bridge")
# Run reconfigure
log.debug("Running dpkg-reconfigure for lxd")
util.subp(['dpkg-reconfigure', 'lxd',
'--frontend=noninteractive'])
elif bridge_cfg:
raise RuntimeError(
"Unable to configure lxd bridge without %s." + dconf_comm)
def bridge_to_debconf(bridge_cfg):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment