From: Ondrej Lichtner <olichtne(a)redhat.com>
The method retuns a list of ip addresses that match the provided
selectors. The selectors are key=value pairs where 'key' is some
attribute of the ipaddress object, if an ipaddress object matches all
the selectors it is added to the return list of the method.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Devices/Device.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py
index 0f84a02..2fa4a58 100644
--- a/lnst/Devices/Device.py
+++ b/lnst/Devices/Device.py
@@ -521,6 +521,21 @@ class Device(object):
log_exc_traceback()
raise DeviceConfigError("IP address flush failed")
+ def ips_filter(self, **selectors):
+ result = []
+ for addr in self.ips:
+ match = True
+ for selector, value in selectors.items():
+ try:
+ if getattr(addr, selector) != value:
+ match = False
+ break
+ except:
+ pass
+ if match:
+ result.append(addr)
+ return result
+
def up(self):
"""set device up"""
with pyroute2.IPRoute() as ipr:
--
2.17.0