diff --git a/inventory_provider/db/opsdb.py b/inventory_provider/db/opsdb.py index 38197e4780535b82f004df8313d9dc244b720933..79b8ff0b46375efb5119b698689eee95de83daaa 100644 --- a/inventory_provider/db/opsdb.py +++ b/inventory_provider/db/opsdb.py @@ -28,6 +28,14 @@ equipment_location_query = """SELECT 'operational')""" +geant_lambda_sql = """SELECT + name, + status + FROM circuit + WHERE + status != 'terminated' + AND service_type = 'geant lambda'""" + circuit_hierarchy_query = """SELECT pc.name AS parent_circuit, pc.absid AS parent_circuit_id, @@ -189,10 +197,18 @@ def _update_fields(r): return func(r) if func else r +def get_geant_lambdas(connection): + with db.cursor(connection) as crs: + crs.execute(geant_lambda_sql) + r = _convert_to_dict(crs) + return r + + def get_circuits(connection): with db.cursor(connection) as crs: crs.execute(retrieve_services_query) r = _convert_to_dict(crs) + r = list(map(_update_fields, r)) return r diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 2c9f7f415224944f5df175290a8d941275de0540..2e33ff6dbfe9483b401bd31bea48db1621cf6eda 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -68,6 +68,14 @@ def get_trap_metadata(source_equipment, interface): 'opsdb:interface_services:%s:%s' % (source_equipment, interface)) if services: result['services'] = json.loads(services.decode('utf=8')) + geant_lambdas = [] + for s in result['services']: + gl = r.get('opsdb:geant_lambdas:%s' % s['name']) + if gl: + geant_lambdas.append(json.loads(gl.decode('utf=8'))) + + if geant_lambdas: + result['geant_lambdas'] = geant_lambdas ifc_info = r.get( 'netconf-interfaces:%s:%s' % (source_equipment, interface)) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 0083aee763dbc9df0c52fd9d273b9938c051c316..19c94dbdd1508ffcb4125550868956774d8136c2 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -200,6 +200,21 @@ def update_interface_statuses(): logger.debug('<<< update_interface_statuses') +@app.task +def update_geant_lambdas(): + logger = logging.getLogger(__name__) + logger.debug('>>> update_geant_lambdas') + + r = get_redis(InventoryTask.config) + for key in r.scan_iter('opsdb:geant_lambdas:*'): + r.delete(key) + with db.connection(InventoryTask.config["ops-db"]) as cx: + for ld in opsdb.get_geant_lambdas(cx): + r.set('opsdb:geant_lambdas:%s' % ld['name'], json.dumps(ld)) + + logger.debug('<<< geant_lambdas') + + @app.task(base=InventoryTask, bind=True) def update_junosspace_device_list(self): logger = logging.getLogger(__name__) @@ -457,6 +472,7 @@ def launch_refresh_cache_all(config): subtasks = [ update_junosspace_device_list.s(), update_interfaces_to_services.s(), + update_geant_lambdas.s(), update_circuit_hierarchy.s() ]