Skip to content
Snippets Groups Projects
Commit be01a4d9 authored by Sam Roberts's avatar Sam Roberts
Browse files

add grouping by location to aggregate provisioning

potentially other fields too, although it's not immediately clear if this would be useful
parent e206e86a
No related branches found
No related tags found
No related merge requests found
...@@ -155,6 +155,7 @@ AGG_DASHBOARDS = { ...@@ -155,6 +155,7 @@ AGG_DASHBOARDS = {
'COPERNICUS': { 'COPERNICUS': {
'tag': 'copernicus', 'tag': 'copernicus',
'dashboard_name': 'COPERNICUS', 'dashboard_name': 'COPERNICUS',
'group_by': 'location',
'interfaces': [] 'interfaces': []
} }
} }
...@@ -213,7 +214,8 @@ def provision_aggregate(token_request, folder, ...@@ -213,7 +214,8 @@ def provision_aggregate(token_request, folder,
name = dash['dashboard_name'] name = dash['dashboard_name']
tag = dash['tag'] tag = dash['tag']
interfaces = dash['interfaces'] interfaces = dash['interfaces']
data = get_aggregate_interface_data(interfaces, name) group_field = dash.get('group_by', 'remote')
data = get_aggregate_interface_data(interfaces, name, group_field)
dashboard = get_aggregate_dashboard_data( dashboard = get_aggregate_dashboard_data(
f'Aggregate - {name}', data, ds_name, tag) f'Aggregate - {name}', data, ds_name, tag)
......
...@@ -157,28 +157,30 @@ def get_interface_data(interfaces): ...@@ -157,28 +157,30 @@ def get_interface_data(interfaces):
return result return result
def get_aggregate_interface_data(interfaces, agg_type): def get_aggregate_interface_data(interfaces, agg_type, group_field):
""" """
Helper for grouping interfaces into groups of remotes Helper for grouping interfaces into groups by fields, eg. remotes
(ISP/NREN/...) used for aggregate dashboards (ISP/NREN/...) used for aggregate dashboards
Extracts information from interfaces to be used in panels. Extracts information from interfaces to be used in panels.
Aggregate dashboards have aggregates at the top for all remotes Aggregate dashboards have aggregates at the top for all groups
as well as aggregate panels for specific remotes. as well as aggregate panels for specific groups.
This builds a dict with interfaces for each remote This builds a dict with interfaces for each group
and one with all interfaces. and one with all interfaces.
""" """
result = [] result = []
def reduce_func(prev, curr): def get_reduce_func_for_field(field):
remotes = prev.get(curr['remote'], []) def reduce_func(prev, curr):
remotes.append(curr) groups = prev.get(curr[field], [])
all_agg = prev.get('EVERYSINGLETARGET', []) groups.append(curr)
all_agg.append(curr) all_agg = prev.get('EVERYSINGLETARGET', [])
prev[curr['remote']] = remotes all_agg.append(curr)
prev['EVERYSINGLETARGET'] = all_agg prev[curr[field]] = groups
return prev prev['EVERYSINGLETARGET'] = all_agg
return prev
return reduce_func
for interface in interfaces: for interface in interfaces:
...@@ -193,9 +195,10 @@ def get_aggregate_interface_data(interfaces, agg_type): ...@@ -193,9 +195,10 @@ def get_aggregate_interface_data(interfaces, agg_type):
'interface': interface_name, 'interface': interface_name,
'hostname': host, 'hostname': host,
'remote': remote, 'remote': remote,
'location': location,
'alias': f"{location} - {remote} ({interface_name})", 'alias': f"{location} - {remote} ({interface_name})",
}) })
return reduce(reduce_func, result, {}) return reduce(get_reduce_func_for_field(group_field), result, {})
def get_aggregate_targets(targets): def get_aggregate_targets(targets):
......
...@@ -11,6 +11,7 @@ DEFAULT_REQUEST_HEADERS = { ...@@ -11,6 +11,7 @@ DEFAULT_REQUEST_HEADERS = {
TEST_DASHBOARD = { TEST_DASHBOARD = {
"tag": "TEST_AGGREGATE", "tag": "TEST_AGGREGATE",
"dashboard_name": "TEST CLS Peers", "dashboard_name": "TEST CLS Peers",
"group_by": "remote",
"interfaces": [ "interfaces": [
{ {
"router": "mx1.gen.ch.geant.net", "router": "mx1.gen.ch.geant.net",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment