From: Ondrej Lichtner <olichtne(a)redhat.com>
This optional attribute can store flags as provided by the kernel, this
can be used for example for checking if an address is tentative as is
the case for IPv6 addresses that haven't been DAD checked yet.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/IpAddress.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index 54c3735..d8aabcc 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -19,9 +19,10 @@
#network
class BaseIpAddress(object):
- def __init__(self, addr):
+ def __init__(self, addr, flags=None):
self.addr, self.prefixlen = self._parse_addr(addr)
+ self.flags = flags
self.family = None
def __str__(self):
@@ -52,8 +53,8 @@ def __repr__(self):
return "{}({}/{})".format(self.__class__.__name__, str(self),
self.prefixlen)
class Ip4Address(BaseIpAddress):
- def __init__(self, addr):
- super(Ip4Address, self).__init__(addr)
+ def __init__(self, addr, flags=None):
+ super(Ip4Address, self).__init__(addr, flags)
self.family = AF_INET
@@ -82,8 +83,8 @@ def is_multicast(self):
return aton("224.0.0.0") <= self.addr <=
aton("239.255.255.255")
class Ip6Address(BaseIpAddress):
- def __init__(self, addr):
- super(Ip6Address, self).__init__(addr)
+ def __init__(self, addr, flags=None):
+ super(Ip6Address, self).__init__(addr, flags)
self.family = AF_INET6
@@ -114,15 +115,15 @@ def is_link_local(self):
def is_multicast(self):
return self.addr[:1] == b'\xff'
-def ipaddress(addr):
+def ipaddress(addr, flags=None):
"""Factory method to create a BaseIpAddress object"""
if isinstance(addr, BaseIpAddress):
return addr
elif isinstance(addr, str):
try:
- return Ip4Address(addr)
+ return Ip4Address(addr, flags)
except:
- return Ip6Address(addr)
+ return Ip6Address(addr, flags)
else:
raise LnstError("Value must be a BaseIpAddress or string object."
" Not {}".format(type(addr)))
--
2.22.0