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

added coriant-info route

parent 1f9f6b68
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,10 @@ import ipaddress
import json
import re
from flask import Blueprint, Response
from flask import Blueprint, Response, current_app
from inventory_provider.routes import common
from inventory_provider.db import opsdb, db
routes = Blueprint("inventory-data-classifier-support-routes", __name__)
......@@ -277,3 +278,36 @@ def get_trap_metadata(source_equipment, interface, circuit_id):
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json")
@routes.route("/coriant-info/"
"<equipment_name>/<card_id>/<port_number>",
methods=['GET', 'POST'])
@common.require_accepts_json
def get_coriant_info(equipment_name, card_id, port_number):
r = common.get_redis()
cache_key = 'classifier-cache:coriant:%s:%s:%s' % (
equipment_name, card_id, port_number)
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
else:
config = current_app.config['INVENTORY_PROVIDER_CONFIG']
with db.connection(config['ops-db']) as cx:
result = opsdb.get_coriant_path(
cx, equipment_name, card_id, port_number)
if not result:
return Response(
response="no available info for {} {} {}".format(
equipment_name, card_id, port_number),
status=404,
mimetype="text/html")
result = json.dumps(result)
# cache this data for the next call
r.set(cache_key, result.encode('utf-8'))
return Response(result, 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