diff options
author | Harald <hjensas@redhat.com> | 2022-02-08 15:49:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 08:49:00 -0600 |
commit | b97a30f0a05c1dea918c46ca9c05c869d15fe2d5 (patch) | |
tree | 95e739f709fd130a8e35885875d048617836f757 /cloudinit/net/__init__.py | |
parent | 339c3b0977363afcf160c564cbf446c4093525fb (diff) | |
download | vyos-cloud-init-b97a30f0a05c1dea918c46ca9c05c869d15fe2d5.tar.gz vyos-cloud-init-b97a30f0a05c1dea918c46ca9c05c869d15fe2d5.zip |
Fix IPv6 netmask format for sysconfig (#1215)
This change converts the IPv6 netmask from the network_data.json[1]
format to the CIDR style, <IPv6_addr>/<prefix>.
Using an IPv6 address like ffff:ffff:ffff:ffff:: does not work with
NetworkManager, nor networkscripts.
NetworkManager will ignore the route, logging:
ifcfg-rh: ignoring invalid route at \
"::/:: via fd00:fd00:fd00:2::fffe dev $DEV" \
(/etc/sysconfig/network-scripts/route6-$DEV:3): \
Argument for "::/::" is not ADDR/PREFIX format
Similarly if using networkscripts, ip route fail with error:
Error: inet6 prefix is expected rather than \
"fd00:fd00:fd00::/ffff:ffff:ffff:ffff::".
Also a bit of refactoring ...
cloudinit.net.sysconfig.Route.to_string:
* Move a couple of lines around to reduce repeated code.
* if "ADDRESS" not in key -> continute, so that the
code block following it can be de-indented.
cloudinit.net.network_state:
* Refactors the ipv4_mask_to_net_prefix, ipv6_mask_to_net_prefix
removes mask_to_net_prefix methods. Utilize ipaddress library to
do some of the heavy lifting.
LP: #1959148
Diffstat (limited to 'cloudinit/net/__init__.py')
-rw-r--r-- | cloudinit/net/__init__.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 1a738dbc..3270e1f7 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -14,7 +14,7 @@ import re from typing import Any, Dict from cloudinit import subp, util -from cloudinit.net.network_state import mask_to_net_prefix +from cloudinit.net.network_state import ipv4_mask_to_net_prefix from cloudinit.url_helper import UrlError, readurl LOG = logging.getLogger(__name__) @@ -1125,9 +1125,12 @@ class EphemeralIPv4Network(object): ) ) try: - self.prefix = mask_to_net_prefix(prefix_or_mask) + self.prefix = ipv4_mask_to_net_prefix(prefix_or_mask) except ValueError as e: - raise ValueError("Cannot setup network: {0}".format(e)) from e + raise ValueError( + "Cannot setup network, invalid prefix or " + "netmask: {0}".format(e) + ) from e self.connectivity_url_data = connectivity_url_data self.interface = interface |