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

use common.get_redis to create connection

parent 4e6b64da
No related branches found
No related tags found
No related merge requests found
import json
import re
from flask import Blueprint, jsonify, Response, current_app
from flask import Blueprint, jsonify, Response
from lxml import etree
import redis
from inventory_provider import juniper
from inventory_provider.routes import common
......@@ -14,10 +13,7 @@ routes = Blueprint("inventory-data-query-routes", __name__)
@routes.route("/routers", methods=['GET', 'POST'])
@common.require_accepts_json
def routers():
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"]
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
r = common.get_redis()
result = []
for k in r.keys('netconf:*'):
m = re.match('^netconf:(.+)$', k.decode('utf-8'))
......@@ -29,11 +25,7 @@ def routers():
@routes.route("/interfaces/<hostname>", methods=['GET', 'POST'])
@common.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"])
r = common.get_redis()
netconf_string = r.get('netconf:' + hostname)
if not netconf_string:
return Response(
......@@ -55,10 +47,7 @@ def router_interfaces(hostname):
@routes.route("/snmp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json
def snmp_ids(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"]
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
r = common.get_redis()
ifc_data_string = r.get('snmp-interfaces:' + hostname)
if not ifc_data_string:
return Response(
......@@ -83,11 +72,7 @@ def snmp_ids(hostname):
@routes.route("/bgp/<hostname>", methods=['GET', 'POST'])
@common.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"])
r = common.get_redis()
netconf_string = r.get('netconf:' + hostname)
if not netconf_string:
return Response(
......
......@@ -33,7 +33,7 @@ def test_get_interface_info_for_equipment(client_with_mocked_data):
def test_get_interface_info_for_equipment_and_interface(
client_with_mocked_data):
client_with_mocked_data):
rv = client_with_mocked_data.get(
'/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0',
headers=DEFAULT_REQUEST_HEADERS)
......
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