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

changed response format for easier client handling

parent 87262386
No related branches found
No related tags found
No related merge requests found
......@@ -157,42 +157,25 @@ GWS_DIRECT_DATA_SCHEMA = {
'type': 'string',
'pattern': r'^(\d+\.)*\d+$'
},
'counters': {
'counter': {
'type': 'object',
'properties': {
'discards_in': {'$ref': '#/definitions/oid'},
'discards_out': {'$ref': '#/definitions/oid'},
'errors_in': {'$ref': '#/definitions/oid'},
'errors_out': {'$ref': '#/definitions/oid'},
'traffic_in': {'$ref': '#/definitions/oid'},
'traffic_out': {'$ref': '#/definitions/oid'},
},
'additionalProperties': False
},
'interface': {
'type': 'object',
'properties': {
'tag': {'type': 'string'},
'counters': {'$ref': '#/definitions/counters'}
},
'required': ['tag', 'counters'],
'additionalProperties': False
},
'host': {
'type': 'object',
'properties': {
'hostname': {'type': 'string'},
'community': {'type': 'string'},
'interfaces': {
'type': 'array',
'items': {'$ref': '#/definitions/interface'},
'minItems': 1
}
'field': {
'enum': [
'discards_in',
'discards_out',
'errors_in',
'errors_out',
'traffic_in',
'traffic_out'
]
},
'oid': {'$ref': '#/definitions/oid'}
},
'required': ['hostname', 'community', 'interfaces'],
'required': ['field', 'oid'],
'additionalProperties': False
},
'nren-isp': {
'interface-counters': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
......@@ -200,19 +183,23 @@ GWS_DIRECT_DATA_SCHEMA = {
'type': 'string',
'enum': ['Cogent', 'Telia', 'Century Link']
},
'hosts': {
'hostname': {'type': 'string'},
'community': {'type': 'string'},
'tag': {'type': 'string'},
'counters': {
'type': 'array',
'items': {'$ref': '#/definitions/host'},
'items': {'$ref': '#/definitions/counter'},
'minItems': 1
}
},
'required': ['nren', 'isp', 'hosts'],
'required': [
'nren', 'isp', 'hostname', 'community', 'tag', 'counters'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/nren-isp'}
'items': {'$ref': '#/definitions/interface-counters'}
}
......@@ -640,5 +627,36 @@ def gws_direct():
:return:
"""
config_params = current_app.config['INVENTORY_PROVIDER_CONFIG']
return jsonify(config_params['gws-direct'])
cache_key = f'classifier-cache:gws-direct'
r = common.get_current_redis()
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
else:
def _interfaces():
config_params = current_app.config['INVENTORY_PROVIDER_CONFIG']
for nren_isp in config_params['gws-direct']:
for host in nren_isp['hosts']:
for ifc in host['interfaces']:
yield {
'nren': nren_isp['nren'],
'isp': nren_isp['isp'],
'hostname': host['hostname'],
'community': host['community'],
'tag': ifc['tag'],
'counters': [
{'field': k, 'oid': v}
for k, v in ifc['counters'].items()]
}
result = json.dumps(list(_interfaces()))
# cache this data for the next call
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json")
......@@ -60,6 +60,5 @@ def test_gws_direct(client):
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(
response_data, poller.GWS_DIRECT_DATA_SCHEMA)
jsonschema.validate(response_data, poller.GWS_DIRECT_DATA_SCHEMA)
assert response_data, "the subscription list shouldn't be empty"
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