Пример #1
0
 def test_update_host(self):
     self.mock_omapi_cli.query_server.side_effect = [
         OmapiMessage(opcode=OMAPI_OP_UPDATE),
         OmapiMessage(opcode=OMAPI_OP_STATUS),
     ]
     cli = OmapiClient("shared-key")
     cli.update_host("aa:bb:cc:dd:ee:ff", "1.2.3.4")
     # first call gets the existing entry by name
     self.assertEqual(
         self.mock_omapi_cli.query_server.mock_calls[0].args[0].obj,
         [(b"name", b"aa-bb-cc-dd-ee-ff")],
     )
     # second call updates the IP address
     self.assertEqual(
         self.mock_omapi_cli.query_server.mock_calls[1].args[0].obj,
         [(b"ip-address", b"\x01\x02\x03\x04")],
     )
Пример #2
0
def _update_hosts(server, remove, add, modify):
    """Update the hosts using the OMAPI."""
    omapi_client = OmapiClient(server.omapi_key, server.ipv6)
    try:
        for host in remove:
            omapi_client.del_host(host["mac"])
    except OmapiError as e:
        raise CannotRemoveHostMap(str(e))
    try:
        for host in add:
            omapi_client.add_host(host["mac"], host["ip"])
    except OmapiError as e:
        raise CannotCreateHostMap(str(e))
    try:
        for host in modify:
            omapi_client.update_host(host["mac"], host["ip"])
    except OmapiError as e:
        raise CannotModifyHostMap(str(e))