diff --git a/brian_dashboard_manager/grafana/provision.py b/brian_dashboard_manager/grafana/provision.py index 62a5e9552ca93d141578ff65de51be06dba20ee7..c0f27229954af0929764e29430474ef2a8dbe9ca 100644 --- a/brian_dashboard_manager/grafana/provision.py +++ b/brian_dashboard_manager/grafana/provision.py @@ -173,12 +173,17 @@ def provision_folder(token_request, folder_name, dash, Function to provision dashboards within a folder. """ - def _check_valid(interface): - return interface['dashboard_info']['name'] != '' + # def _check_valid(interface): + # return interface['dashboard_info']['name'] != '' folder = find_folder(token_request, folder_name) tag = dash['tag'] - interfaces = list(filter(_check_valid, dash['interfaces'])) + interfaces = list( + filter( + lambda x: x['dashboards_info'], + dash['interfaces'] + ) + ) # dashboard should include error panels errors = dash.get('errors', False) @@ -286,9 +291,19 @@ def _provision_interfaces(config, org_config, ds_name, token): desc = interface['description'].lower() lab = 'lab.office' in interface['router'].lower() to_exclude = any(nren.lower() in desc for nren in excluded_nrens) + if not (to_exclude or lab): + if 'dashboards_info' not in interface: + to_exclude = True + logger.info(f'No "dashboards_info" for ' + f'{interface["router"]}:{interface["name"]}') return not (to_exclude or lab) relevant_interfaces = list(filter(excluded, interfaces)) + for interface in relevant_interfaces: + interface['dashboards_info'] = filter( + lambda x: x['name'] != '', + interface['dashboards_info'] + ) # loop over interfaces and add them to the dashboard_name # -> folder mapping structure `dashboards` above, for convenience. diff --git a/brian_dashboard_manager/templating/helpers.py b/brian_dashboard_manager/templating/helpers.py index a6331f41555bdb8258340cdb173644db3456718a..fceb3e0d5bc49bcf8bcdcd501b3ed042fa8e1684 100644 --- a/brian_dashboard_manager/templating/helpers.py +++ b/brian_dashboard_manager/templating/helpers.py @@ -79,49 +79,50 @@ def get_nren_interface_data(interfaces): host = interface['router'] router = host.replace('.geant.net', '') + location = host.split('.')[1].upper() panel_title = f"{router} - {{}} - {interface_name} - {description}" - info = interface['dashboard_info'] - - dashboard_name = info['name'] + dashboards_info = interface['dashboards_info'] - dashboard = result.get(dashboard_name, { - 'AGGREGATES': [], - 'SERVICES': [], - 'PHYSICAL': [] - }) - - location = host.split('.')[1].upper() + for info in dashboards_info: + dashboard_name = info['name'] - if info['interface_type'] == 'AGGREGATE': - dashboard['AGGREGATES'].append({ - 'interface': interface_name, - 'hostname': host, - 'alias': f"{location} - {dashboard_name} ({interface_name})" + dashboard = result.get(dashboard_name, { + 'AGGREGATES': [], + 'SERVICES': [], + 'PHYSICAL': [] }) - # link aggregates are also shown - # under the physical dropdown - dashboard['PHYSICAL'].append({ - 'title': panel_title, - 'hostname': host, - 'interface': interface_name - }) - - elif info['interface_type'] == 'LOGICAL': - dashboard['SERVICES'].append({ - 'title': panel_title, - 'hostname': host, - 'interface': interface_name - }) - elif info['interface_type'] == 'PHYSICAL': - dashboard['PHYSICAL'].append({ - 'title': panel_title, - 'hostname': host, - 'interface': interface_name - }) - - result[dashboard_name] = dashboard + if info['interface_type'] == 'AGGREGATE': + dashboard['AGGREGATES'].append({ + 'interface': interface_name, + 'hostname': host, + 'alias': + f"{location} - {dashboard_name} ({interface_name})" + }) + + # link aggregates are also shown + # under the physical dropdown + dashboard['PHYSICAL'].append({ + 'title': panel_title, + 'hostname': host, + 'interface': interface_name + }) + + elif info['interface_type'] == 'LOGICAL': + dashboard['SERVICES'].append({ + 'title': panel_title, + 'hostname': host, + 'interface': interface_name + }) + elif info['interface_type'] == 'PHYSICAL': + dashboard['PHYSICAL'].append({ + 'title': panel_title, + 'hostname': host, + 'interface': interface_name + }) + + result[dashboard_name] = dashboard return result @@ -141,19 +142,20 @@ def get_interface_data(interfaces): router = host.replace('.geant.net', '') panel_title = f"{router} - {{}} - {interface_name} - {description}" - info = interface['dashboard_info'] + dashboards_info = interface['dashboards_info'] - dashboard_name = info['name'] + for info in dashboards_info: + dashboard_name = info['name'] - dashboard = result.get(dashboard_name, []) - dashboard.append({ - 'title': panel_title, - 'interface': interface_name, - 'hostname': host, - 'has_v6': len(interface.get('ipv6', [])) > 0 - }) + dashboard = result.get(dashboard_name, []) + dashboard.append({ + 'title': panel_title, + 'interface': interface_name, + 'hostname': host, + 'has_v6': len(interface.get('ipv6', [])) > 0 + }) - result[dashboard_name] = dashboard + result[dashboard_name] = dashboard return result @@ -187,17 +189,18 @@ def get_aggregate_interface_data(interfaces, agg_type, group_field): interface_name = interface.get('name') host = interface.get('router', '') - remote = interface['dashboard_info']['name'] + for info in interface['dashboards_info']: + remote = info['name'] - location = host.split('.')[1].upper() - result.append({ - 'type': agg_type, - 'interface': interface_name, - 'hostname': host, - 'remote': remote, - 'location': location, - 'alias': f"{location} - {remote} ({interface_name})", - }) + location = host.split('.')[1].upper() + result.append({ + 'type': agg_type, + 'interface': interface_name, + 'hostname': host, + 'remote': remote, + 'location': location, + 'alias': f"{location} - {remote} ({interface_name})", + }) return reduce(get_reduce_func_for_field(group_field), result, {}) diff --git a/test/test_aggregrate.py b/test/test_aggregrate.py index d0484a24ba83bd98ff660b062e258e3a73687ffe..7c494ba0283110ffaf5e0bd7b9d70617264f283a 100644 --- a/test/test_aggregrate.py +++ b/test/test_aggregrate.py @@ -39,6 +39,10 @@ TEST_DASHBOARD = { "name": "EXOSCALE", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "EXOSCALE", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.100.26/31" ], @@ -71,6 +75,10 @@ TEST_DASHBOARD = { "name": "EXOSCALE", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "EXOSCALE", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.100.20/31" ], @@ -103,6 +111,10 @@ TEST_DASHBOARD = { "name": "T-SYSTEMS", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "T-SYSTEMS", + "interface_type": "LOGICAL" + }], "ipv4": [ "94.100.252.88/31" ], @@ -133,6 +145,10 @@ TEST_DASHBOARD = { "name": "AWS", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "AWS", + "interface_type": "LOGICAL" + }], "ipv4": [ "52.95.219.129/31" ], @@ -165,6 +181,10 @@ TEST_DASHBOARD = { "name": "CLOUDFERRO", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "CLOUDFERRO", + "interface_type": "LOGICAL" + }], "ipv4": [ "45.92.241.127/31" ], @@ -195,6 +215,10 @@ TEST_DASHBOARD = { "name": "ORACLE", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "ORACLE", + "interface_type": "LOGICAL" + }], "ipv4": [ "130.61.6.73/31" ], @@ -227,6 +251,10 @@ TEST_DASHBOARD = { "name": "AWS", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "AWS", + "interface_type": "LOGICAL" + }], "ipv4": [ "52.95.219.37/31" ], @@ -259,6 +287,10 @@ TEST_DASHBOARD = { "name": "ORACLE", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "ORACLE", + "interface_type": "LOGICAL" + }], "ipv4": [ "132.145.7.81/31" ], diff --git a/test/test_update.py b/test/test_update.py index 94600c1ceb6da2928010c1859056c2e98c40081c..381c4ab73756cd2a0e1d0d9d0aa05850cba4d67d 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -28,6 +28,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -54,6 +58,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.127.131/31" ], @@ -84,6 +92,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [ "10.101.0.6/30" ], @@ -112,6 +124,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.127.141/31" ], @@ -140,6 +156,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [ "10.1.1.1/30" ], @@ -163,6 +183,10 @@ TEST_INTERFACES = [ "name": "KIAE", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "KIAE", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -184,6 +208,10 @@ TEST_INTERFACES = [ "name": "SWITCH", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "SWITCH", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -202,6 +230,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [], "ipv6": [] }, @@ -220,6 +252,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [], "ipv6": [] }, @@ -238,6 +274,10 @@ TEST_INTERFACES = [ "name": "GEANT", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }], "ipv4": [], "ipv6": [] } @@ -262,6 +302,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -283,6 +327,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -304,6 +352,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "PHYSICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "PHYSICAL" + }], "ipv4": [], "ipv6": [] }, @@ -327,6 +379,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "AGGREGATE" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "AGGREGATE" + }], "ipv4": [], "ipv6": [] }, @@ -357,6 +413,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.125.13/30" ], @@ -391,6 +451,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "LOGICAL" + }], "ipv4": [ "62.40.102.36/31" ], @@ -423,6 +487,10 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "HEANET", + "interface_type": "LOGICAL" + }], "ipv4": [ "83.97.88.77/30" ], @@ -456,6 +524,14 @@ NREN_INTERFACES = [ "name": "HEANET", "interface_type": "LOGICAL" }, + "dashboards_info": [{ + "name": "GEANT", + "interface_type": "LOGICAL" + }, + { + "name": "HEANET", + "interface_type": "LOGICAL" + }], "ipv4": [], "ipv6": [] }