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 json
import re import re
from flask import Blueprint, jsonify, Response, current_app from flask import Blueprint, jsonify, Response
from lxml import etree from lxml import etree
import redis
from inventory_provider import juniper from inventory_provider import juniper
from inventory_provider.routes import common from inventory_provider.routes import common
...@@ -14,10 +13,7 @@ routes = Blueprint("inventory-data-query-routes", __name__) ...@@ -14,10 +13,7 @@ routes = Blueprint("inventory-data-query-routes", __name__)
@routes.route("/routers", methods=['GET', 'POST']) @routes.route("/routers", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def routers(): def routers():
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] r = common.get_redis()
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
result = [] result = []
for k in r.keys('netconf:*'): for k in r.keys('netconf:*'):
m = re.match('^netconf:(.+)$', k.decode('utf-8')) m = re.match('^netconf:(.+)$', k.decode('utf-8'))
...@@ -29,11 +25,7 @@ def routers(): ...@@ -29,11 +25,7 @@ def routers():
@routes.route("/interfaces/<hostname>", methods=['GET', 'POST']) @routes.route("/interfaces/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def router_interfaces(hostname): def router_interfaces(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] r = common.get_redis()
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
netconf_string = r.get('netconf:' + hostname) netconf_string = r.get('netconf:' + hostname)
if not netconf_string: if not netconf_string:
return Response( return Response(
...@@ -55,10 +47,7 @@ def router_interfaces(hostname): ...@@ -55,10 +47,7 @@ def router_interfaces(hostname):
@routes.route("/snmp/<hostname>", methods=['GET', 'POST']) @routes.route("/snmp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def snmp_ids(hostname): def snmp_ids(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] r = common.get_redis()
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
ifc_data_string = r.get('snmp-interfaces:' + hostname) ifc_data_string = r.get('snmp-interfaces:' + hostname)
if not ifc_data_string: if not ifc_data_string:
return Response( return Response(
...@@ -83,11 +72,7 @@ def snmp_ids(hostname): ...@@ -83,11 +72,7 @@ def snmp_ids(hostname):
@routes.route("/bgp/<hostname>", methods=['GET', 'POST']) @routes.route("/bgp/<hostname>", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def bgp_configs(hostname): def bgp_configs(hostname):
redis_config = current_app.config["INVENTORY_PROVIDER_CONFIG"]["redis"] r = common.get_redis()
r = redis.StrictRedis(
host=redis_config["hostname"],
port=redis_config["port"])
netconf_string = r.get('netconf:' + hostname) netconf_string = r.get('netconf:' + hostname)
if not netconf_string: if not netconf_string:
return Response( return Response(
......
...@@ -33,7 +33,7 @@ def test_get_interface_info_for_equipment(client_with_mocked_data): ...@@ -33,7 +33,7 @@ def test_get_interface_info_for_equipment(client_with_mocked_data):
def test_get_interface_info_for_equipment_and_interface( def test_get_interface_info_for_equipment_and_interface(
client_with_mocked_data): client_with_mocked_data):
rv = client_with_mocked_data.get( rv = client_with_mocked_data.get(
'/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0', '/opsdb/interfaces/mx1.ams.nl.geant.net/ae0.0',
headers=DEFAULT_REQUEST_HEADERS) headers=DEFAULT_REQUEST_HEADERS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment