Bert JW Regeer has proposed merging 
~bregeer-ctl/cloud-init:bugfix/centos7_resolv into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~bregeer-ctl/cloud-init/+git/cloud-init/+merge/305058

See bugs:

https://bugs.launchpad.net/cloud-init/+bug/1620796
https://bugs.launchpad.net/cloud-init/+bug/1620807
-- 
Your team cloud init development team is requested to review the proposed merge 
of ~bregeer-ctl/cloud-init:bugfix/centos7_resolv into cloud-init:master.
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index c53acf7..a5d6611 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -20,8 +20,11 @@ import six
 from cloudinit.distros.parsers import resolv_conf
 from cloudinit import util
 
+from cloudinit import log as logging
+
 from . import renderer
 
+LOG = logging.getLogger(__name__)
 
 def _make_header(sep='#'):
     lines = [
@@ -206,6 +209,10 @@ class Renderer(renderer.Renderer):
         self.netrules_path = config.get(
             'netrules_path', 'etc/udev/rules.d/70-persistent-net.rules')
         self.dns_path = config.get('dns_path', 'etc/resolv.conf')
+        self.dns_symlink = config.get('dns_symlink', True)
+
+        self.dns_write_path = config.get('dns_write_path', 'etc/resolv.conf.cloud') \
+            if self.dns_symlink else self.dns_path
 
     @classmethod
     def _render_iface_shared(cls, iface, iface_cfg):
@@ -335,7 +342,10 @@ class Renderer(renderer.Renderer):
         if existing_dns_path and os.path.isfile(existing_dns_path):
             content = resolv_conf.ResolvConf(util.load_file(existing_dns_path))
         for nameserver in network_state.dns_nameservers:
-            content.add_nameserver(nameserver)
+            try:
+                content.add_nameserver(nameserver)
+            except ValueError as e:
+                LOG.debug('Unable to add nameserver %s: %s', nameserver, e)
         for searchdomain in network_state.dns_searchdomains:
             content.add_search_domain(searchdomain)
         return "\n".join([_make_header(';'), str(content)])
@@ -389,11 +399,22 @@ class Renderer(renderer.Renderer):
         for path, data in self._render_sysconfig(base_sysconf_dir,
                                                  network_state).items():
             util.write_file(path, data)
-        if self.dns_path:
+        if self.dns_write_path:
             dns_path = os.path.join(target, self.dns_path)
+            dns_write_path = os.path.join(target, self.dns_write_path)
             resolv_content = self._render_dns(network_state,
                                               existing_dns_path=dns_path)
-            util.write_file(dns_path, resolv_content)
+            util.write_file(dns_write_path, resolv_content)
+
+            if self.dns_symlink:
+                if os.path.exists(dns_path) and not os.path.islink(dns_path):
+                    LOG.debug('Removing existing resolv.conf')
+                    os.unlink(dns_path)
+
+                if not os.path.exists(dns_path):
+                    LOG.debug('Adding symlink from %s to %s', dns_path, dns_write_path)
+                    os.symlink(dns_write_path, dns_path)
+
         if self.netrules_path:
             netrules_content = self._render_persistent_net(network_state)
             netrules_path = os.path.join(target, self.netrules_path)
_______________________________________________
Mailing list: https://launchpad.net/~cloud-init-dev
Post to     : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to