Skip to content

Commit

Permalink
Merge pull request #27 from sagarun/upstream-master
Browse files Browse the repository at this point in the history
Add a new method add_host_supersede
  • Loading branch information
cygnusb authored Sep 19, 2018
2 parents 6ff9784 + 7d1d771 commit 2354b6c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pypureomapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,42 @@ def lookup_hostname(self, ip):
except KeyError: # client hostname
raise OmapiErrorNotFound()

def add_host_supersede(self, ip, mac, name, hostname=None, router=None, domain=None):
"""Create a host object with given ip, mac, name, hostname, router and
domain. hostname, router and domain are optional arguments.
@type ip: str
@type mac: str
@type name: str
@type hostname: str
@type router: str
@type domain: str
@raises OmapiError:
@raises socket.error:
"""
stmts = []

msg = OmapiMessage.open(b"host")
msg.message.append((b"create", struct.pack("!I", 1)))
msg.obj.append((b"name", name))
msg.obj.append((b"hardware-address", pack_mac(mac)))
msg.obj.append((b"hardware-type", struct.pack("!I", 1)))
msg.obj.append((b"ip-address", pack_ip(ip)))
if hostname:
stmts.append('supersede host-name "{0}";\n '.format(hostname))
if router:
stmts.append('supersede routers {0};\n '.format(router))
if domain:
stmts.append('supersede domain-name "{0}";'.format(domain))
if stmts:
encoded_stmts = ''.join(stmts).encode('utf-8')
msg.obj.append((b"statements", encoded_stmts))

response = self.query_server(msg)
if response.opcode != OMAPI_OP_UPDATE:
raise OmapiError("add failed")


if __name__ == '__main__':
import doctest
doctest.testmod()

0 comments on commit 2354b6c

Please sign in to comment.