From ad6a82f9fff3245bb52db4ca202dade12f6297a1 Mon Sep 17 00:00:00 2001
From: Robert Latta <robert.latta@geant.org>
Date: Thu, 22 Apr 2021 12:04:11 +0000
Subject: [PATCH] addcontacts to schema; added extra infinera endpoint checks

---
 inventory_provider/routes/classifier.py       | 29 +++++++++++++++++--
 .../routes/classifier_schema.py               |  6 +++-
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py
index 40a20f37..5a7dd631 100644
--- a/inventory_provider/routes/classifier.py
+++ b/inventory_provider/routes/classifier.py
@@ -618,9 +618,8 @@ def get_trap_metadata(source_equipment: str, interface: str, circuit_id: str) \
     result = _ignore_cache_or_retrieve(request, cache_key, r)
 
     if not result:
-        result = {
-            'locations': []
-        }
+
+        result = {}
 
         result.update(get_interface_services_and_loc(
             ims_source_equipment,
@@ -628,6 +627,30 @@ def get_trap_metadata(source_equipment: str, interface: str, circuit_id: str) \
             r
         ))
 
+        # rubbish hack to cope with Dashboard Classifier removing piece of
+        # interface name. Once Dashboard is fully driven by IMS we can remove that  # noqa
+        # part of the classifier and then this
+        # As of 2021-04-21 the Dashboard line that will need removing is
+        # https://gitlab.geant.net/live-projects/dashboardv3/dashboard-v3-python/-/blob/develop/dashboard/classification/classifier.py#L207  # noqa
+        if not result or not result.get('services', []):
+            interface_parts = interface.split('-')
+            interface_parts[-2] = 'T' + interface_parts[-2]
+            t_interface = '-'.join(interface_parts)
+            result.update(get_interface_services_and_loc(
+                ims_source_equipment,
+                t_interface,
+                r
+            ))
+            if not result or not result.get('services', []):
+                interface_parts = interface.split('-')
+                interface_parts[-1] = 'T' + interface_parts[-1]
+                t_interface = '-'.join(interface_parts)
+                result.update(get_interface_services_and_loc(
+                    ims_source_equipment,
+                    t_interface,
+                    r
+                ))
+
         if not result:
             return Response(
                 response="no available info for {} {}".format(
diff --git a/inventory_provider/routes/classifier_schema.py b/inventory_provider/routes/classifier_schema.py
index e4e9e0d1..fe2ed7c7 100644
--- a/inventory_provider/routes/classifier_schema.py
+++ b/inventory_provider/routes/classifier_schema.py
@@ -541,7 +541,11 @@ INFINERA_LAMBDA_INFO_RESPONSE_SCHEMA = {
         "geant-lambda": {
             "$ref": "#/definitions/geant-lambda"
         },
-        "locations": {"$ref": "#/definitions/locations-list"}
+        "locations": {"$ref": "#/definitions/locations-list"},
+        "contacts": {
+            "type": "array",
+            "items": {"type": "string"}
+        }
     },
     "additionalProperties": False
 }
-- 
GitLab