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

added sample bgp info route

parent 91cec3e0
No related branches found
No related tags found
No related merge requests found
......@@ -104,3 +104,32 @@ def debug_dump_router_info(hostname):
return Response(
json.dumps(info),
mimetype="application/json")
@routes.route("/bgp/<hostname>", methods=['GET', 'POST'])
@require_accepts_json
def bgp_configs(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"]
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
bgp_data_string = r.hget(hostname, 'bgp')
if not bgp_data_string:
return Response(
response="no available bgp info for '%s'" % hostname,
status=404,
mimetype="text/html")
def _interfaces(s):
for ifc in json.loads(s):
yield {
"description": ifc["description"][0],
"as": {
"peer": ifc["peer-as"][0],
"local": ifc["local-as"][0]["as-number"][0]
}
}
interfaces = list(_interfaces(bgp_data_string.decode('utf-8')))
return Response(
json.dumps(interfaces),
mimetype="application/json")
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