summaryrefslogtreecommitdiff
path: root/cloudinit/net/netplan.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-05-24 21:10:50 -0400
committerScott Moser <smoser@brickies.net>2017-06-08 18:34:06 -0400
commitd00da2d5b0d45db5670622a66d833d2abb907388 (patch)
treead084f88eb4de4c448959e4f3f8543550259a441 /cloudinit/net/netplan.py
parent76d58265e34851b78e952a7f275340863c90a9f5 (diff)
downloadvyos-cloud-init-d00da2d5b0d45db5670622a66d833d2abb907388.tar.gz
vyos-cloud-init-d00da2d5b0d45db5670622a66d833d2abb907388.zip
net: normalize data in network_state object
The network_state object's network and route keys would have different information depending upon how the network_state object was populated. This change cleans that up. Now: * address will always contain an IP address. * prefix will always include an integer value that is the network_prefix for the address. * netmask will be present only if the address is ipv4, and its value will always correlate to the 'prefix'.
Diffstat (limited to 'cloudinit/net/netplan.py')
-rw-r--r--cloudinit/net/netplan.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index a715f3b0..67543305 100644
--- a/cloudinit/net/netplan.py
+++ b/cloudinit/net/netplan.py
@@ -4,7 +4,7 @@ import copy
import os
from . import renderer
-from .network_state import mask2cidr, subnet_is_ipv6
+from .network_state import subnet_is_ipv6
from cloudinit import log as logging
from cloudinit import util
@@ -118,10 +118,9 @@ def _extract_addresses(config, entry):
sn_type += '4'
entry.update({sn_type: True})
elif sn_type in ['static']:
- addr = '%s' % subnet.get('address')
- netmask = subnet.get('netmask')
- if netmask and '/' not in addr:
- addr += '/%s' % mask2cidr(netmask)
+ addr = "%s" % subnet.get('address')
+ if 'prefix' in subnet:
+ addr += "/%d" % subnet.get('prefix')
if 'gateway' in subnet and subnet.get('gateway'):
gateway = subnet.get('gateway')
if ":" in gateway:
@@ -138,9 +137,8 @@ def _extract_addresses(config, entry):
mtukey += '6'
entry.update({mtukey: subnet.get('mtu')})
for route in subnet.get('routes', []):
- network = route.get('network')
- netmask = route.get('netmask')
- to_net = '%s/%s' % (network, mask2cidr(netmask))
+ to_net = "%s/%s" % (route.get('network'),
+ route.get('prefix'))
route = {
'via': route.get('gateway'),
'to': to_net,