summaryrefslogtreecommitdiff
path: root/cloudinit/net
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-05-09 20:23:05 -0600
committerScott Moser <smoser@brickies.net>2017-05-10 12:58:50 -0400
commitdd03bb411c9a6f10854a3bbc3223b204c3d4d174 (patch)
treebedcd3e6bd970ef99f87fee215af9a152e046457 /cloudinit/net
parent0a71d5a870b416f2c86c8bc196004bb3fc0768a0 (diff)
downloadvyos-cloud-init-dd03bb411c9a6f10854a3bbc3223b204c3d4d174.tar.gz
vyos-cloud-init-dd03bb411c9a6f10854a3bbc3223b204c3d4d174.zip
sysconfig: Raise ValueError when multiple default gateways are present.
Fixed setting Route.has_set_default_ipv6 or *_ipv4 to track whether a route already has a default gateway defined. The code was setting Route.has_set_default which wasn't checked when raising "duplicate gateway" ValueErrors. Added unit tests to exercise this expected raised ValueError. Also moved is_ipv6 = subnet.get('ipv6') logic out of a for loop because we don't need to recalculate the same value every route iteration. LP: #1687485
Diffstat (limited to 'cloudinit/net')
-rw-r--r--cloudinit/net/sysconfig.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index 504e4d02..d981277a 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -232,12 +232,8 @@ class Renderer(renderer.Renderer):
iface_cfg.name))
if 'netmask' in subnet:
iface_cfg['NETMASK'] = subnet['netmask']
+ is_ipv6 = subnet.get('ipv6')
for route in subnet.get('routes', []):
- if subnet.get('ipv6'):
- gw_cfg = 'IPV6_DEFAULTGW'
- else:
- gw_cfg = 'GATEWAY'
-
if _is_default_route(route):
if (
(subnet.get('ipv4') and
@@ -258,8 +254,12 @@ class Renderer(renderer.Renderer):
# also provided the default route?
iface_cfg['DEFROUTE'] = True
if 'gateway' in route:
- iface_cfg[gw_cfg] = route['gateway']
- route_cfg.has_set_default = True
+ if is_ipv6:
+ iface_cfg['IPV6_DEFAULTGW'] = route['gateway']
+ route_cfg.has_set_default_ipv6 = True
+ else:
+ iface_cfg['GATEWAY'] = route['gateway']
+ route_cfg.has_set_default_ipv4 = True
else:
gw_key = 'GATEWAY%s' % route_cfg.last_idx
nm_key = 'NETMASK%s' % route_cfg.last_idx