diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index 29b36f202cb515f5c38e0aa950bf9193c9b76b00..a6a041880eb9e5e1c96ce54969c8915d65e15225 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))