← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~rackerhacker/cloud-init/add-ipv6-static-address-support into lp:cloud-init

 

Major Hayden has proposed merging lp:~rackerhacker/cloud-init/add-ipv6-static-address-support into lp:cloud-init.

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

For more details, see:
https://code.launchpad.net/~rackerhacker/cloud-init/add-ipv6-static-address-support/+merge/242435

This branch adds static IPv6 address support for cloud-init.  If nova provides IPv6 data with a config disk right now, cloud-init breaks and doesn't write any RHEL/CentOS/Fedora networking configuration files.  The new code checks for "iface <interface> inet6" and adds in the IPv6 network configuration information so that it can be written to the network config files.
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~rackerhacker/cloud-init/add-ipv6-static-address-support into lp:cloud-init.
=== modified file 'cloudinit/distros/net_util.py'
--- cloudinit/distros/net_util.py	2014-01-24 21:20:54 +0000
+++ cloudinit/distros/net_util.py	2014-11-20 22:34:50 +0000
@@ -128,12 +128,21 @@
             # really care about
             if proto_type in ['dhcp', 'static']:
                 iface_info['bootproto'] = proto_type
-        # These can just be copied over
-        for k in ['netmask', 'address', 'gateway', 'broadcast']:
-            if k in info:
-                val = info[k].strip().lower()
-                if val:
-                    iface_info[k] = val
+
+        # Get the IPv4 and IPv6 (if applicable) configuration for our interface
+        if iface_details[1] == 'inet':
+            # Copy over IPv4 configuration verbatim
+            for k in ['netmask', 'address', 'gateway', 'broadcast']:
+                if k in info:
+                    val = info[k].strip().lower()
+                    if val:
+                        iface_info[k] = val
+        elif iface_details[1] == 'inet6' and 'gateway' in info:
+            # We have an IPv6 configuration for this interface
+            iface_info['ipv6_address'] = info['address'].strip()
+            iface_info['ipv6_gateway'] = info['gateway'].strip()
+            iface_info['ipv6_netmask'] = info['netmask'].strip()
+
         # Name server info provided??
         if 'dns-nameservers' in info:
             iface_info['dns-nameservers'] = info['dns-nameservers'].split()
@@ -148,7 +157,11 @@
                 hw_addr = hw_split[1]
                 if hw_addr:
                     iface_info['hwaddress'] = hw_addr
-        real_ifaces[dev_name] = iface_info
+        if dev_name in real_ifaces:
+            # We're probably dealing with dual-stack ipv4/ipv6 interfaces
+            real_ifaces[dev_name] = dict(real_ifaces[dev_name].items() + iface_info.items())
+        else:
+            real_ifaces[dev_name] = iface_info
     # Check for those that should be started on boot via 'auto'
     for (cmd, args) in entries:
         if cmd == 'auto':

=== modified file 'cloudinit/distros/rhel.py'
--- cloudinit/distros/rhel.py	2014-10-17 19:32:41 +0000
+++ cloudinit/distros/rhel.py	2014-11-20 22:34:50 +0000
@@ -83,6 +83,18 @@
                 'MACADDR': info.get('hwaddress'),
                 'ONBOOT': _make_sysconfig_bool(info.get('auto')),
             }
+            # We might have some IPv6 configuration data for this interface. If
+            # we do, let's write that configuration down with the IPv4 data.
+            if 'ipv6_address' in info:
+                ipv6_net_cfg = {
+                    'IPV6ADDR': "%s/%s" % (info.get('ipv6_address'),
+                                           info.get('ipv6_netmask')),
+                    'IPV6_DEFAULTGW': info.get('ipv6_gateway'),
+                    'IPV6INIT': 'yes',
+                    'IPV6_AUTOCONF': 'no'
+                }
+                # Append our IPv6 data onto the IPv4 data that already exists
+                net_cfg = dict(net_cfg.items() + ipv6_net_cfg.items())
             rhel_util.update_sysconfig_file(net_fn, net_cfg)
             if 'dns-nameservers' in info:
                 nameservers.extend(info['dns-nameservers'])