Skip to content
Snippets Groups Projects
Commit 81432d32 authored by Robert Latta's avatar Robert Latta
Browse files

Added in routes for circuit hierarchy and tidied up other routes

parent 78ee78c0
No related branches found
No related tags found
No related merge requests found
import functools import functools
import json import json
from flask import Blueprint, request, Response, current_app from flask import Blueprint, request, Response
from inventory_provider import opsdb
from inventory_provider import db from inventory_provider import db
from inventory_provider.storage import external_inventory
routes = Blueprint("inventory-opsdb-query-routes", __name__) routes = Blueprint("inventory-opsdb-query-routes", __name__)
...@@ -39,17 +39,6 @@ def _decode_utf8_dict(d): ...@@ -39,17 +39,6 @@ def _decode_utf8_dict(d):
return {k.decode('utf8'): json.loads(v) for k, v in d.items()} return {k.decode('utf8'): json.loads(v) for k, v in d.items()}
@routes.route("/circuit-hierarchy", methods=['GET', ])
@require_accepts_json
def opsdb_circuit_hierarchy():
# todo - Retrieve data from redis
result = [{"Parent Name": "circuit 1"}, {"Parent Name": "Circuit 2"}]
return Response(
json.dumps(result),
mimetype="application/json")
@routes.route("/interfaces") @routes.route("/interfaces")
def get_all_interface_details(): def get_all_interface_details():
r = db.get_redis() r = db.get_redis()
...@@ -95,28 +84,29 @@ def get_all_equipment_locations(): ...@@ -95,28 +84,29 @@ def get_all_equipment_locations():
mimetype="application/json") mimetype="application/json")
@routes.route("/equipment-location/<equipment_name>") @routes.route("/equipment-location/<path:equipment_name>")
def get_equipment_location(equipment_name): def get_equipment_location(equipment_name):
r = db.get_redis() r = db.get_redis()
return Response( return Response(
r.hget(equipment_locations_key, equipment_name), r.hget(equipment_locations_key, equipment_name),
mimetype="application/json") mimetype="application/json")
# todo - Add in the routes for the circuit hierarchy, the actual load of the data is already done
# todo - Below are temporary routes that need to be removed
@routes.route("/circuit-sql")
def get_circuits_sql():
return Response(opsdb._generate_get_circuits_sql(), mimetype="text/plain")
@routes.route("/circuit-hierarchy/children/<parent_id>")
@routes.route("/infinera-circuit-sql", methods=['GET',]) def get_children(parent_id):
def get_infinera_circuits_sql(): r = db.get_redis()
return Response(opsdb.generate_infinera_sql(), mimetype="text/plain") return Response(
r.hget(
external_inventory.service_parent_to_children_key,
parent_id),
mimetype="application/json")
@routes.route("/equipment-location-sql", methods=['GET',]) @routes.route("/circuit-hierarchy/parents/<child_id>")
def get_equipment_location_sql(): def get_parents(child_id):
return Response(opsdb.equipment_location_query, mimetype="text/plain") r = db.get_redis()
\ No newline at end of file return Response(
r.hget(
external_inventory.service_child_to_parents_key,
child_id),
mimetype="application/json")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment