Skip to content

Commit

Permalink
Change lookup to generic lookup function
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusb committed Nov 3, 2018
1 parent e1d23d4 commit 89a5075
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions pypureomapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,15 +1132,7 @@ def lookup_ip(self, mac):
address could be found or the object lacks an ip address
@raises socket.error:
"""
msg = OmapiMessage.open(b"lease")
msg.obj.append((b"hardware-address", pack_mac(mac)))
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()
return self.lookup("lease", ["ip"], mac=mac)

def lookup_mac(self, ip):
"""Look up a lease object with given ip address and return the
Expand All @@ -1154,15 +1146,7 @@ def lookup_mac(self, ip):
address could be found or the object lacks a mac address
@raises socket.error:
"""
msg = OmapiMessage.open(b"lease")
msg.obj.append((b"ip-address", pack_ip(ip)))
response = self.query_server(msg)
if response.opcode != OMAPI_OP_UPDATE:
raise OmapiErrorNotFound()
try:
return unpack_mac(dict(response.obj)[b"hardware-address"])
except KeyError: # hardware-address
raise OmapiErrorNotFound()
return self.lookup("lease", ["mac"], ip=ip)

def lookup_host(self, name):
"""Look for a host object with given name and return the
Expand Down Expand Up @@ -1245,7 +1229,7 @@ def lookup(self, ltype, rvalues=[], ip=None, mac=None, name=None):
if response.opcode != OMAPI_OP_UPDATE:
raise OmapiErrorNotFound()
try:
print("response is ", dict(response.obj))
# print("response is ", dict(response.obj))
result = {}
for elem in rvalues:
if elem == "ip":
Expand Down

0 comments on commit 89a5075

Please sign in to comment.