From 69f63ee8ee1744f760dcbde9c11082cfd3e3aef0 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 27 Nov 2020 16:55:51 +0000 Subject: [PATCH] added handling IP PEERING - NON R&E (PUBLIC) --- inventory_provider/routes/ims_classifier.py | 46 +++++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/inventory_provider/routes/ims_classifier.py b/inventory_provider/routes/ims_classifier.py index f2c5f4f1..91ca946b 100644 --- a/inventory_provider/routes/ims_classifier.py +++ b/inventory_provider/routes/ims_classifier.py @@ -3,6 +3,7 @@ import itertools import json import logging import re +from copy import copy from functools import lru_cache from typing import Optional, Iterator, List @@ -143,25 +144,34 @@ def get_top_level_services(circuit_id: str, r: Redis) -> List[dict]: if results: results = json.loads(results.decode('utf-8')) + def _is_tls(candidate): + tls_names = copy(IMS_SERVICE_NAMES) + + # whilst this is a service type the top level for reporting + # are the BGP services on top of it + tls_names.remove('IP PEERING - NON R&E (PUBLIC)') + if candidate['product'] in tls_names: + return True + if candidate['speed'] == 'BGP': + return True + return False + # should only ever be one, may refactor this - for c in results: - if c['product'] in IMS_SERVICE_NAMES: - circuit_type = 'service' - else: - circuit_type = 'circuit' - if c['sub-circuits'] and circuit_type == 'circuit': - for sub in c['sub-circuits']: - temp_parents = \ - get_top_level_services(sub, r) - tls.update({t['id']: t for t in temp_parents}) - elif circuit_type == 'service': - tls[c['id']] = { - 'id': c['id'], - 'name': c['name'], - 'status': c['status'], - 'circuit_type': circuit_type, - 'project': c['project'] - } + c = results[0] + + if _is_tls(c): + tls[c['id']] = { + 'id': c['id'], + 'name': c['name'], + 'status': c['status'], + 'circuit_type': 'service', + 'project': c['project'] + } + elif c['sub-circuits']: + for sub in c['sub-circuits']: + temp_parents = \ + get_top_level_services(sub, r) + tls.update({t['id']: t for t in temp_parents}) return list(tls.values()) -- GitLab