def test_get_one_by_ip(self):
     expected = ('web01', '192.168.1.101')
     self.create_test_role_data()
     self.create_test_ip_data()
     self.create_test_host_data()
     self.create_test_role_map_data()
     host = Host.get_one_by_ip(db.session.query, '192.168.1.101')
     actual = (host.host_name, host.ip)
     self.assertEqual(expected, actual)
Example #2
0
def search_by_ip(ipaddr):

    host = Host.get_one_by_ip(db.session.query, ipaddr)
    if not host:
        abort(404)

    role_maps = RoleMap.get_by_host_name(db.session.query, host.host_name)
    role_names = [r.role_name for r in role_maps]

    result = [dict(host_name=host.host_name, ip=host.ip, role=role_names)]
    return jsonify(result=result)