diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index ccff949fec9f4b4313f396abfc8d57f821cd0150..685b2764a056087bb6ad1fe11117ff430687ecf4 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -13,6 +13,14 @@ routes = Blueprint("inventory-data-classifier-support-routes", __name__) logger = logging.getLogger(__name__) +def _LOCATION(equipment, name, abbreviation): + return { + 'equipment': equipment, + 'name': name, + 'abbreviation': abbreviation + } + + def _unique_dicts_from_list(l): tmp_dict = dict([(json.dumps(item, sort_keys=True), item) for item in l]) return list(tmp_dict.values()) @@ -31,32 +39,29 @@ def _location_from_router(router_name): return None return { - 'a': { - 'equipment': result[0]['equipment-name'], - 'name': result[0]['pop']['name'], - 'abbreviation': result[0]['pop']['abbreviation'] - } + 'a': _LOCATION( + equipment=result[0]['equipment-name'], + name=result[0]['pop']['name'], + abbreviation=result[0]['pop']['abbreviation']) } def _location_from_service_dict(s): location = { - 'a': { - 'equipment': s['equipment'], - 'name': s['pop_name'], - 'abbreviation': s['pop_abbreviation'] - } + 'a': _LOCATION( + equipment=s['equipment'], + name=s['pop_name'], + abbreviation=s['pop_abbreviation']) } if all(s[n] for n in ( 'other_end_equipment', 'other_end_pop_name', 'other_end_pop_abbreviation')): - location['b'] = { - 'equipment': s['other_end_equipment'], - 'name': s['other_end_pop_name'], - 'abbreviation': s['other_end_pop_abbreviation'] - } + location['b'] = _LOCATION( + equipment=s['other_end_equipment'], + name=s['other_end_pop_name'], + abbreviation=s['other_end_pop_abbreviation']) return location @@ -441,16 +446,14 @@ def get_coriant_info(equipment_name, entity_string): if path: result['path'] = path result['locations'] += [{ - 'a': { - 'equipment': path['a']['equipment name'], - 'name': path['a']['pop']['name'], - 'abbreviation': path['a']['pop']['abbreviation'] - }, - 'b': { - 'equipment': path['b']['equipment name'], - 'name': path['b']['pop']['name'], - 'abbreviation': path['b']['pop']['abbreviation'] - } + 'a': _LOCATION( + equipment=path['a']['equipment name'], + name=path['a']['pop']['name'], + abbreviation=path['a']['pop']['abbreviation']), + 'b': _LOCATION( + equipment=path['b']['equipment name'], + name=path['b']['pop']['name'], + abbreviation=path['b']['pop']['abbreviation']), }] top_level_services = get_top_level_services(path['id'], r)