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

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.geant.net:live-projects/dashboardv3/inventory-provider into develop
parents 88344727 aa5f3034
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,12 @@
All notable changes to this project will be documented in this file.
## [0.50] - 2020-08-14
- performance improvment for /poller/services
## [0.49] - 2020-08-13
- performance improvement /data/interfaces
- refactored a new method for testability
- performance improvement for /data/interfaces
- refactored service category sorting for better testability
## [0.48] - 2020-07-02
- recover update gracefully in case of Kombu exceptions
......
import json
from flask import Blueprint, Response, jsonify
from flask import Blueprint, Response, jsonify, current_app
from lxml import etree
from inventory_provider import juniper
from inventory_provider.routes import common
......@@ -88,10 +88,12 @@ def poller_interface_oids(hostname):
@common.require_accepts_json
def service_category_interfaces(category):
def _interfaces(rc, cat):
for k in rc.scan_iter(f'interface-services:{cat}:*'):
cached_ifc = rc.get(k.decode('utf-8')).decode('utf-8')
cached_ifc = json.loads(cached_ifc)
def _interfaces(cat):
config_params = current_app.config['INVENTORY_PROVIDER_CONFIG']
for doc in common.load_json_docs(
config_params=config_params,
key_pattern=f'interface-services:{cat}:*'):
cached_ifc = doc['value']
basic_ifc_info = dict()
for k in ['description', 'interface', 'router']:
basic_ifc_info[k] = cached_ifc[k]
......@@ -110,15 +112,17 @@ def service_category_interfaces(category):
result = r.get(cache_key)
if result:
result = json.loads(result.decode('utf-8'))
result = result.decode('utf-8')
else:
result = list(_interfaces(r, category))
if result:
r.set(cache_key, json.dumps(result).encode('utf-8'))
else:
result = list(_interfaces(category))
if not result:
return Response(
response=f'no info available for service category {category}',
status=404,
mimetype="text/html")
return jsonify(result)
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")
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='inventory-provider',
version="0.50",
version="0.51",
author='GEANT',
author_email='swd@geant.org',
description='Dashboard inventory provider',
......
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