summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-08-21 16:26:43 -0400
committerScott Moser <smoser@ubuntu.com>2014-08-21 16:26:43 -0400
commit589f740909b40d814a4b802263e61ff2b5c35b24 (patch)
tree06d176e0dc83f3a90a579d742a8c0fa68f312b16
parentd8c8a87f9b4c314bc39f5987602c02d3861f329f (diff)
downloadvyos-cloud-init-589f740909b40d814a4b802263e61ff2b5c35b24.tar.gz
vyos-cloud-init-589f740909b40d814a4b802263e61ff2b5c35b24.zip
fix rendering resolv.conf if no 'options' are provided
this makes some changes to the cc_resolv_conf to make its generate_resolv_conf method more easily callable (for future test). Also sets it up so that 'options' is always defined when the template is rendered. LP: #1328953
-rw-r--r--ChangeLog1
-rw-r--r--cloudinit/config/cc_resolv_conf.py29
-rw-r--r--templates/resolv.conf.tmpl2
3 files changed, 20 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d8d6427..4d326b31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,7 @@
are generated. [Jordan Evans] (LP: #1333920)
- default settings: fix typo resulting in OpenStack and GCE not working
unless config explicitly provided (LP: #1329583) [Garrett Holmstrom])
+ - fix rendering resolv.conf if no 'options' are provided (LP: #1328953)
0.7.5:
- open 0.7.5
- Add a debug log message around import failures
diff --git a/cloudinit/config/cc_resolv_conf.py b/cloudinit/config/cc_resolv_conf.py
index 879b62b1..bbaa6c63 100644
--- a/cloudinit/config/cc_resolv_conf.py
+++ b/cloudinit/config/cc_resolv_conf.py
@@ -49,23 +49,22 @@
#
+from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
from cloudinit import templater
from cloudinit import util
+LOG = logging.getLogger(__name__)
+
frequency = PER_INSTANCE
distros = ['fedora', 'rhel', 'sles']
-def generate_resolv_conf(cloud, log, params):
- template_fn = cloud.get_template_filename('resolv.conf')
- if not template_fn:
- log.warn("No template found, not rendering /etc/resolv.conf")
- return
-
+def generate_resolv_conf(template_fn, params, target_fname="/etc/resolv.conf"):
flags = []
false_flags = []
+
if 'options' in params:
for key, val in params['options'].iteritems():
if type(val) == bool:
@@ -77,12 +76,15 @@ def generate_resolv_conf(cloud, log, params):
for flag in flags + false_flags:
del params['options'][flag]
+ if not params.get('options'):
+ params['options'] = {}
+
params['flags'] = flags
- log.debug("Writing resolv.conf from template %s" % template_fn)
- templater.render_to_file(template_fn, '/etc/resolv.conf', params)
+ LOG.debug("Writing resolv.conf from template %s" % template_fn)
+ templater.render_to_file(template_fn, target_fname, params)
-def handle(name, cfg, _cloud, log, _args):
+def handle(name, cfg, cloud, log, _args):
"""
Handler for resolv.conf
@@ -102,8 +104,13 @@ def handle(name, cfg, _cloud, log, _args):
" 'manage_resolv_conf' present but set to False"), name)
return
- if not "resolv_conf" in cfg:
+ if "resolv_conf" not in cfg:
log.warn("manage_resolv_conf True but no parameters provided!")
- generate_resolv_conf(_cloud, log, cfg["resolv_conf"])
+ template_fn = cloud.get_template_filename('resolv.conf')
+ if not template_fn:
+ log.warn("No template found, not rendering /etc/resolv.conf")
+ return
+
+ generate_resolv_conf(template_fn=template_fn, params=cfg["resolv_conf"])
return
diff --git a/templates/resolv.conf.tmpl b/templates/resolv.conf.tmpl
index 6f908f30..1300156c 100644
--- a/templates/resolv.conf.tmpl
+++ b/templates/resolv.conf.tmpl
@@ -21,7 +21,7 @@ domain {{domain}}
sortlist {% for sort in sortlist %}{{sort}} {% endfor %}
{% endif %}
-{% if options is defined or flags is defined %}
+{% if options or flags %}
options {% for flag in flags %}{{flag}} {% endfor %}
{% for key, value in options.iteritems() -%}