From ec41598a37bd117946a74fc8f987166cd3374211 Mon Sep 17 00:00:00 2001
From: Sam Roberts <sam.roberts@geant.org>
Date: Mon, 2 Sep 2024 11:35:15 +0100
Subject: [PATCH] rework region dashboards change into _get_dashboard_data

---
 inventory_provider/routes/poller.py | 31 +++++++++++++----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py
index 0656b76f..e6187d68 100644
--- a/inventory_provider/routes/poller.py
+++ b/inventory_provider/routes/poller.py
@@ -523,7 +523,10 @@ def _get_dashboards(interface):
         yield BRIAN_DASHBOARDS.ANA
 
 
-def _get_dashboard_data(ifc, customers):
+def _get_dashboard_data(ifc, customers, regions=None):
+    if regions is None:
+        regions = []
+
     def _get_interface_type(description):
         if re.match(r'^PHY', description):
             return INTERFACE_TYPES.PHYSICAL
@@ -580,6 +583,15 @@ def _get_dashboard_data(ifc, customers):
     if not names:
         return ifc
 
+    # add region-based dashboard names
+    region_names = []
+    for name in names:
+        if name in regions:
+            region = regions[name]
+            if region == 'EAP':
+                region_names.append(BRIAN_DASHBOARDS.EAP.name)
+    names.extend(region_names)
+
     # to maintain compatability with current brian dashboard manager we will
     # continue to return dashboard_info with the first customer name. We will
     # also return dashboards_info (note the plural of dashboards) with up to
@@ -597,20 +609,6 @@ def _get_dashboard_data(ifc, customers):
     }
 
 
-def _add_region_data(ifc, regions):
-    if 'dashboards_info' in ifc:
-        for item in ifc['dashboards_info']:
-            name = item['name']
-            if name in regions:
-                region = regions[name]
-                if region == 'EAP':
-                    dashboards = ifc['dashboards']
-                    dashboards.append(BRIAN_DASHBOARDS.EAP.name)
-                    ifc['dashboards'] = sorted(dashboards)
-                    return ifc
-    return ifc
-
-
 def _load_interface_bundles(config, hostname=None, use_next_redis=False):
     result = dict()
 
@@ -883,8 +881,7 @@ def load_interfaces_to_poll(config, hostname=None, no_lab=False, use_next_redis=
                 ifc['dashboards'] = sorted([d.name for d in dashboards])
 
                 ifc = _get_dashboard_data(
-                    ifc, ifc_services_and_customers.get('customers', []))
-                ifc = _add_region_data(ifc, nren_regions)
+                    ifc, ifc_services_and_customers.get('customers', []), nren_regions)
                 port_type = _get_port_type(ifc['description'])
                 ifc['port_type'] = port_type
                 yield ifc
-- 
GitLab