From e71fc0954c412e4836af4379d24c26a0ae589b8d Mon Sep 17 00:00:00 2001
From: Robert Latta <robert.latta@geant.org>
Date: Mon, 8 Apr 2019 17:58:29 +0100
Subject: [PATCH] added circuit_id to end-point, used it to populate
 'geant-lambda' key (no longer plural)

---
 inventory_provider/routes/classifier.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py
index 5e6f2c9d..6a604491 100644
--- a/inventory_provider/routes/classifier.py
+++ b/inventory_provider/routes/classifier.py
@@ -238,10 +238,11 @@ def peer_info(address):
     return Response(result, mimetype="application/json")
 
 
-@routes.route("/infinera-lambda-info/<source_equipment>/<path:interface>",
+@routes.route("/infinera-lambda-info/"
+              "<source_equipment>/<interface>/<circuit_id>",
               methods=['GET', 'POST'])
 @common.require_accepts_json
-def get_trap_metadata(source_equipment, interface):
+def get_trap_metadata(source_equipment, interface, circuit_id):
     r = common.get_redis()
 
     cache_key = 'classifier-cache:infinera:%s:%s' % (
@@ -257,16 +258,12 @@ 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:
-                    t_gl = json.loads(gl.decode('utf=8'))
-                    t_gl['status'] = t_gl['status'].lower()
-                    geant_lambdas.append(t_gl)
-
-            if geant_lambdas:
-                result['geant-lambdas'] = geant_lambdas
+
+        gl = r.get('opsdb:geant_lambdas:%s' % circuit_id.lower())
+        if gl:
+            t_gl = json.loads(gl.decode('utf=8'))
+            t_gl['status'] = t_gl['status'].lower()
+            result['geant-lambda'] = t_gl
 
         if not result:
             return Response(
-- 
GitLab