From: Jiri Pirko jiri@mellanox.com
Extend ip_add and ip_del methods to accept lists. Example: self.matched.m1.if1.ip_add([ipaddress("192.168.101.10/24"), ipaddress("2002::1/64")])
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Devices/Device.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py index 6b2e35f..bd750a9 100644 --- a/lnst/Devices/Device.py +++ b/lnst/Devices/Device.py @@ -402,12 +402,7 @@ class Device(object): def _clear_ips(self): self._ip_addrs = []
- def ip_add(self, addr): - """add an ip address - - Args: - addr -- an address accepted by the ipaddress factory method - """ + def _ip_add_one(self, addr): ip = ipaddress(addr) if ip not in self.ips: with pyroute2.IPRoute() as ipr: @@ -418,14 +413,23 @@ class Device(object): except pyroute2.netlink.NetlinkError: log_exc_traceback() raise DeviceConfigValueError("Invalid IP address") - return ip
- def ip_del(self, addr): - """remove an ip address + def ip_add(self, addr): + """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 """ + + if isinstance(addr, list): + for oneaddr in addr: + self._ip_add_one(oneaddr) + else: + self._ip_add_one(addr) + + def _ip_del_one(self, addr): ip = ipaddress(addr) if ip in self.ips: with pyroute2.IPRoute() as ipr: @@ -437,6 +441,20 @@ class Device(object): log_exc_traceback() raise DeviceConfigValueError("Invalid IP address")
+ def ip_del(self, addr): + """remove 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 + """ + if isinstance(addr, list): + for oneaddr in addr: + self._ip_del_one(oneaddr) + else: + self._ip_del_one(addr) + def ip_flush(self): """flush all ip addresses of the device""" with pyroute2.IPRoute() as ipr:
Wed, Sep 20, 2017 at 11:00:50AM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Extend ip_add and ip_del methods to accept lists. Example: self.matched.m1.if1.ip_add([ipaddress("192.168.101.10/24"), ipaddress("2002::1/64")])
Signed-off-by: Jiri Pirko jiri@mellanox.com
Self-applied.
lnst-developers@lists.fedorahosted.org