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

Finished feature POL1-445-gws-direct-api.

parents 4db3a2a6 e4b7116c
No related branches found
No related tags found
No related merge requests found
...@@ -29,9 +29,10 @@ API modules ...@@ -29,9 +29,10 @@ API modules
:caption: Contents: :caption: Contents:
classifier classifier
poller
lg lg
data data
jobs jobs
msr msr
lnetd lnetd
\ No newline at end of file
.. automodule:: inventory_provider.routes.poller
.. poller endpoint docs
BRIAN support Endpoints
=========================
These endpoints are intended for use by BRIAN.
.. contents:: :local:
/poller/interfaces</hostname>
---------------------------------
.. autofunction:: inventory_provider.routes.poller.interfaces
/poller/speeds</hostname>
---------------------------------
.. autofunction:: inventory_provider.routes.poller.interface_speeds
/poller/eumetsat-multicast
---------------------------------
.. autofunction:: inventory_provider.routes.poller.eumetsat_multicast
"""
BRIAN support Endpoints
=========================
These endpoints are intended for use by BRIAN.
.. contents:: :local:
/poller/interfaces</hostname>
---------------------------------
.. autofunction:: inventory_provider.routes.poller.interfaces
/poller/speeds</hostname>
---------------------------------
.. autofunction:: inventory_provider.routes.poller.interface_speeds
/poller/eumetsat-multicast
---------------------------------
.. autofunction:: inventory_provider.routes.poller.eumetsat_multicast
/poller/gws/direct
---------------------------------
.. autofunction:: inventory_provider.routes.poller.gws_direct
"""
import json import json
import logging import logging
import re import re
from flask import Blueprint, Response, current_app, request from flask import Blueprint, Response, current_app, request, jsonify
from lxml import etree from lxml import etree
from inventory_provider import juniper from inventory_provider import juniper
...@@ -117,6 +149,60 @@ MULTICAST_SUBSCRIPTION_LIST_SCHEMA = { ...@@ -117,6 +149,60 @@ MULTICAST_SUBSCRIPTION_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/subscription'} 'items': {'$ref': '#/definitions/subscription'}
} }
GWS_DIRECT_DATA_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'snmp-counter': {
'type': 'object',
'properties': {
'hostname': {'type': 'string'},
'community': {'type': 'string'},
'oid': {
'type': 'string',
'pattern': r'^(\d+\.)*\d+$'
}
},
'required': ['hostname', 'community', 'oid'],
'additionalProperties': False
},
'snmp-counter-list': {
'type': 'array',
'items': {'$ref': '#/definitions/snmp-counter'},
'minItems': 1
},
'isp-counters': {
'type': 'object',
'properties': {
'traffic_in': {'$ref': '#/definitions/snmp-counter-list'},
'traffic_out': {'$ref': '#/definitions/snmp-counter-list'},
'discards_in': {'$ref': '#/definitions/snmp-counter-list'},
'discards_out': {'$ref': '#/definitions/snmp-counter-list'},
'errors_in': {'$ref': '#/definitions/snmp-counter-list'},
'errors_out': {'$ref': '#/definitions/snmp-counter-list'}
},
'required': ['traffic_in', 'traffic_out'],
'additionalProperties': False
},
'nren-isp-direct-counters': {
'type': 'object',
'properties': {
'nren': {'type': 'string'},
'isp': {
'type': 'string',
'enum': ['Cogent', 'Telia', 'Century Link']
},
'counters': {'$ref': '#/definitions/isp-counters'},
},
'required': ['nren', 'isp', 'counters'],
'additionalProperties': False
}
},
'type': 'array',
'items': {'$ref': '#/definitions/nren-isp-direct-counters'}
}
@routes.after_request @routes.after_request
def after_request(resp): def after_request(resp):
...@@ -522,3 +608,367 @@ def eumetsat_multicast(hostname=None): ...@@ -522,3 +608,367 @@ def eumetsat_multicast(hostname=None):
r.set(cache_key, result.encode('utf-8')) r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json") return Response(result, mimetype="application/json")
@routes.route("/gws/direct", methods=['GET', 'POST'])
@common.require_accepts_json
def gws_direct():
"""
Handler for `/poller/gws/direct` which returns required for polling
customer equipment counters for ISP connetions.
The response is a list of nren/isp/counter structures that must be
polled.
.. asjson::
inventory_provider.routes.poller.GWS_DIRECT_DATA_SCHEMA
This method returns essentially hard-coded data,
based on the information in POL1-422.
TODO: this hard-coded data should be in the config file
:return:
"""
data = [
{
"nren": "ARNES",
"isp": "Cogent",
"counters": {
"discards_in": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.2.2.1.13.533"
}
],
"discards_out": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.2.2.1.19.533"
}
],
"errors_in": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.2.2.1.14.533"
}
],
"errors_out": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.2.2.1.20.533"
}
],
"traffic_in": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.531"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.525"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.553"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.563"
}
],
"traffic_out": [
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.531"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.525"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.553"
},
{
"hostname": "88.200.0.63",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.563"
}
]
}
},
{
"nren": "ARNES",
"isp": "Telia",
"counters": {
"traffic_in": [
{
"hostname": "62.40.124.6",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.611"
},
{
"hostname": "62.40.124.6",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.6.589"
}
],
"traffic_out": [
{
"hostname": "62.40.124.6",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.611"
},
{
"hostname": "62.40.124.6",
"community": "gn2nocT3st",
"oid": "1.3.6.1.2.1.31.1.1.1.10.589"
}
]
}
},
{
"nren": "CARNET",
"isp": "Cogent",
"counters": {
"traffic_in": [
{
"hostname": "62.40.124.10",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.35"
}
],
"traffic_out": [
{
"hostname": "62.40.124.10",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.35"
}
]
}
},
{
"nren": "CARNET",
"isp": "Telia",
"counters": {
"traffic_in": [
{
"hostname": "62.40.125.150",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.48"
}
],
"traffic_out": [
{
"hostname": "62.40.125.150",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.48"
}
]
}
},
{
"nren": "KIFU",
"isp": "Cogent",
"counters": {
"traffic_in": [
{
"hostname": "195.111.97.108",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.155"
}
],
"traffic_out": [
{
"hostname": "195.111.97.108",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.155"
}
]
}
},
{
"nren": "KIFU",
"isp": "Telia",
"counters": {
"traffic_in": [
{
"hostname": "195.111.97.108",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.148"
}
],
"traffic_out": [
{
"hostname": "195.111.97.108",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.148"
}
]
}
},
{
"nren": "RedIRIS",
"isp": "Telia",
"counters": {
"traffic_in": [
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.1487"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.1488"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.1489"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.760"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.796"
}
],
"traffic_out": [
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.1487"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.1488"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.1489"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.760"
},
{
"hostname": "130.206.206.250",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.796"
}
]
}
},
{
"nren": "RoEduNet",
"isp": "Cogent",
"counters": {
"traffic_in": [
{
"hostname": "149.6.50.10",
"community": "dante",
"oid": "1.3.6.1.2.1.31.1.1.1.6.531"
}
],
"traffic_out": [
{
"hostname": "149.6.50.10",
"community": "dante",
"oid": "1.3.6.1.2.1.31.1.1.1.10.531"
}
]
}
},
{
"nren": "RoEduNet",
"isp": "Century Link",
"counters": {
"traffic_in": [
{
"hostname": "212.162.45.194",
"community": "dante",
"oid": "1.3.6.1.2.1.31.1.1.1.6.9"
}
],
"traffic_out": [
{
"hostname": "212.162.45.194",
"community": "dante",
"oid": "1.3.6.1.2.1.31.1.1.1.10.9"
}
]
}
},
{
"nren": "EENet",
"isp": "Telia",
"counters": {
"traffic_in": [
{
"hostname": "193.40.133.2",
"community": "geant-mon-telia",
"oid": "1.3.6.1.2.1.31.1.1.1.6.263"
}
],
"traffic_out": [
{
"hostname": "193.40.133.2",
"community": "geant-mon-telia",
"oid": "1.3.6.1.2.1.31.1.1.1.10.263"
}
]
}
},
{
"nren": "PSNC",
"isp": "Century Link",
"counters": {
"traffic_in": [
{
"hostname": "212.191.126.6",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.675"
},
{
"hostname": "212.191.126.7",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.6.677"
}
],
"traffic_out": [
{
"hostname": "212.191.126.6",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.675"
},
{
"hostname": "212.191.126.7",
"community": "atlas1453",
"oid": "1.3.6.1.2.1.31.1.1.1.10.677"
}
]
}
}
]
return jsonify(data)
...@@ -50,3 +50,16 @@ def test_eumetsat_multicast(mocker, client): ...@@ -50,3 +50,16 @@ def test_eumetsat_multicast(mocker, client):
jsonschema.validate( jsonschema.validate(
response_data, poller.MULTICAST_SUBSCRIPTION_LIST_SCHEMA) response_data, poller.MULTICAST_SUBSCRIPTION_LIST_SCHEMA)
assert response_data, "the subscription list shouldn't be empty" assert response_data, "the subscription list shouldn't be empty"
def test_gws_direct(client):
rv = client.get(
'/poller/gws/direct',
headers=DEFAULT_REQUEST_HEADERS)
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)
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.
Please register or to comment