1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

python3: replacing ipaddr with custom ipnetwork.IPNetwork object

As mentioned in a previous commit:
python3 ipaddress behave differently from python2-ipaddr, this is
a serious problem for us since it breaks most of the ip addresses
code.

>>> import ipaddress
>>> ipaddress.ip_network("10.10.10.242/10", False)
IPv4Network('10.0.0.0/10')

This is a problem for us, so we need to use a custom IPNetwork object.
Our custom IPNetwork object uses ipaddress.IPAddress under the hood

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
Julien Fortin
2020-01-07 16:58:56 +01:00
parent 447796a6c3
commit 0e936c3ffa
13 changed files with 400 additions and 388 deletions

View File

@@ -26,7 +26,6 @@
#
from collections import OrderedDict
from ipaddr import IPv4Address, IPv6Address
from .nlpacket import *
from select import select
from struct import pack, unpack
@@ -371,14 +370,12 @@ class NetlinkManager(object):
data = data[length:]
def ip_to_afi(self, ip):
type_ip = type(ip)
if type_ip == IPv4Address:
if ip.version == 4:
return socket.AF_INET
elif type_ip == IPv6Address:
elif ip.version == 6:
return socket.AF_INET6
else:
raise Exception("%s is an invalid IP type" % type_ip)
raise Exception("%s is an invalid IP type" % type(ip))
def request_dump(self, rtm_type, family, debug):
"""
@@ -498,9 +495,7 @@ class NetlinkManager(object):
def route_get(self, ip, debug=False):
"""
ip must be one of the following:
- IPv4Address
- IPv6Address
ip must be ipnetwork.IPNetwork
"""
# Transmit a RTM_GETROUTE to query for the route we want
route = Route(RTM_GETROUTE, debug, use_color=self.use_color)