sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
ef3f20
From bc2e1a64e64bddf04fd3e27c79432facbedca182 Mon Sep 17 00:00:00 2001
ef3f20
From: Ryan McCabe <rmccabe@redhat.com>
ef3f20
Date: Tue, 13 Jun 2017 11:45:07 -0400
ef3f20
Subject: [PATCH] Fix ipv6 subnet detection
ef3f20
ef3f20
Add better ipv6 subnet detection that was added as part of a
ef3f20
much larger patch set in upstream commit
ef3f20
ef18b8ac4cf7e3dfd98830fbdb298380a192a0fc
ef3f20
ef3f20
Related: rhbz#1438082
ef3f20
X-approved-upstream: true
ef3f20
ef3f20
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
ef3f20
---
ef3f20
 cloudinit/net/sysconfig.py | 15 +++++++++++++--
ef3f20
 1 file changed, 13 insertions(+), 2 deletions(-)
ef3f20
ef3f20
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
ef3f20
index ef80d99..6a0dd43 100644
ef3f20
--- a/cloudinit/net/sysconfig.py
ef3f20
+++ b/cloudinit/net/sysconfig.py
ef3f20
@@ -11,6 +11,17 @@ from cloudinit import util
ef3f20
 from . import renderer
ef3f20
 
ef3f20
 
ef3f20
+def _subnet_is_ipv6(subnet):
ef3f20
+    """Common helper for checking network_state subnets for ipv6."""
ef3f20
+    # 'static6' or 'dhcp6'
ef3f20
+    if subnet['type'].endswith('6'):
ef3f20
+        # This is a request for DHCPv6.
ef3f20
+        return True
ef3f20
+    elif subnet['type'] == 'static' and ":" in subnet['address']:
ef3f20
+        return True
ef3f20
+    return False
ef3f20
+
ef3f20
+
ef3f20
 def _make_header(sep='#'):
ef3f20
     lines = [
ef3f20
         "Created by cloud-init on instance boot automatically, do not edit.",
ef3f20
@@ -286,7 +297,7 @@ class Renderer(renderer.Renderer):
ef3f20
                 # but should remain 'none'
ef3f20
                 # if iface_cfg['BOOTPROTO'] == 'none':
ef3f20
                 #    iface_cfg['BOOTPROTO'] = 'static'
ef3f20
-                if subnet.get('ipv6'):
ef3f20
+                if _subnet_is_ipv6(subnet):
ef3f20
                     iface_cfg['IPV6INIT'] = True
ef3f20
             else:
ef3f20
                 raise ValueError("Unknown subnet type '%s' found"
ef3f20
@@ -303,7 +314,7 @@ class Renderer(renderer.Renderer):
ef3f20
             elif subnet_type in ['dhcp4', 'dhcp']:
ef3f20
                 continue
ef3f20
             elif subnet_type == 'static':
ef3f20
-                if subnet.get('ipv6'):
ef3f20
+                if _subnet_is_ipv6(subnet):
ef3f20
                     ipv6_index = ipv6_index + 1
ef3f20
                     if 'netmask' in subnet and str(subnet['netmask']) != "":
ef3f20
                         ipv6_cidr = (subnet['address'] +