sailesh1993 / rpms / cloud-init

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