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

added /data/interfaces/<hostname> route

parent f8a185c3
No related branches found
No related tags found
No related merge requests found
......@@ -50,3 +50,36 @@ def routers():
return Response(
json.dumps(list([k.decode("utf-8") for k in r.keys("*")])),
mimetype="application/json")
@routes.route("/interfaces/<hostname>", methods=['GET', 'POST'])
@require_accepts_json
def router_interfaces(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, 'interfaces')
if not ifc_data_string:
return Response(
response="no available info for '%s'" % hostname,
status=404,
mimetype="text/html")
def _interfaces(s):
for ifc in json.loads(s):
if 'v4InterfaceName' in ifc:
yield ifc['v4InterfaceName']
if 'v6InterfaceName' in ifc:
yield ifc['v6InterfaceName']
interfaces = list(_interfaces(ifc_data_string.decode('utf-8')))
if not interfaces:
return Response(
response="no interfaces found for '%s'" % hostname,
status=404,
mimetype="text/html")
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