diff --git a/brian_dashboard_manager/templating/helpers.py b/brian_dashboard_manager/templating/helpers.py index e3f58ac01649a948830268f28eaf933fe23a5374..649179452a6de94805496aa2f00a9eda9d396fd0 100644 --- a/brian_dashboard_manager/templating/helpers.py +++ b/brian_dashboard_manager/templating/helpers.py @@ -24,6 +24,18 @@ PANEL_WIDTH = 24 logger = logging.getLogger(__file__) +def endpoint_sort_key(endpoint): + # sort by equipment/port if exists, otherwise host/interface + if 'equipment' in endpoint: + equipment = endpoint['equipment'] + port = endpoint['port'] + return equipment, port + else: + hostname = endpoint['hostname'] + interface = endpoint['interface'] + return hostname, interface + + def num_generator(start=30): """ Generator for numbers starting from the value of `start` @@ -223,7 +235,7 @@ def get_re_peer_interface_data(interfaces): def get_service_aggregate_targets(services): for service in services: - _interfaces = service.get('endpoints') + _interfaces = sorted(service.get('endpoints', []), key=endpoint_sort_key) name = service.get('name') sid = service.get('sid') scid = service.get('scid') @@ -309,7 +321,7 @@ def get_nren_interface_data(services, interfaces, excluded_dashboards, region_cu dashboard['AGGREGATES'].append(target) for service in services: - _interfaces = service.get('endpoints') + _interfaces = sorted(service.get('endpoints', []), key=endpoint_sort_key) name = service.get('name') sid = service.get('sid') scid = service.get('scid') @@ -450,7 +462,7 @@ def get_service_data(service_type, services, interfaces, excluded_dashboards): }) for service in services: - _interfaces = service.get('endpoints') + _interfaces = sorted(service.get('endpoints', []), key=endpoint_sort_key) name = service.get('name') sid = service.get('sid') scid = service.get('scid')