← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~rmccabe/cloud-init:bug1705804-2 into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
> index f572796..6e11247 100644
> --- a/cloudinit/net/sysconfig.py
> +++ b/cloudinit/net/sysconfig.py
> @@ -347,6 +347,16 @@ class Renderer(renderer.Renderer):
>                      else:
>                          iface_cfg['GATEWAY'] = subnet['gateway']
>  
> +                if 'dns_search' in subnet:
> +                    if isinstance(subnet['dns_search'], (list, tuple)):

I see the problem.  In the per-subnet config, we include support for dns_search and dns_nameservers, but they don't get converted into lists as we're not inspecting the subnets for those values before copying the values into the network_state dictionary.

so, the eth99 subnet:
          - type: static
            address: 192.168.21.3/24
            dns_nameservers:
              - 8.8.8.8
              - 8.8.4.4
            dns_search: barley.maas sach.maas

results in a network_state which includes a string value; but really it should get converted to a list.

I think this does the right thing for network_state and then you can drop the else clause for dns_search below:

diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index 0e830ee..445fd3c 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -325,13 +325,29 @@ class NetworkStateInterpreter(object):
         # convert subnet ipv6 netmask to cidr as needed
         subnets = _normalize_subnets(command.get('subnets'))
 
+        # extract per-subnet dns and
         # automatically set 'use_ipv6' if any addresses are ipv6
-        if not self.use_ipv6:
-            for subnet in subnets:
+        dns = self._network_state.get('dns')
+        for subnet in subnets:
+            if not self.use_ipv6:
                 if (subnet.get('type').endswith('6') or
                         is_ipv6_addr(subnet.get('address'))):
                     self.use_ipv6 = True
                     break
+            if 'dns_search' in subnet:
+                paths = subnet['dns_search']
+                if not isinstance(paths, list):
+                    paths = paths.split(" ")
+                    subnet['dns_search'] = paths
+                for path in paths:
+                    dns['search'].append(path)
+            if 'dns_nameservers' in subnet:
+                addrs = subnet['dns_nameservers']
+                if not type(addrs) == list:
+                    addrs = addrs.split(" ")
+                    subnet['dns_nameservers'] = addrs
+                for addr in addrs:
+                    dns['nameservers'].append(addr)

> +                      iface_cfg['DOMAIN'] = ' '.join(subnet['dns_search'][:3])
> +                    else:
> +                      iface_cfg['DOMAIN'] = subnet['dns_search']
> +
> +                if 'dns_nameservers' in subnet:
> +                    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)):


-- 
https://code.launchpad.net/~rmccabe/cloud-init/+git/cloud-init/+merge/333722
Your team cloud-init commiters is requested to review the proposed merge of ~rmccabe/cloud-init:bug1705804-2 into cloud-init:master.


References