Skip to content

Commit

Permalink
Merge pull request #16 from wmturner/master
Browse files Browse the repository at this point in the history
Lookup IP by host object MAC address
  • Loading branch information
cygnusb committed Nov 23, 2015
2 parents 54453d5 + 8585f40 commit 8637337
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
19 changes: 19 additions & 0 deletions pypureomapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8637337

Please sign in to comment.