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

added a prototype lg endpoint

parent b0077d87
Branches
Tags
No related merge requests found
......@@ -58,6 +58,9 @@ def create_app():
from inventory_provider.routes import poller
app.register_blueprint(poller.routes, url_prefix='/poller')
from inventory_provider.routes import lg
app.register_blueprint(lg.routes, url_prefix='/lg')
if app.config.get('ENABLE_TESTING_ROUTES', False):
from inventory_provider.routes import testing
app.register_blueprint(testing.routes, url_prefix='/testing')
......
......@@ -297,6 +297,64 @@ ORDER BY FIELD(e.status, 'Operational', 'Installed')
return list([_row2rsp(r) for r in rows])
def lookup_lg_routers(connection):
# this is literally the definition of the view vlg_routers
# (cf. https://jira.software.geant.org/projects/LGR/issues/LGR-73)
# but with the city added and filtering on names instead of absid's
# for readability
INTERNAL_POP_NAMES = {
'Cambridge OC',
'DANTE Lab',
'Amsterdam GEANT Office'
}
query = """
SELECT
e.name AS router_name,
p.name AS pop_name,
p.city AS pop_city,
p.abbreviation AS pop_abbreviation,
g.latitude AS pop_latitude,
g.longitude AS pop_longitude,
p.country_code AS pop_country_code,
g.country AS pop_country,
g.city AS pop_city
FROM
opsdb.equipment e
LEFT JOIN opsdb.pop p ON p.absid = e.PTR_pop
LEFT JOIN opsdb.geocoding g ON g.absid = p.PTR_geocoding
LEFT JOIN opsdb.organisation o ON o.absid = e.PTR_owner
WHERE
e.model LIKE 'mx%'
AND e.status = 'Operational'
AND o.name = 'DANTE / GEANT'
AND NOT (e.name REGEXP 'vpn-proxy|vrr|taas')
"""
def _row2rsp(row):
print(row)
return {
'equipment-name': row['router_name'],
'type': 'INTERNAL' if row['pop_name'] in INTERNAL_POP_NAMES else 'CORE',
'pop': {
'name': row['pop_name'],
'city': row['pop_city'],
'country': row['pop_country'],
'country code': row['pop_country_code'],
'abbreviation': row['pop_abbreviation'],
'longitude': row['pop_longitude'],
'latitude': row['pop_latitude'],
}
}
with db.cursor(connection) as crs:
crs.execute(query)
rows = _convert_to_dict(crs)
return list([_row2rsp(r) for r in rows])
def lookup_coriant_path(connection, equipment_name, card_id, port_number):
base_query = """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment