From 35f7daab1efb86ee8abe9280a74b804c9f8331dc Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Fri, 28 Feb 2020 16:11:10 +0100 Subject: [PATCH] added access services api --- inventory_provider/db/opsdb.py | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index 29b36f20..a6a04188 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -210,6 +210,36 @@ name, return r +def get_access_services(connection): + _sql = """ +SELECT + c.absid AS id, + c.name, + pop_a.name as pop_name, + pop_b.name as other_end_pop_name, + e_a.name AS equipment, + e_b.name AS other_end_equipment, + c.speed_value, + c.speed_unit +FROM circuit c + INNER JOIN circuit_connections cc ON cc.circ_absid = c.absid + LEFT JOIN pop pop_a ON pop_a.absid = cc.PTR_pop_a + LEFT JOIN pop pop_b ON pop_b.absid = cc.PTR_pop_b + INNER JOIN equipment e_a ON e_a.absid = cc.PTR_equip_a + LEFT JOIN equipment e_b ON e_b.absid = cc.PTR_equip_b +WHERE LOWER(c.status) = 'operational' + AND LOWER(c.circuit_type) = 'service' + AND LOWER(c.service_type) = 'ip access' + AND c.is_circuit = 1 + AND e_a.name IS NOT NULL + AND e_a.name != '' +ORDER BY name +""" + with db.cursor(connection) as crs: + crs.execute(_sql) + return _convert_to_dict(crs) + + def get_circuit_hierarchy(connection): # pragma: no cover _sql = """ @@ -512,7 +542,7 @@ def get_service_users(connection, service_ids): if __name__ == '__main__': from inventory_provider.db import db - + import json db_params = { 'hostname': '83.97.93.8', 'dbname': 'opsdb', @@ -520,7 +550,7 @@ if __name__ == '__main__': 'password': 'opsro' } with db.connection(db_params) as cx: - circuits = get_circuits(cx) + circuits = get_access_services(cx) - print(circuits) + print(json.dumps(circuits)) -- GitLab