← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~xnox/cloud-init:cidr into cloud-init:master

 

Dimitri John Ledkov has proposed merging ~xnox/cloud-init:cidr into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1689346 in cloud-init (Ubuntu): "cloud-init and nplan do not parse and use OpenStack networking correctly with netmask"
  https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1689346

For more details, see:
https://code.launchpad.net/~xnox/cloud-init/+git/cloud-init/+merge/324010
-- 
Your team cloud init development team is requested to review the proposed merge of ~xnox/cloud-init:cidr into cloud-init:master.
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index 825fe83..fa04eab 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 subnet_is_ipv6
+from .network_state import mask2cidr, subnet_is_ipv6
 
 from cloudinit import log as logging
 from cloudinit import util
@@ -119,8 +119,8 @@ def _extract_addresses(config, entry):
             entry.update({sn_type: True})
         elif sn_type in ['static']:
             addr = "%s" % subnet.get('address')
-            if 'netmask' in subnet:
-                addr += "/%s" % subnet.get('netmask')
+            if subnet.get('netmask') and '/' not in addr:
+                addr += "/%s" % mask2cidr(subnet.get('netmask'))
             if 'gateway' in subnet and subnet.get('gateway'):
                 gateway = subnet.get('gateway')
                 if ":" in gateway:
@@ -138,7 +138,7 @@ def _extract_addresses(config, entry):
                 entry.update({mtukey: subnet.get('mtu')})
             for route in subnet.get('routes', []):
                 to_net = "%s/%s" % (route.get('network'),
-                                    route.get('netmask'))
+                                    mask2cidr(route.get('netmask')))
                 route = {
                     'via': route.get('gateway'),
                     'to': to_net,
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 1e10a33..4fe16a9 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -127,7 +127,7 @@ network:
     ethernets:
         eth0:
             addresses:
-            - 192.168.1.5/255.255.255.0
+            - 192.168.1.5/24
             gateway4: 192.168.1.254
         eth1:
             dhcp4: true
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 7c5dc4e..752157a 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -440,7 +440,7 @@ NETWORK_CONFIGS = {
                             - sach.maas
                             - wark.maas
                         routes:
-                        -   to: 0.0.0.0/0.0.0.0
+                        -   to: 0.0.0.0/0
                             via: 65.61.151.37
                         set-name: eth99
         """).rstrip(' '),

Follow ups