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

moved some unused routes to /testing (intention is to delete these)

parent ea210e01
No related branches found
No related tags found
No related merge requests found
import json
import re
from flask import Blueprint, jsonify, Response
from lxml import etree
from flask import Blueprint, jsonify, Response, current_app
from inventory_provider import juniper
from inventory_provider.routes import common
from inventory_provider.db import db
from inventory_provider.db import opsdb
routes = Blueprint("inventory-data-query-routes", __name__)
......@@ -41,83 +41,22 @@ def router_interfaces(hostname):
return jsonify(interfaces)
@routes.route("/snmp/<hostname>", methods=['GET', 'POST'])
@routes.route("/pop/<equipment_name>", methods=['GET', 'POST'])
@common.require_accepts_json
def snmp_ids(hostname):
r = common.get_redis()
ifc_data_string = r.get('snmp-interfaces:' + hostname)
if not ifc_data_string:
def equipment_location(equipment_name):
config = current_app.config['INVENTORY_PROVIDER_CONFIG']
with db.connection(config['ops-db']) as cx:
result = opsdb.get_equipment_location_data(cx, equipment_name)
if not result:
return Response(
response="no available info for '%s'" % hostname,
response="no available info for {}".format(equipment_name),
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 jsonify(result)
@routes.route("/bgp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json
def bgp_configs(hostname):
r = common.get_redis()
netconf_string = r.get('netconf:' + hostname)
if not netconf_string:
return Response(
response="no available info for '%s'" % hostname,
status=404,
mimetype="text/html")
routes = list(juniper.list_bgp_routes(
etree.XML(netconf_string.decode('utf-8'))))
if not routes:
return Response(
response="no interfaces found for '%s'" % hostname,
status=404,
mimetype="text/html")
return jsonify(routes)
# TODO: remove all alarmsdb i/o, and then remove the following
# @routes.route("/interfaces/status/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def interface_statuses(hostname, interface):
# r = common.get_redis()
# status = r.get(
# 'alarmsdb:interface_status:%s:%s'
# % (hostname, interface))
# if not status:
# return Response(
# response="no available info for {} {}".format(
# hostname, interface),
# status=404,
# mimetype="text/html")
# return jsonify({"status": status.decode('utf-8')})
#
#
# @routes.route("/services/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def services_for_interface(hostname, interface):
# r = common.get_redis()
# services = r.get(
# 'opsdb:interface_services:%s:%s'
# % (hostname, interface))
# if not services:
# return Response(
# response="no available info for {} {}".format(
# hostname, interface),
# status=404,
# mimetype="text/html")
# return jsonify(json.loads(services.decode('utf-8')))
......@@ -3,6 +3,9 @@ import json
import re
from flask import Blueprint, Response, current_app, jsonify
from lxml import etree
from inventory_provider import juniper
from inventory_provider.routes import common
from inventory_provider.tasks import worker
......@@ -137,3 +140,85 @@ def get_parents(child_id):
result = r.get('opsdb:services:parents:%d' % child_id)
# TODO: handle None (return 404)
return jsonify(json.loads(result.decode('utf-8')))
@routes.route("bgp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json
def bgp_configs(hostname):
r = common.get_redis()
netconf_string = r.get('netconf:' + hostname)
if not netconf_string:
return Response(
response="no available info for '%s'" % hostname,
status=404,
mimetype="text/html")
routes = list(juniper.list_bgp_routes(
etree.XML(netconf_string.decode('utf-8'))))
if not routes:
return Response(
response="no interfaces found for '%s'" % hostname,
status=404,
mimetype="text/html")
return jsonify(routes)
@routes.route("snmp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json
def snmp_ids(hostname):
r = common.get_redis()
ifc_data_string = r.get('snmp-interfaces:' + hostname)
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 jsonify(result)
# TODO: remove all alarmsdb i/o, and then remove the following
# @routes.route("/interfaces/status/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def interface_statuses(hostname, interface):
# r = common.get_redis()
# status = r.get(
# 'alarmsdb:interface_status:%s:%s'
# % (hostname, interface))
# if not status:
# return Response(
# response="no available info for {} {}".format(
# hostname, interface),
# status=404,
# mimetype="text/html")
# return jsonify({"status": status.decode('utf-8')})
#
#
# @routes.route("/services/<hostname>/<path:interface>",
# methods=['GET', 'POST'])
# @common.require_accepts_json
# def services_for_interface(hostname, interface):
# r = common.get_redis()
# services = r.get(
# 'opsdb:interface_services:%s:%s'
# % (hostname, interface))
# if not services:
# return Response(
# response="no available info for {} {}".format(
# hostname, interface),
# status=404,
# mimetype="text/html")
# return jsonify(json.loads(services.decode('utf-8')))
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