Skip to content
Snippets Groups Projects
Commit 9a47f5e1 authored by Robert Latta's avatar Robert Latta
Browse files

added route for tnms fibre trap classification

parent 90963544
No related branches found
No related tags found
No related merge requests found
......@@ -883,6 +883,103 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \
return Response(result, mimetype="application/json")
@routes.route("/tnms-fibre-info/<path:enms_pc_name>", methods=['GET', 'POST'])
@common.require_accepts_json
def get_tnms_fibre_trap_metadata(enms_pc_name: str) -> Response:
"""
Handler for /classifier/infinera-fiberlink-info that
returns metadata for a particular opitical path segment.
TODO: no schema is declared, and there are no validation tests
:param enms_pc_name: both node names separated by a forward slash
:return:
"""
r = common.get_current_redis()
# double check that we only need to check the two nodes and not the objects
cache_key = f'classifier-cache:fiberlink:{enms_pc_name}'
result = _ignore_cache_or_retrieve(request, cache_key, r)
if not result:
logger.debug("1")
try:
equipment_a, equipment_b = enms_pc_name.split("/")
logger.debug(f"{equipment_a} - {equipment_b}")
except ValueError:
raise ClassifierProcessingError(
f'unable to parse {enms_pc_name} '
'into two elements')
circuits = r.get(f'ims:node_pair_services:{enms_pc_name}')
all_frs = {}
all_tls = {}
contacts = set()
if circuits:
circuits = json.loads(circuits.decode('utf-8'))
for c in circuits:
contacts.update(c['contacts'])
for fr in c['fibre-routes']:
all_frs[fr['id']] = fr
for fr in c['related-services']:
all_tls[fr['id']] = fr
fibre_routes = list(all_frs.values())
top_level_services = list(all_tls.values())
if fibre_routes:
location_a = _location_from_equipment(equipment_a, r)
location_b = _location_from_equipment(equipment_b, r)
if location_a:
loc_a = location_a
else:
loc_a = _LOCATION(equipment_a, '', '')
if location_b:
loc_b = location_b
else:
loc_b = _LOCATION(equipment_b, '', '')
# added locations in preparation for refactoring to be in-line
# with other location data. Once Dashboard has been altered to
# use this for fiberlink alarms the 'ends' attribute can be
# removed
result = {
'locations': [
build_locations(loc_a, loc_b)
],
'ends': {
'a': {
'pop': loc_a['name'],
'pop_abbreviation': loc_a['abbreviation'],
'equipment': loc_a['equipment']
},
'b': {
'pop': loc_b['name'],
'pop_abbreviation': loc_b['abbreviation'],
'equipment': loc_b['equipment']
},
},
'df_route': fibre_routes[0],
'related-services': top_level_services,
'contacts': sorted(list(contacts))
}
for rs in result['related-services']:
rs.pop('id', None)
result = json.dumps(result)
r.set(cache_key, result)
if not result:
return Response(
response=f"no available info for {enms_pc_name}",
status=404,
mimetype="text/html")
return Response(result, mimetype="application/json")
@routes.route('/coriant-info/<equipment_name>/<path:entity_string>',
methods=['GET', 'POST'])
@common.require_accepts_json
......
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