Skip to content
Snippets Groups Projects
Commit df07258c authored by Erik Reid's avatar Erik Reid
Browse files

add snmp id/ifcname map route

parent cf64eb60
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,7 @@ def router_interfaces(hostname):
status=404,
mimetype="text/html")
def _interfaces(s):
for ifc in json.loads(s):
if 'v4InterfaceName' in ifc:
......@@ -85,6 +86,36 @@ def router_interfaces(hostname):
mimetype="application/json")
@routes.route("/snmp/<hostname>", methods=['GET', 'POST'])
@require_accepts_json
def snmp_ids(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"]
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
ifc_data_string = r.hget(hostname, 'snmp-interfaces')
if not ifc_data_string:
return Response(
response="no available info for '%s'" % hostname,
status=404,
mimetype="text/html")
def _ifc_name(ifc):
if 'v4InterfaceName' in ifc:
return ifc['v4InterfaceName']
if 'v6InterfaceName' in ifc:
return ifc['v6InterfaceName']
assert False, "sanity failure: no interface name found"
ifc_data = json.loads(ifc_data_string.decode('utf-8'))
result = [
{ 'index': i['index'], 'name': _ifc_name(i)}
for i in ifc_data]
return Response(
json.dumps(result),
mimetype="application/json")
@routes.route("/debug-dump/<hostname>", methods=['GET', 'POST'])
@require_accepts_json
def debug_dump_router_info(hostname):
......
......@@ -254,6 +254,33 @@ def test_router_interfaces(client_with_mocked_data):
assert response # at least shouldn't be empty
def test_snmp_ids(client_with_mocked_data):
snmp_id_list_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {"type": "string"},
"name": {"type": "string"}
},
"required": ["index", "name"],
"additionalProperties": False
}
}
for hostname in _routers(client_with_mocked_data):
rv = client_with_mocked_data.post(
"/data/snmp/" + hostname,
headers=DEFAULT_REQUEST_HEADERS)
response = json.loads(rv.data.decode("utf-8"))
jsonschema.validate(response, snmp_id_list_schema)
assert response # at least shouldn't be empty
def test_router_bgp_route(client_with_mocked_data):
bgp_list_schema = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment