On Mon, 2018-05-21 at 10:42 +0200, olichtne(a)redhat.com wrote:
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:
If exception is raised by "getattr" function or comparison, variable
"match" is not set to False.
except:
match = False
pass
> + pass
> + if match:
> + result.append(addr)
> + return result
> +
> def up(self):
> """set device up"""
> with pyroute2.IPRoute() as ipr:
> --
> 2.17.0
> _______________________________________________
> LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.or
> g
> To unsubscribe send an email to lnst-developers-leave(a)lists.fedorahos
>
ted.org
> Fedora Code of Conduct:
https://getfedora.org/code-of-conduct.html
> List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelin
> es
> List Archives:
https://lists.fedoraproject.org/archives/list/lnst-dev
> elopers(a)lists.fedorahosted.org/message/3DFOTAMCHJXYA244TSY4DXEPDGOQNU
> GA/