|
|
c36ff1 |
From 290353d6df0b3bbbbcfa4f949f943388939ebc12 Mon Sep 17 00:00:00 2001
|
|
|
c36ff1 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
|
|
|
c36ff1 |
Date: Fri, 11 Feb 2022 14:57:40 +0100
|
|
|
c36ff1 |
Subject: [PATCH 1/3] Fix IPv6 netmask format for sysconfig (#1215)
|
|
|
c36ff1 |
|
|
|
c36ff1 |
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
|
|
|
c36ff1 |
RH-MergeRequest: 20: Fix IPv6 netmask format for sysconfig (#1215)
|
|
|
c36ff1 |
RH-Commit: [1/1] 2eb7ac7c85e82c14f9a95b9baf1482ac987b1084 (eesposit/cloud-init-centos-)
|
|
|
c36ff1 |
RH-Bugzilla: 2053546
|
|
|
c36ff1 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
c36ff1 |
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
|
c36ff1 |
|
|
|
c36ff1 |
commit b97a30f0a05c1dea918c46ca9c05c869d15fe2d5
|
|
|
c36ff1 |
Author: Harald <hjensas@redhat.com>
|
|
|
c36ff1 |
Date: Tue Feb 8 15:49:00 2022 +0100
|
|
|
c36ff1 |
|
|
|
c36ff1 |
Fix IPv6 netmask format for sysconfig (#1215)
|
|
|
c36ff1 |
|
|
|
c36ff1 |
This change converts the IPv6 netmask from the network_data.json[1]
|
|
|
c36ff1 |
format to the CIDR style, <IPv6_addr>/<prefix>.
|
|
|
c36ff1 |
|
|
|
c36ff1 |
Using an IPv6 address like ffff:ffff:ffff:ffff:: does not work with
|
|
|
c36ff1 |
NetworkManager, nor networkscripts.
|
|
|
c36ff1 |
|
|
|
c36ff1 |
NetworkManager will ignore the route, logging:
|
|
|
c36ff1 |
ifcfg-rh: ignoring invalid route at \
|
|
|
c36ff1 |
"::/:: via fd00:fd00:fd00:2::fffe dev $DEV" \
|
|
|
c36ff1 |
(/etc/sysconfig/network-scripts/route6-$DEV:3): \
|
|
|
c36ff1 |
Argument for "::/::" is not ADDR/PREFIX format
|
|
|
c36ff1 |
|
|
|
c36ff1 |
Similarly if using networkscripts, ip route fail with error:
|
|
|
c36ff1 |
Error: inet6 prefix is expected rather than \
|
|
|
c36ff1 |
"fd00:fd00:fd00::/ffff:ffff:ffff:ffff::".
|
|
|
c36ff1 |
|
|
|
c36ff1 |
Also a bit of refactoring ...
|
|
|
c36ff1 |
|
|
|
c36ff1 |
cloudinit.net.sysconfig.Route.to_string:
|
|
|
c36ff1 |
* Move a couple of lines around to reduce repeated code.
|
|
|
c36ff1 |
* if "ADDRESS" not in key -> continute, so that the
|
|
|
c36ff1 |
code block following it can be de-indented.
|
|
|
c36ff1 |
cloudinit.net.network_state:
|
|
|
c36ff1 |
* Refactors the ipv4_mask_to_net_prefix, ipv6_mask_to_net_prefix
|
|
|
c36ff1 |
removes mask_to_net_prefix methods. Utilize ipaddress library to
|
|
|
c36ff1 |
do some of the heavy lifting.
|
|
|
c36ff1 |
|
|
|
c36ff1 |
LP: #1959148
|
|
|
c36ff1 |
|
|
|
c36ff1 |
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
|
|
|
c36ff1 |
---
|
|
|
c36ff1 |
cloudinit/net/__init__.py | 7 +-
|
|
|
c36ff1 |
cloudinit/net/network_state.py | 103 +++++++-----------
|
|
|
c36ff1 |
cloudinit/net/sysconfig.py | 91 ++++++++++------
|
|
|
c36ff1 |
cloudinit/sources/DataSourceOpenNebula.py | 2 +-
|
|
|
c36ff1 |
.../sources/helpers/vmware/imc/config_nic.py | 4 +-
|
|
|
c36ff1 |
tests/unittests/test_net.py | 78 ++++++++++++-
|
|
|
c36ff1 |
6 files changed, 176 insertions(+), 109 deletions(-)
|
|
|
c36ff1 |
|
|
|
c36ff1 |
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
|
|
|
c36ff1 |
index 4bdc1bda..91cb0627 100644
|
|
|
c36ff1 |
--- a/cloudinit/net/__init__.py
|
|
|
c36ff1 |
+++ b/cloudinit/net/__init__.py
|
|
|
c36ff1 |
@@ -13,7 +13,7 @@ import re
|
|
|
c36ff1 |
|
|
|
c36ff1 |
from cloudinit import subp
|
|
|
c36ff1 |
from cloudinit import util
|
|
|
c36ff1 |
-from cloudinit.net.network_state import mask_to_net_prefix
|
|
|
c36ff1 |
+from cloudinit.net.network_state import ipv4_mask_to_net_prefix
|
|
|
c36ff1 |
from cloudinit.url_helper import UrlError, readurl
|
|
|
c36ff1 |
|
|
|
c36ff1 |
LOG = logging.getLogger(__name__)
|
|
|
c36ff1 |
@@ -986,10 +986,11 @@ class EphemeralIPv4Network(object):
|
|
|
c36ff1 |
'Cannot init network on {0} with {1}/{2} and bcast {3}'.format(
|
|
|
c36ff1 |
interface, ip, prefix_or_mask, broadcast))
|
|
|
c36ff1 |
try:
|
|
|
c36ff1 |
- self.prefix = mask_to_net_prefix(prefix_or_mask)
|
|
|
c36ff1 |
+ self.prefix = ipv4_mask_to_net_prefix(prefix_or_mask)
|
|
|
c36ff1 |
except ValueError as e:
|
|
|
c36ff1 |
raise ValueError(
|
|
|
c36ff1 |
- 'Cannot setup network: {0}'.format(e)
|
|
|
c36ff1 |
+ "Cannot setup network, invalid prefix or "
|
|
|
c36ff1 |
+ "netmask: {0}".format(e)
|
|
|
c36ff1 |
) from e
|
|
|
c36ff1 |
|
|
|
c36ff1 |
self.connectivity_url = connectivity_url
|
|
|
c36ff1 |
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
|
|
|
c36ff1 |
index e8bf9e39..2768ef94 100644
|
|
|
c36ff1 |
--- a/cloudinit/net/network_state.py
|
|
|
c36ff1 |
+++ b/cloudinit/net/network_state.py
|
|
|
c36ff1 |
@@ -6,6 +6,7 @@
|
|
|
c36ff1 |
|
|
|
c36ff1 |
import copy
|
|
|
c36ff1 |
import functools
|
|
|
c36ff1 |
+import ipaddress
|
|
|
c36ff1 |
import logging
|
|
|
c36ff1 |
import socket
|
|
|
c36ff1 |
import struct
|
|
|
c36ff1 |
@@ -872,12 +873,18 @@ def _normalize_net_keys(network, address_keys=()):
|
|
|
c36ff1 |
try:
|
|
|
c36ff1 |
prefix = int(maybe_prefix)
|
|
|
c36ff1 |
except ValueError:
|
|
|
c36ff1 |
- # this supports input of <address>/255.255.255.0
|
|
|
c36ff1 |
- prefix = mask_to_net_prefix(maybe_prefix)
|
|
|
c36ff1 |
- elif netmask:
|
|
|
c36ff1 |
- prefix = mask_to_net_prefix(netmask)
|
|
|
c36ff1 |
- elif 'prefix' in net:
|
|
|
c36ff1 |
- prefix = int(net['prefix'])
|
|
|
c36ff1 |
+ if ipv6:
|
|
|
c36ff1 |
+ # this supports input of ffff:ffff:ffff::
|
|
|
c36ff1 |
+ prefix = ipv6_mask_to_net_prefix(maybe_prefix)
|
|
|
c36ff1 |
+ else:
|
|
|
c36ff1 |
+ # this supports input of 255.255.255.0
|
|
|
c36ff1 |
+ prefix = ipv4_mask_to_net_prefix(maybe_prefix)
|
|
|
c36ff1 |
+ elif netmask and not ipv6:
|
|
|
c36ff1 |
+ prefix = ipv4_mask_to_net_prefix(netmask)
|
|
|
c36ff1 |
+ elif netmask and ipv6:
|
|
|
c36ff1 |
+ prefix = ipv6_mask_to_net_prefix(netmask)
|
|
|
c36ff1 |
+ elif "prefix" in net:
|
|
|
c36ff1 |
+ prefix = int(net["prefix"])
|
|
|
c36ff1 |
else:
|
|
|
c36ff1 |
prefix = 64 if ipv6 else 24
|
|
|
c36ff1 |
|
|
|
c36ff1 |
@@ -972,72 +979,42 @@ def ipv4_mask_to_net_prefix(mask):
|
|
|
c36ff1 |
str(24) => 24
|
|
|
c36ff1 |
"24" => 24
|
|
|
c36ff1 |
"""
|
|
|
c36ff1 |
- if isinstance(mask, int):
|
|
|
c36ff1 |
- return mask
|
|
|
c36ff1 |
- if isinstance(mask, str):
|
|
|
c36ff1 |
- try:
|
|
|
c36ff1 |
- return int(mask)
|
|
|
c36ff1 |
- except ValueError:
|
|
|
c36ff1 |
- pass
|
|
|
c36ff1 |
- else:
|
|
|
c36ff1 |
- raise TypeError("mask '%s' is not a string or int")
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- if '.' not in mask:
|
|
|
c36ff1 |
- raise ValueError("netmask '%s' does not contain a '.'" % mask)
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- toks = mask.split(".")
|
|
|
c36ff1 |
- if len(toks) != 4:
|
|
|
c36ff1 |
- raise ValueError("netmask '%s' had only %d parts" % (mask, len(toks)))
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- return sum([bin(int(x)).count('1') for x in toks])
|
|
|
c36ff1 |
+ return ipaddress.ip_network(f"0.0.0.0/{mask}").prefixlen
|
|
|
c36ff1 |
|
|
|
c36ff1 |
|
|
|
c36ff1 |
def ipv6_mask_to_net_prefix(mask):
|
|
|
c36ff1 |
"""Convert an ipv6 netmask (very uncommon) or prefix (64) to prefix.
|
|
|
c36ff1 |
|
|
|
c36ff1 |
- If 'mask' is an integer or string representation of one then
|
|
|
c36ff1 |
- int(mask) will be returned.
|
|
|
c36ff1 |
+ If the input is already an integer or a string representation of
|
|
|
c36ff1 |
+ an integer, then int(mask) will be returned.
|
|
|
c36ff1 |
+ "ffff:ffff:ffff::" => 48
|
|
|
c36ff1 |
+ "48" => 48
|
|
|
c36ff1 |
"""
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- if isinstance(mask, int):
|
|
|
c36ff1 |
- return mask
|
|
|
c36ff1 |
- if isinstance(mask, str):
|
|
|
c36ff1 |
- try:
|
|
|
c36ff1 |
- return int(mask)
|
|
|
c36ff1 |
- except ValueError:
|
|
|
c36ff1 |
- pass
|
|
|
c36ff1 |
- else:
|
|
|
c36ff1 |
- raise TypeError("mask '%s' is not a string or int")
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- if ':' not in mask:
|
|
|
c36ff1 |
- raise ValueError("mask '%s' does not have a ':'")
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- bitCount = [0, 0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00,
|
|
|
c36ff1 |
- 0xff00, 0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc,
|
|
|
c36ff1 |
- 0xfffe, 0xffff]
|
|
|
c36ff1 |
- prefix = 0
|
|
|
c36ff1 |
- for word in mask.split(':'):
|
|
|
c36ff1 |
- if not word or int(word, 16) == 0:
|
|
|
c36ff1 |
- break
|
|
|
c36ff1 |
- prefix += bitCount.index(int(word, 16))
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- return prefix
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
-def mask_to_net_prefix(mask):
|
|
|
c36ff1 |
- """Return the network prefix for the netmask provided.
|
|
|
c36ff1 |
-
|
|
|
c36ff1 |
- Supports ipv4 or ipv6 netmasks."""
|
|
|
c36ff1 |
try:
|
|
|
c36ff1 |
- # if 'mask' is a prefix that is an integer.
|
|
|
c36ff1 |
- # then just return it.
|
|
|
c36ff1 |
- return int(mask)
|
|
|
c36ff1 |
+ # In the case the mask is already a prefix
|
|
|
c36ff1 |
+ prefixlen = ipaddress.ip_network(f"::/{mask}").prefixlen
|
|
|
c36ff1 |
+ return prefixlen
|
|
|
c36ff1 |
except ValueError:
|
|
|
c36ff1 |
+ # ValueError means mask is an IPv6 address representation and need
|
|
|
c36ff1 |
+ # conversion.
|
|
|
c36ff1 |
pass
|
|
|
c36ff1 |
- if is_ipv6_addr(mask):
|
|
|
c36ff1 |
- return ipv6_mask_to_net_prefix(mask)
|
|
|
c36ff1 |
- else:
|
|
|
c36ff1 |
- return ipv4_mask_to_net_prefix(mask)
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ netmask = ipaddress.ip_address(mask)
|
|
|
c36ff1 |
+ mask_int = int(netmask)
|
|
|
c36ff1 |
+ # If the mask is all zeroes, just return it
|
|
|
c36ff1 |
+ if mask_int == 0:
|
|
|
c36ff1 |
+ return mask_int
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ trailing_zeroes = min(
|
|
|
c36ff1 |
+ ipaddress.IPV6LENGTH, (~mask_int & (mask_int - 1)).bit_length()
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ leading_ones = mask_int >> trailing_zeroes
|
|
|
c36ff1 |
+ prefixlen = ipaddress.IPV6LENGTH - trailing_zeroes
|
|
|
c36ff1 |
+ all_ones = (1 << prefixlen) - 1
|
|
|
c36ff1 |
+ if leading_ones != all_ones:
|
|
|
c36ff1 |
+ raise ValueError("Invalid network mask '%s'" % mask)
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ return prefixlen
|
|
|
c36ff1 |
|
|
|
c36ff1 |
|
|
|
c36ff1 |
def mask_and_ipv4_to_bcast_addr(mask, ip):
|
|
|
c36ff1 |
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
|
|
|
c36ff1 |
index d5440998..7ecbe1c3 100644
|
|
|
c36ff1 |
--- a/cloudinit/net/sysconfig.py
|
|
|
c36ff1 |
+++ b/cloudinit/net/sysconfig.py
|
|
|
c36ff1 |
@@ -12,6 +12,7 @@ from cloudinit import util
|
|
|
c36ff1 |
from cloudinit import subp
|
|
|
c36ff1 |
from cloudinit.distros.parsers import networkmanager_conf
|
|
|
c36ff1 |
from cloudinit.distros.parsers import resolv_conf
|
|
|
c36ff1 |
+from cloudinit.net import network_state
|
|
|
c36ff1 |
|
|
|
c36ff1 |
from . import renderer
|
|
|
c36ff1 |
from .network_state import (
|
|
|
c36ff1 |
@@ -171,43 +172,61 @@ class Route(ConfigMap):
|
|
|
c36ff1 |
# (because Route can contain a mix of IPv4 and IPv6)
|
|
|
c36ff1 |
reindex = -1
|
|
|
c36ff1 |
for key in sorted(self._conf.keys()):
|
|
|
c36ff1 |
- if 'ADDRESS' in key:
|
|
|
c36ff1 |
- index = key.replace('ADDRESS', '')
|
|
|
c36ff1 |
- address_value = str(self._conf[key])
|
|
|
c36ff1 |
- # only accept combinations:
|
|
|
c36ff1 |
- # if proto ipv6 only display ipv6 routes
|
|
|
c36ff1 |
- # if proto ipv4 only display ipv4 routes
|
|
|
c36ff1 |
- # do not add ipv6 routes if proto is ipv4
|
|
|
c36ff1 |
- # do not add ipv4 routes if proto is ipv6
|
|
|
c36ff1 |
- # (this array will contain a mix of ipv4 and ipv6)
|
|
|
c36ff1 |
- if proto == "ipv4" and not self.is_ipv6_route(address_value):
|
|
|
c36ff1 |
- netmask_value = str(self._conf['NETMASK' + index])
|
|
|
c36ff1 |
- gateway_value = str(self._conf['GATEWAY' + index])
|
|
|
c36ff1 |
- # increase IPv4 index
|
|
|
c36ff1 |
- reindex = reindex + 1
|
|
|
c36ff1 |
- buf.write("%s=%s\n" % ('ADDRESS' + str(reindex),
|
|
|
c36ff1 |
- _quote_value(address_value)))
|
|
|
c36ff1 |
- buf.write("%s=%s\n" % ('GATEWAY' + str(reindex),
|
|
|
c36ff1 |
- _quote_value(gateway_value)))
|
|
|
c36ff1 |
- buf.write("%s=%s\n" % ('NETMASK' + str(reindex),
|
|
|
c36ff1 |
- _quote_value(netmask_value)))
|
|
|
c36ff1 |
- metric_key = 'METRIC' + index
|
|
|
c36ff1 |
- if metric_key in self._conf:
|
|
|
c36ff1 |
- metric_value = str(self._conf['METRIC' + index])
|
|
|
c36ff1 |
- buf.write("%s=%s\n" % ('METRIC' + str(reindex),
|
|
|
c36ff1 |
- _quote_value(metric_value)))
|
|
|
c36ff1 |
- elif proto == "ipv6" and self.is_ipv6_route(address_value):
|
|
|
c36ff1 |
- netmask_value = str(self._conf['NETMASK' + index])
|
|
|
c36ff1 |
- gateway_value = str(self._conf['GATEWAY' + index])
|
|
|
c36ff1 |
- metric_value = (
|
|
|
c36ff1 |
- 'metric ' + str(self._conf['METRIC' + index])
|
|
|
c36ff1 |
- if 'METRIC' + index in self._conf else '')
|
|
|
c36ff1 |
+ if "ADDRESS" not in key:
|
|
|
c36ff1 |
+ continue
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ index = key.replace("ADDRESS", "")
|
|
|
c36ff1 |
+ address_value = str(self._conf[key])
|
|
|
c36ff1 |
+ netmask_value = str(self._conf["NETMASK" + index])
|
|
|
c36ff1 |
+ gateway_value = str(self._conf["GATEWAY" + index])
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ # only accept combinations:
|
|
|
c36ff1 |
+ # if proto ipv6 only display ipv6 routes
|
|
|
c36ff1 |
+ # if proto ipv4 only display ipv4 routes
|
|
|
c36ff1 |
+ # do not add ipv6 routes if proto is ipv4
|
|
|
c36ff1 |
+ # do not add ipv4 routes if proto is ipv6
|
|
|
c36ff1 |
+ # (this array will contain a mix of ipv4 and ipv6)
|
|
|
c36ff1 |
+ if proto == "ipv4" and not self.is_ipv6_route(address_value):
|
|
|
c36ff1 |
+ # increase IPv4 index
|
|
|
c36ff1 |
+ reindex = reindex + 1
|
|
|
c36ff1 |
+ buf.write(
|
|
|
c36ff1 |
+ "%s=%s\n"
|
|
|
c36ff1 |
+ % ("ADDRESS" + str(reindex), _quote_value(address_value))
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ buf.write(
|
|
|
c36ff1 |
+ "%s=%s\n"
|
|
|
c36ff1 |
+ % ("GATEWAY" + str(reindex), _quote_value(gateway_value))
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ buf.write(
|
|
|
c36ff1 |
+ "%s=%s\n"
|
|
|
c36ff1 |
+ % ("NETMASK" + str(reindex), _quote_value(netmask_value))
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ metric_key = "METRIC" + index
|
|
|
c36ff1 |
+ if metric_key in self._conf:
|
|
|
c36ff1 |
+ metric_value = str(self._conf["METRIC" + index])
|
|
|
c36ff1 |
buf.write(
|
|
|
c36ff1 |
- "%s/%s via %s %s dev %s\n" % (address_value,
|
|
|
c36ff1 |
- netmask_value,
|
|
|
c36ff1 |
- gateway_value,
|
|
|
c36ff1 |
- metric_value,
|
|
|
c36ff1 |
- self._route_name))
|
|
|
c36ff1 |
+ "%s=%s\n"
|
|
|
c36ff1 |
+ % ("METRIC" + str(reindex), _quote_value(metric_value))
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ elif proto == "ipv6" and self.is_ipv6_route(address_value):
|
|
|
c36ff1 |
+ prefix_value = network_state.ipv6_mask_to_net_prefix(
|
|
|
c36ff1 |
+ netmask_value
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ metric_value = (
|
|
|
c36ff1 |
+ "metric " + str(self._conf["METRIC" + index])
|
|
|
c36ff1 |
+ if "METRIC" + index in self._conf
|
|
|
c36ff1 |
+ else ""
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ buf.write(
|
|
|
c36ff1 |
+ "%s/%s via %s %s dev %s\n"
|
|
|
c36ff1 |
+ % (
|
|
|
c36ff1 |
+ address_value,
|
|
|
c36ff1 |
+ prefix_value,
|
|
|
c36ff1 |
+ gateway_value,
|
|
|
c36ff1 |
+ metric_value,
|
|
|
c36ff1 |
+ self._route_name,
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
+ )
|
|
|
c36ff1 |
|
|
|
c36ff1 |
return buf.getvalue()
|
|
|
c36ff1 |
|
|
|
c36ff1 |
diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py
|
|
|
c36ff1 |
index 730ec586..e7980ab1 100644
|
|
|
c36ff1 |
--- a/cloudinit/sources/DataSourceOpenNebula.py
|
|
|
c36ff1 |
+++ b/cloudinit/sources/DataSourceOpenNebula.py
|
|
|
c36ff1 |
@@ -233,7 +233,7 @@ class OpenNebulaNetwork(object):
|
|
|
c36ff1 |
# Set IPv4 address
|
|
|
c36ff1 |
devconf['addresses'] = []
|
|
|
c36ff1 |
mask = self.get_mask(c_dev)
|
|
|
c36ff1 |
- prefix = str(net.mask_to_net_prefix(mask))
|
|
|
c36ff1 |
+ prefix = str(net.ipv4_mask_to_net_prefix(mask))
|
|
|
c36ff1 |
devconf['addresses'].append(
|
|
|
c36ff1 |
self.get_ip(c_dev, mac) + '/' + prefix)
|
|
|
c36ff1 |
|
|
|
c36ff1 |
diff --git a/cloudinit/sources/helpers/vmware/imc/config_nic.py b/cloudinit/sources/helpers/vmware/imc/config_nic.py
|
|
|
c36ff1 |
index 9cd2c0c0..3a45c67e 100644
|
|
|
c36ff1 |
--- a/cloudinit/sources/helpers/vmware/imc/config_nic.py
|
|
|
c36ff1 |
+++ b/cloudinit/sources/helpers/vmware/imc/config_nic.py
|
|
|
c36ff1 |
@@ -9,7 +9,7 @@ import logging
|
|
|
c36ff1 |
import os
|
|
|
c36ff1 |
import re
|
|
|
c36ff1 |
|
|
|
c36ff1 |
-from cloudinit.net.network_state import mask_to_net_prefix
|
|
|
c36ff1 |
+from cloudinit.net.network_state import ipv4_mask_to_net_prefix
|
|
|
c36ff1 |
from cloudinit import subp
|
|
|
c36ff1 |
from cloudinit import util
|
|
|
c36ff1 |
|
|
|
c36ff1 |
@@ -180,7 +180,7 @@ class NicConfigurator(object):
|
|
|
c36ff1 |
"""
|
|
|
c36ff1 |
route_list = []
|
|
|
c36ff1 |
|
|
|
c36ff1 |
- cidr = mask_to_net_prefix(netmask)
|
|
|
c36ff1 |
+ cidr = ipv4_mask_to_net_prefix(netmask)
|
|
|
c36ff1 |
|
|
|
c36ff1 |
for gateway in gateways:
|
|
|
c36ff1 |
destination = "%s/%d" % (gen_subnet(gateway, netmask), cidr)
|
|
|
c36ff1 |
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
|
|
|
c36ff1 |
index c67b5fcc..0bc547af 100644
|
|
|
c36ff1 |
--- a/tests/unittests/test_net.py
|
|
|
c36ff1 |
+++ b/tests/unittests/test_net.py
|
|
|
c36ff1 |
@@ -2025,10 +2025,10 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
|
|
|
c36ff1 |
routes:
|
|
|
c36ff1 |
- gateway: 2001:67c:1562:1
|
|
|
c36ff1 |
network: 2001:67c:1
|
|
|
c36ff1 |
- netmask: ffff:ffff:0
|
|
|
c36ff1 |
+ netmask: "ffff:ffff::"
|
|
|
c36ff1 |
- gateway: 3001:67c:1562:1
|
|
|
c36ff1 |
network: 3001:67c:1
|
|
|
c36ff1 |
- netmask: ffff:ffff:0
|
|
|
c36ff1 |
+ netmask: "ffff:ffff::"
|
|
|
c36ff1 |
metric: 10000
|
|
|
c36ff1 |
"""),
|
|
|
c36ff1 |
'expected_netplan': textwrap.dedent("""
|
|
|
c36ff1 |
@@ -2295,8 +2295,8 @@ iface bond0 inet6 static
|
|
|
c36ff1 |
'route6-bond0': textwrap.dedent("""\
|
|
|
c36ff1 |
# Created by cloud-init on instance boot automatically, do not edit.
|
|
|
c36ff1 |
#
|
|
|
c36ff1 |
- 2001:67c:1/ffff:ffff:0 via 2001:67c:1562:1 dev bond0
|
|
|
c36ff1 |
- 3001:67c:1/ffff:ffff:0 via 3001:67c:1562:1 metric 10000 dev bond0
|
|
|
c36ff1 |
+ 2001:67c:1/32 via 2001:67c:1562:1 dev bond0
|
|
|
c36ff1 |
+ 3001:67c:1/32 via 3001:67c:1562:1 metric 10000 dev bond0
|
|
|
c36ff1 |
"""),
|
|
|
c36ff1 |
'route-bond0': textwrap.dedent("""\
|
|
|
c36ff1 |
ADDRESS0=10.1.3.0
|
|
|
c36ff1 |
@@ -3084,6 +3084,76 @@ USERCTL=no
|
|
|
c36ff1 |
renderer.render_network_state(ns, target=render_dir)
|
|
|
c36ff1 |
self.assertEqual([], os.listdir(render_dir))
|
|
|
c36ff1 |
|
|
|
c36ff1 |
+ def test_invalid_network_mask_ipv6(self):
|
|
|
c36ff1 |
+ net_json = {
|
|
|
c36ff1 |
+ "services": [{"type": "dns", "address": "172.19.0.12"}],
|
|
|
c36ff1 |
+ "networks": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "network_id": "public-ipv6",
|
|
|
c36ff1 |
+ "type": "ipv6",
|
|
|
c36ff1 |
+ "netmask": "",
|
|
|
c36ff1 |
+ "link": "tap1a81968a-79",
|
|
|
c36ff1 |
+ "routes": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "gateway": "2001:DB8::1",
|
|
|
c36ff1 |
+ "netmask": "ff:ff:ff:ff::",
|
|
|
c36ff1 |
+ "network": "2001:DB8:1::1",
|
|
|
c36ff1 |
+ },
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ "ip_address": "2001:DB8::10",
|
|
|
c36ff1 |
+ "id": "network1",
|
|
|
c36ff1 |
+ }
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ "links": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "ethernet_mac_address": "fa:16:3e:ed:9a:59",
|
|
|
c36ff1 |
+ "mtu": None,
|
|
|
c36ff1 |
+ "type": "bridge",
|
|
|
c36ff1 |
+ "id": "tap1a81968a-79",
|
|
|
c36ff1 |
+ "vif_id": "1a81968a-797a-400f-8a80-567f997eb93f",
|
|
|
c36ff1 |
+ },
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ }
|
|
|
c36ff1 |
+ macs = {"fa:16:3e:ed:9a:59": "eth0"}
|
|
|
c36ff1 |
+ network_cfg = openstack.convert_net_json(net_json, known_macs=macs)
|
|
|
c36ff1 |
+ with self.assertRaises(ValueError):
|
|
|
c36ff1 |
+ network_state.parse_net_config_data(network_cfg, skip_broken=False)
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
+ def test_invalid_network_mask_ipv4(self):
|
|
|
c36ff1 |
+ net_json = {
|
|
|
c36ff1 |
+ "services": [{"type": "dns", "address": "172.19.0.12"}],
|
|
|
c36ff1 |
+ "networks": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "network_id": "public-ipv4",
|
|
|
c36ff1 |
+ "type": "ipv4",
|
|
|
c36ff1 |
+ "netmask": "",
|
|
|
c36ff1 |
+ "link": "tap1a81968a-79",
|
|
|
c36ff1 |
+ "routes": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "gateway": "172.20.0.1",
|
|
|
c36ff1 |
+ "netmask": "255.234.255.0",
|
|
|
c36ff1 |
+ "network": "172.19.0.0",
|
|
|
c36ff1 |
+ },
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ "ip_address": "172.20.0.10",
|
|
|
c36ff1 |
+ "id": "network1",
|
|
|
c36ff1 |
+ }
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ "links": [
|
|
|
c36ff1 |
+ {
|
|
|
c36ff1 |
+ "ethernet_mac_address": "fa:16:3e:ed:9a:59",
|
|
|
c36ff1 |
+ "mtu": None,
|
|
|
c36ff1 |
+ "type": "bridge",
|
|
|
c36ff1 |
+ "id": "tap1a81968a-79",
|
|
|
c36ff1 |
+ "vif_id": "1a81968a-797a-400f-8a80-567f997eb93f",
|
|
|
c36ff1 |
+ },
|
|
|
c36ff1 |
+ ],
|
|
|
c36ff1 |
+ }
|
|
|
c36ff1 |
+ macs = {"fa:16:3e:ed:9a:59": "eth0"}
|
|
|
c36ff1 |
+ network_cfg = openstack.convert_net_json(net_json, known_macs=macs)
|
|
|
c36ff1 |
+ with self.assertRaises(ValueError):
|
|
|
c36ff1 |
+ network_state.parse_net_config_data(network_cfg, skip_broken=False)
|
|
|
c36ff1 |
+
|
|
|
c36ff1 |
def test_openstack_rendering_samples(self):
|
|
|
c36ff1 |
for os_sample in OS_SAMPLES:
|
|
|
c36ff1 |
render_dir = self.tmp_dir()
|
|
|
c36ff1 |
--
|
|
|
c36ff1 |
2.27.0
|
|
|
c36ff1 |
|