summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/net/network_state.py8
-rw-r--r--cloudinit/net/sysconfig.py15
-rw-r--r--tests/unittests/test_net.py6
3 files changed, 29 insertions, 0 deletions
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)):
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index bbb63cb3..f3fa2a30 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -436,6 +436,9 @@ NETWORK_CONFIGS = {
BOOTPROTO=dhcp
DEFROUTE=yes
DEVICE=eth99
+ DNS1=8.8.8.8
+ DNS2=8.8.4.4
+ DOMAIN="barley.maas sach.maas"
GATEWAY=65.61.151.37
HWADDR=c0:d6:9f:2c:e8:80
IPADDR=192.168.21.3
@@ -836,6 +839,9 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0.101
+ DNS1=192.168.0.10
+ DNS2=10.23.23.134
+ DOMAIN="barley.maas sacchromyces.maas brettanomyces.maas"
GATEWAY=192.168.0.1
IPADDR=192.168.0.2
IPADDR1=192.168.2.10