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

corrected loading coriant details

parent b9f7486f
No related branches found
No related tags found
No related merge requests found
......@@ -134,6 +134,11 @@ def get_port_id_services(ds: IMS):
_circuit['port_a_id'], _circuit['port_b_id'] = \
_circuit['port_b_id'], _circuit['port_a_id']
yield _circuit
if len(port_ids) > 2:
_circuit.pop('port_b_id', None)
for p in port_ids[1:-1]:
_circuit['port_a_id'] = p
yield _circuit
for circuit in circuits:
cd = {
......@@ -147,15 +152,13 @@ def get_port_id_services(ds: IMS):
}
ports = []
if circuit['internalports']:
tmp_ports = sorted(
ports = sorted(
circuit['internalports'], key=lambda x: x['sequencenumber'])
ports = [tmp_ports[0]['id'], tmp_ports[-1]['id']]
ports = [p['id'] for p in ports]
elif circuit['ports']:
tmp_ports = sorted(
ports = sorted(
circuit['ports'], key=lambda x: x['sequencenumber'])
ports = [tmp_ports[0]['id'], tmp_ports[-1]['id']]
# elif circuit['internalportaid'] or circuit['internalportbid']:
# ports = [circuit['internalportaid'], circuit['internalportbid']]
ports = [p['id'] for p in ports]
elif circuit['portaid'] or circuit['portbid']:
ports = [circuit['portaid'], circuit['portbid']]
yield from _populate_end_info(cd, ports)
......
......@@ -197,7 +197,6 @@ def get_related_services(source_equipment: str, interface: str, r) -> dict:
yield from get_top_level_services(s['id'], r)
for related in related_interfaces(source_equipment, interface):
ims_interface = get_ims_interface(related)
logger.debug(f'Related Interface: {ims_interface}')
rif_services = r.get(
f'ims:interface_services:{ims_source_equipment}:{ims_interface}')
if rif_services:
......@@ -661,10 +660,12 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \
@common.require_accepts_json
def get_coriant_info(equipment_name: str, entity_string: str) -> Response:
r = common.get_current_redis()
equipment_name = get_ims_equipment_name(equipment_name)
cache_key = 'ims-classifier-cache:coriant:%s:%s' % (
equipment_name, entity_string)
ims_source_equipment = get_ims_equipment_name(equipment_name)
ims_interface = get_ims_interface(entity_string)
cache_key = 'ims-classifier-cache:coriant:' \
f'{ims_source_equipment}:{ims_interface}'
ignore_cache = request.args.get('ignore-cache', default='false', type=str)
try:
......@@ -680,61 +681,27 @@ def get_coriant_info(equipment_name: str, entity_string: str) -> Response:
result = result.decode('utf-8')
else:
m = re.match(r'^(\d+\-\d+)\.(\d+)', entity_string)
m = re.match(r'^(\d+\-\d+)\.(\d+)', ims_interface)
if not m:
logger.error(
'invalid coriant entity string format: %r' % entity_string)
f'invalid coriant entity string format: {ims_interface}')
return Response(
response="no available info for '{}' '{}'".format(
equipment_name, entity_string),
response="no available info for "
f"'{ims_source_equipment}' '{ims_interface}'",
status=404,
mimetype="text/html")
result = {
'equipment name': equipment_name,
'equipment name': ims_source_equipment,
'card id': m.group(1).replace('-', '/'),
'port number': m.group(2),
'locations': []
'port number': m.group(2)
}
interface_name = f'{result["card id"]}/{result["port number"]}'
top_level_services = []
services = r.get(
f'ims:interface_services:{equipment_name}:{interface_name}')
if services:
result['services'] = json.loads(services.decode('utf=8'))
for s in result['services']:
top_level_services.extend(get_top_level_services(s['id'], r))
result['locations'] += \
_location_from_equipment(s['equipment'], r)
result['locations'] += \
_location_from_equipment(s['other_end_equipment'], r)
def _related_services():
for related in related_interfaces(equipment_name, interface_name):
logger.debug(f'Related Interface: {related}')
rs = r.get(f'ims:interface_services:{equipment_name}:'
f'{related.upper()}')
if rs:
for s in json.loads(rs.decode('utf-8')):
top_level_services.extend(
get_top_level_services(s['id'], r))
yield {
'name': s['name'],
'status': s['status'],
'circuit_type': s['circuit_type'],
'project': s['project']
}
related_services = list(_related_services())
if related_services:
top_level_services.extend(related_services)
if top_level_services:
result['related-services'] = top_level_services
if not result['locations']:
result['locations'] = _location_from_equipment(equipment_name, r)
result.update(get_interface_services_and_locs(
ims_source_equipment,
interface_name,
r
))
result['locations'] = _remove_duplicates_from_list(result['locations'])
result = json.dumps(result)
......
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