From 6d3f9f3007f5f9d297ead17996b4c4cc1e78ef34 Mon Sep 17 00:00:00 2001 From: William Michael Turner Date: Mon, 23 Nov 2015 02:28:37 +0000 Subject: [PATCH 1/3] Added function 'lookup_ip_host' to lookup the IP address corresponding to a MAC address in a host entry --- pypureomapi.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pypureomapi.py b/pypureomapi.py index c5cd600..47f9aea 100644 --- a/pypureomapi.py +++ b/pypureomapi.py @@ -1090,6 +1090,25 @@ def del_host(self, mac): if response.opcode != OMAPI_OP_STATUS: raise OmapiError("delete failed") + def lookup_ip_host(self, mac): + """Lookup a host object with with given mac address. + + @type mac: str + @raises ValueError: + @raises OmapiError: + @raises socket.error: + """ + msg = OmapiMessage.open(b"host") + msg.obj.append((b"hardware-address", pack_mac(mac))) + msg.obj.append((b"hardware-type", struct.pack("!I", 1))) + response = self.query_server(msg) + if response.opcode != OMAPI_OP_UPDATE: + raise OmapiErrorNotFound() + try: + return unpack_ip(dict(response.obj)[b"ip-address"]) + except KeyError: # ip-address + raise OmapiErrorNotFound() + def lookup_ip(self, mac): """Look for a lease object with given mac address and return the assigned ip address. From 0ba51e00d8b1483bc0a86daee0c7230b862c07b4 Mon Sep 17 00:00:00 2001 From: William Michael Turner Date: Mon, 23 Nov 2015 02:42:03 +0000 Subject: [PATCH 2/3] Updated README to include newly added lookup_ip_host function --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 994e0b0..04225bd 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,29 @@ def get_lease(omapi, ip): return response ``` +#Get an IP from a host MAC address + +``` +def lookup_ip_host(self, mac): + """Lookup a host object with with given mac address. + + @type mac: str + @raises ValueError: + @raises OmapiError: + @raises socket.error: + """ + msg = OmapiMessage.open(b"host") + msg.obj.append((b"hardware-address", pack_mac(mac))) + msg.obj.append((b"hardware-type", struct.pack("!I", 1))) + response = self.query_server(msg) + if response.opcode != OMAPI_OP_UPDATE: + raise OmapiErrorNotFound() + try: + return unpack_ip(dict(response.obj)[b"ip-address"]) + except KeyError: # ip-address + raise OmapiErrorNotFound() +``` + #Change Group ``` From 8585f40903e4f2fcbcaddf434122f68c52e65a29 Mon Sep 17 00:00:00 2001 From: William Michael Turner Date: Mon, 23 Nov 2015 02:53:54 +0000 Subject: [PATCH 3/3] Fixed tabbing issue --- pypureomapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypureomapi.py b/pypureomapi.py index 47f9aea..dcaf20b 100644 --- a/pypureomapi.py +++ b/pypureomapi.py @@ -1090,7 +1090,7 @@ def del_host(self, mac): if response.opcode != OMAPI_OP_STATUS: raise OmapiError("delete failed") - def lookup_ip_host(self, mac): + def lookup_ip_host(self, mac): """Lookup a host object with with given mac address. @type mac: str