From 5af9a6b2e1b4b57260fa40bc22dac102381f96d9 Mon Sep 17 00:00:00 2001 From: Maxim <55401893+Vatson112@users.noreply.github.com> Date: Fri, 22 Oct 2021 13:54:34 +0300 Subject: [PATCH] Add function for lookups host by ip Add function for lookups host by ip --- pypureomapi.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pypureomapi.py b/pypureomapi.py index bb870a4..5039a63 100644 --- a/pypureomapi.py +++ b/pypureomapi.py @@ -1143,7 +1143,25 @@ def lookup_host(self, name): return dict(ip=res["ip-address"], mac=res["hardware-address"], hostname=res["name"].decode('utf-8')) except KeyError: raise OmapiErrorAttributeNotFound() + + def lookup_host_by_ip(self, ip): + """Look for a host object with given ip address and return the + name, mac, and ip address + @type ip: str + @rtype: dict or None + @raises ValueError: + @raises OmapiError: + @raises OmapiErrorNotFound: if no host object with the given name could be found + @raises OmapiErrorAttributeNotFound: if lease could be found, but objects lacks ip, mac or name + @raises socket.error: + """ + res = self.lookup_by_host(ip=ip) + try: + return dict(ip=res["ip-address"], mac=res["hardware-address"], hostname=res["name"].decode('utf-8')) + except KeyError: + raise OmapiErrorAttributeNotFound() + def lookup_host_host(self, mac): """Look for a host object with given mac address and return the name, mac, and ip address