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

continued development; changed route and function name to match Infinera

parent 756e7570
Branches
Tags
No related merge requests found
...@@ -413,15 +413,18 @@ def get_trap_metadata(source_equipment, interface, circuit_id): ...@@ -413,15 +413,18 @@ def get_trap_metadata(source_equipment, interface, circuit_id):
return Response(result, mimetype="application/json") return Response(result, mimetype="application/json")
@routes.route("/infinera-fibrelink-info/<ne_name_str>/<object_name_str>", @routes.route("/infinera-fiberlink-info/<ne_name_str>/<object_name_str>",
methods=['GET', 'POST']) methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def get_fibrelink_trap_metadata(ne_name_str, object_name_str): def get_fiberlink_trap_metadata(ne_name_str, object_name_str):
objects = object_name_str.split('_') objects = object_name_str.split('_')
shelfs = [x.split('-')[0] for x in objects] shelves = [x.split('-')[0] for x in objects]
p = r'([a-zA-Z\d]+?-(OLA|DTNX)\d+(-\d)?)' p = r'([a-zA-Z\d]+?-(OLA|DTNX)\d+(-\d)?)'
matches = re.findall(p, ne_name_str) matches = re.findall(p, ne_name_str)
assert len(matches) == 2 if len(matches) != 2 or len(shelves) != 2:
raise ClassifierProcessingError(
f'unable to parse {ne_name_str} {object_name_str } '
'into two elements')
r = common.get_current_redis() r = common.get_current_redis()
...@@ -432,16 +435,15 @@ def get_fibrelink_trap_metadata(ne_name_str, object_name_str): ...@@ -432,16 +435,15 @@ def get_fibrelink_trap_metadata(ne_name_str, object_name_str):
if result: if result:
result = result.decode('utf-8') result = result.decode('utf-8')
else: else:
nes_a = f'{matches[0][0]}-{shelfs[0]}' nes_a = f'{matches[0][0]}-{shelves[0]}'
nes_b = f'{matches[1][0]}-{shelfs[1]}' nes_b = f'{matches[1][0]}-{shelves[1]}'
result = [] result = []
df_a = r.get(f'opsdb:ne_fibre_spans:{nes_a}') df_a = r.get(f'opsdb:ne_fibre_spans:{nes_a}')
df_b = r.get(f'opsdb:ne_fibre_spans:{nes_b}') df_b = r.get(f'opsdb:ne_fibre_spans:{nes_b}')
if df_a: if df_a and df_b:
a = json.loads(df_a.decode('utf-8')) a = json.loads(df_a.decode('utf-8'))
if df_b:
b = json.loads(df_b.decode('utf-8')) b = json.loads(df_b.decode('utf-8'))
if df_a and df_b:
matches = [x for x in itertools.product(a, b) if matches = [x for x in itertools.product(a, b) if
x[0]['df_route_id'] == x[1]['df_route_id']] x[0]['df_route_id'] == x[1]['df_route_id']]
if matches: if matches:
...@@ -469,7 +471,8 @@ def get_fibrelink_trap_metadata(ne_name_str, object_name_str): ...@@ -469,7 +471,8 @@ def get_fibrelink_trap_metadata(ne_name_str, object_name_str):
r.set(cache_key, result) r.set(cache_key, result)
if not result: if not result:
return Response( return Response(
response=f'no available info for {ne_name_str}', response="no available info for "
f"{ne_name_str} {object_name_str}",
status=404, status=404,
mimetype="text/html") mimetype="text/html")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment