The addr parameter of the _ip_add_one() method can now take either a string
specifying a device address or a tuple that includes both the device address
and peer address to support point-to-point networks.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Devices/Device.py | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py
index 68b5f1af..b98d9235 100644
--- a/lnst/Devices/Device.py
+++ b/lnst/Devices/Device.py
@@ -569,15 +569,30 @@ class Device(object, metaclass=DeviceMeta):
self._ip_addrs = []
def _ip_add_one(self, addr):
- ip = ipaddress(addr)
+ if type(addr) is tuple:
+ ip = ipaddress(addr[0])
+ peer = ipaddress(addr[1])
+ else:
+ ip = ipaddress(addr)
+ peer = None
+
if ip not in self.ips:
- self._ipr_wrapper("addr", "add", index=self.ifindex,
- address=str(ip), mask=ip.prefixlen)
+ kwargs = dict(
+ index=self.ifindex,
+ local=str(ip),
+ address=str(ip),
+ mask=ip.prefixlen
+ )
+ if peer:
+ kwargs['address'] = str(peer)
+
+ self._ipr_wrapper("addr", "add", **kwargs)
+
for i in range(5):
logging.debug("Waiting for ip address to be added {} of
5".format(i))
time.sleep(1)
self._if_manager.rescan_devices()
- if addr in self.ips:
+ if ip in self.ips:
break
else:
raise DeviceError("Failed to configure ip address
{}".format(str(ip)))
@@ -586,9 +601,9 @@ class Device(object, metaclass=DeviceMeta):
"""add an ip address or a list of ip addresses
Args:
- addr -- an address accepted by the ipaddress factory method
- or a list of addresses accepted by the ipaddress
- factory method
+ addr -- an address or a tuple (address, peer_address) accepted
+ by the ipaddress factory method or a list of the previous
+ two types
"""
if isinstance(addr, list):
--
2.26.3