From a9d0769fe88c5f13e469b0bb8a8ecb562475bcba Mon Sep 17 00:00:00 2001 From: shirenn Date: Mon, 14 Nov 2022 17:04:01 +0100 Subject: [PATCH] Easier option to query single ipv4 and ipv6 --- lookup_plugins/ldap.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lookup_plugins/ldap.py b/lookup_plugins/ldap.py index 5baf7dbf..42501ffd 100644 --- a/lookup_plugins/ldap.py +++ b/lookup_plugins/ldap.py @@ -62,18 +62,18 @@ class LookupModule(LookupBase): def ip4(self, host, vlan): """ - Retrieve the first IP addresses of an interface of a device + Retrieve the first IPv4 addresse of an interface of a device query('ldap', 'ip4', HOST, VLAN) """ - result = [res for res in self.ip(host, vlan) if ipaddress.ip_address(res).version == 4 ] + result = [ res for res in self.ip(host, vlan) if ipaddress.ip_address(res).version == 4 ] return result[0] def ip6(self, host, vlan): """ - Retrieve IP addresses of an interface of a device - query('ldap', 'ip', HOST, VLAN) + Retrieve the first IPv6 addresse of an interface of a device + query('ldap', 'ip6', HOST, VLAN) """ - result = [res for res in self.ip(host, vlan) if ipaddress.ip_address(res).version == 6 ] + result = [ res for res in self.ip(host, vlan) if ipaddress.ip_address(res).version == 6 ] return result[0] def all_ip(self, host): @@ -157,6 +157,10 @@ class LookupModule(LookupBase): result = self.query(*terms[1:]) elif terms[0] == 'ip': result = self.ip(*terms[1:]) + elif terms[0] == 'ip4': + result = self.ip4(*terms[1:]) + elif terms[0] == 'ip6': + result = self.ip6(*terms[1:]) elif terms[0] == 'all_ip': result = self.all_ip(*terms[1:]) elif terms[0] == 'cn':