From bbe91cdc6917adb503b455e6860c21ea7b3f567f Mon Sep 17 00:00:00 2001 From: Ryan McCabe Date: Mon, 20 Nov 2017 18:16:00 -0500 Subject: sysconfig: Correctly render dns and dns search info. Currently when dns and dns search info is provided, it is not rendered when outputting to sysconfig format. This patch causes the DNS and DOMAIN lines to be written out rendering sysconfig. LP: #1705804 --- cloudinit/net/network_state.py | 8 ++++++++ cloudinit/net/sysconfig.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'cloudinit/net') diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py index 0e830ee8..e9e2cf4e 100644 --- a/cloudinit/net/network_state.py +++ b/cloudinit/net/network_state.py @@ -746,6 +746,14 @@ def _normalize_subnet(subnet): _normalize_net_keys(normal_subnet, address_keys=('address',))) normal_subnet['routes'] = [_normalize_route(r) for r in subnet.get('routes', [])] + + def listify(snet, name): + if name in snet and not isinstance(snet[name], list): + snet[name] = snet[name].split() + + for k in ('dns_search', 'dns_nameservers'): + listify(normal_subnet, k) + return normal_subnet diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py index f5727969..39d89c46 100644 --- a/cloudinit/net/sysconfig.py +++ b/cloudinit/net/sysconfig.py @@ -7,12 +7,15 @@ import six from cloudinit.distros.parsers import networkmanager_conf from cloudinit.distros.parsers import resolv_conf +from cloudinit import log as logging from cloudinit import util from . import renderer from .network_state import ( is_ipv6_addr, net_prefix_to_ipv4_mask, subnet_is_ipv6) +LOG = logging.getLogger(__name__) + def _make_header(sep='#'): lines = [ @@ -347,6 +350,18 @@ class Renderer(renderer.Renderer): else: iface_cfg['GATEWAY'] = subnet['gateway'] + if 'dns_search' in subnet: + iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search']) + + if 'dns_nameservers' in subnet: + if len(subnet['dns_nameservers']) > 3: + # per resolv.conf(5) MAXNS sets this to 3. + LOG.debug("%s has %d entries in dns_nameservers. " + "Only 3 are used.", iface_cfg.name, + len(subnet['dns_nameservers'])) + for i, k in enumerate(subnet['dns_nameservers'][:3], 1): + iface_cfg['DNS' + str(i)] = k + @classmethod def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets): for i, subnet in enumerate(subnets, start=len(iface_cfg.children)): -- cgit v1.2.3