cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #02914
[Merge] ~smoser/cloud-init:feature/curtin-centos2 into cloud-init:master
Scott Moser has proposed merging ~smoser/cloud-init:feature/curtin-centos2 into cloud-init:master.
Commit message:
sysconfig: ipv6 and default gateway fixes.
With this change, entries in IPV6ADDR and IPV6ADDR_SECONDARIES will now
always be in format addr/prefix. When a subnet has a gateway will be
written. If the gateway is ipv6, use the key IPV6_DEFAULTGW rather than
GATEWAY.
LP: #1704872
Requested reviews:
cloud-init commiters (cloud-init-dev)
Related bugs:
Bug #1704872 in cloud-init: "sysconfig use subnet prefix and set DEFROUTE key"
https://bugs.launchpad.net/cloud-init/+bug/1704872
For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327739
--
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:feature/curtin-centos2 into cloud-init:master.
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index ad8c268..e45a6c3 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -10,7 +10,8 @@ from cloudinit.distros.parsers import resolv_conf
from cloudinit import util
from . import renderer
-from .network_state import subnet_is_ipv6, net_prefix_to_ipv4_mask
+from .network_state import (
+ is_ipv6_addr, net_prefix_to_ipv4_mask, subnet_is_ipv6)
def _make_header(sep='#'):
@@ -308,19 +309,13 @@ class Renderer(renderer.Renderer):
elif subnet_type == 'static':
if subnet_is_ipv6(subnet):
ipv6_index = ipv6_index + 1
- if 'netmask' in subnet and str(subnet['netmask']) != "":
- ipv6_cidr = (subnet['address'] +
- '/' +
- str(subnet['netmask']))
- else:
- ipv6_cidr = subnet['address']
+ ipv6_cidr = "%s/%s" % (subnet['address'], subnet['prefix'])
if ipv6_index == 0:
iface_cfg['IPV6ADDR'] = ipv6_cidr
elif ipv6_index == 1:
iface_cfg['IPV6ADDR_SECONDARIES'] = ipv6_cidr
else:
- iface_cfg['IPV6ADDR_SECONDARIES'] = (
- iface_cfg['IPV6ADDR_SECONDARIES'] +
+ iface_cfg['IPV6ADDR_SECONDARIES'] += (
" " + ipv6_cidr)
else:
ipv4_index = ipv4_index + 1
@@ -330,7 +325,11 @@ class Renderer(renderer.Renderer):
net_prefix_to_ipv4_mask(subnet['prefix'])
if 'gateway' in subnet:
- iface_cfg['GATEWAY'] = subnet['gateway']
+ iface_cfg['DEFROUTE'] = True
+ if is_ipv6_addr(subnet['gateway']):
+ iface_cfg['IPV6_DEFAULTGW'] = subnet['gateway']
+ else:
+ iface_cfg['GATEWAY'] = subnet['gateway']
@classmethod
def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index dffe178..2f505d9 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -476,10 +476,11 @@ NETWORKING=yes
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
+DEFROUTE=yes
DEVICE=eth0
+GATEWAY=192.168.1.254
IPADDR=192.168.1.5
NETMASK=255.255.255.0
-GATEWAY=192.168.1.254
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
@@ -626,10 +627,11 @@ IPV6_AUTOCONF=no
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
+DEFROUTE=yes
DEVICE=eth0
IPV6ADDR=2607:f0d0:1002:0011::2/64
-GATEWAY=2607:f0d0:1002:0011::1
IPV6INIT=yes
+IPV6_DEFAULTGW=2607:f0d0:1002:0011::1
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 76721ba..2224271 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -298,7 +298,7 @@ DEVICE=eth0
GATEWAY=172.19.3.254
HWADDR=fa:16:3e:ed:9a:59
IPADDR=172.19.1.34
-IPV6ADDR=2001:DB8::10
+IPV6ADDR=2001:DB8::10/64
IPV6ADDR_SECONDARIES="2001:DB9::10/64 2001:DB10::10/64"
IPV6INIT=yes
IPV6_DEFAULTGW=2001:DB8::1
@@ -1161,6 +1161,7 @@ USERCTL=no
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
+DEFROUTE=yes
DEVICE=interface0
GATEWAY=10.0.2.2
HWADDR=52:54:00:12:34:00
References