From d29eeccd2c422b8eb3b053fc13ca966ed6d74c78 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 22 Mar 2018 09:55:27 -0600 Subject: Handle global dns entries in netplan In network config v1 format, there are dns values which are not bound to a specific interface and do not map to the per-interface format in netplan. To handle this case we render netplan configuration that duplicates the DNS configuration on any interface that has a static network config. We avoiding interfaces which have DHCP configuration which may provide conflicting DNS values. LP: #1750884 --- cloudinit/net/netplan.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'cloudinit/net') diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py index 6bee3d37..63443484 100644 --- a/cloudinit/net/netplan.py +++ b/cloudinit/net/netplan.py @@ -336,22 +336,15 @@ class Renderer(renderer.Renderer): _extract_addresses(ifcfg, vlan) vlans.update({ifname: vlan}) - # inject global nameserver values under each physical interface - if nameservers: - for _eth, cfg in ethernets.items(): - nscfg = cfg.get('nameservers', {}) - addresses = nscfg.get('addresses', []) - addresses += nameservers - nscfg.update({'addresses': addresses}) - cfg.update({'nameservers': nscfg}) - - if searchdomains: - for _eth, cfg in ethernets.items(): - nscfg = cfg.get('nameservers', {}) - search = nscfg.get('search', []) - search += searchdomains - nscfg.update({'search': search}) - cfg.update({'nameservers': nscfg}) + # inject global nameserver values under each all interface which + # has addresses and do not already have a DNS configuration + if nameservers or searchdomains: + nscfg = {'addresses': nameservers, 'search': searchdomains} + for section in [ethernets, wifis, bonds, bridges, vlans]: + for _name, cfg in section.items(): + if 'nameservers' in cfg or 'addresses' not in cfg: + continue + cfg.update({'nameservers': nscfg}) # workaround yaml dictionary key sorting when dumping def _render_section(name, section): -- cgit v1.2.3