← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~xnox/cloud-init:nplan-ipv6-int-mask2cidr into cloud-init:master

 

Dimitri John Ledkov has proposed merging ~xnox/cloud-init:nplan-ipv6-int-mask2cidr into cloud-init:master.

Commit message:
nplan: correctly generate ipv6 and ipv4 netmask addresses

It appears that the internal networking state parses netmask as
netmask for ipv4, yet as a cidr for ipv6, resulting in mask2cidr
failing as the passed value is not an integer. This feels like a
workaround to me. I think mask2cidr should cash the arguments passed
to int, into a string first.

LP: #1691100

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1691100 in cloud-init (Ubuntu): "ipv6 parsing appears to fail for netplan, with latest changes"
  https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1691100

For more details, see:
https://code.launchpad.net/~xnox/cloud-init/+git/cloud-init/+merge/324106

nplan: correctly generate ipv6 and ipv4 netmask addresses

It appears that the internal networking state parses netmask as
netmask for ipv4, yet as a cidr for ipv6, resulting in mask2cidr
failing as the passed value is not an integer. This feels like a
workaround to me. I think mask2cidr should cash the arguments passed
to int, into a string first.

LP: #1691100
-- 
Your team cloud init development team is requested to review the proposed merge of ~xnox/cloud-init:nplan-ipv6-int-mask2cidr into cloud-init:master.
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index 825fe83..92591cc 100644
--- a/cloudinit/net/netplan.py
+++ b/cloudinit/net/netplan.py
@@ -118,9 +118,13 @@ def _extract_addresses(config, entry):
                 sn_type += '4'
             entry.update({sn_type: True})
         elif sn_type in ['static']:
-            addr = "%s" % subnet.get('address')
-            if 'netmask' in subnet:
-                addr += "/%s" % subnet.get('netmask')
+            addr = '%s' % subnet.get('address')
+            netmask = subnet.get('netmask')
+            if netmask and '/' not in addr:
+                if ':' in addr:
+                    addr += '/%s' % netmask
+                else:
+                    addr += '/%s' % mask2cidr(netmask)
             if 'gateway' in subnet and subnet.get('gateway'):
                 gateway = subnet.get('gateway')
                 if ":" in gateway:
@@ -137,8 +141,12 @@ def _extract_addresses(config, entry):
                     mtukey += '6'
                 entry.update({mtukey: subnet.get('mtu')})
             for route in subnet.get('routes', []):
-                to_net = "%s/%s" % (route.get('network'),
-                                    route.get('netmask'))
+                network = route.get('network')
+                netmask = route.get('netmask')
+                if ':' in network:
+                    to_net = '%s/%s' % (network, netmask)
+                else:
+                    to_net = '%s/%s' % (network, mask2cidr(netmask))
                 route = {
                     'via': route.get('gateway'),
                     'to': to_net,

Follow ups