From 1e3d6c25de953fc88f610bc5629404dcfc00e850 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Wed, 10 Mar 2021 16:53:00 +0000 Subject: [PATCH] corrected deletion key; added location info to services --- inventory_provider/tasks/worker.py | 36 +++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 1c6dac41..e0330a0c 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -550,38 +550,48 @@ def update_interfaces_to_services(self, use_current=False): rp = r.pipeline() # scan with bigger batches, to mitigate network latency effects - for key in r.scan_iter('ims:port_id_services:*', count=2000): + for key in r.scan_iter('ims:interface_services:*', count=2000): rp.delete(key) rp.execute() locations = {k: v for k, v in ims_data.get_node_locations(ds)} + port_id_details = {d['port_id']: d for d in ims_data.get_port_details(ds)} for service in ims_data.get_port_id_services(ds): port_id_services[service["port_a_id"]].append(service) rp = r.pipeline() - def _format_service(s, port, loc): - s['pop_name'] = loc['name'] - s['pop_abbreviation'] = loc['abbreviation'] - s['equipment'] = '' # this is redundant I believe + def _format_service(s): + pd_a = port_id_details[s['port_a_id']] + loc_a = locations[pd_a['equipment_name']]['pop'] + s['pop_name'] = loc_a['name'] + s['pop_abbreviation'] = loc_a['abbreviation'] + s['equipment'] = pd_a['equipment_name'] s['card_d'] = '' # this is redundant I believe - s['port'] = port # this is redundant I believe + s['port'] = pd_a['interface_name'] s['logical_unit'] = '' # this is redundant I believe + if 'port_b_id' in s: + pd_b = port_id_details[s['port_b_id']] + loc_b = locations[pd_b['equipment_name']]['pop'] + s['other_end_pop_name'] = loc_a['name'] + s['other_end_pop_abbreviation'] = loc_b['abbreviation'] + s['other_end_equipment'] = pd_b['equipment_name'] + s['other_end_port'] = pd_b['interface_name'] + else: + s['other_end_pop_name'] = '' + s['other_end_pop_abbreviation'] = '' + s['other_end_equipment'] = '' + s['other_end_port'] = '' - s['other_end_pop_name'] = '' # redundant - s['other_end_pop_abbreviation'] = '' # redundant - s['other_end_equipment'] = '' # this is redundant I believe s['other_end_card_d'] = '' # this is redundant I believe - s['other_end_port'] = '' # this is redundant I believe s['other_end_logical_unit'] = '' # this is redundant I believe s['manufacturer'] = '' # this is redundant I believe s.pop('port_a_id', None) s.pop('port_b_id', None) - for port_info in ims_data.get_port_details(ds): - location = locations[port_info['equipment_name']]['pop'] + for port_info in port_id_details.values(): services = [] for service in port_id_services[port_info['port_id']]: - _format_service(service, port_info['interface_name'], location) + _format_service(service) services.append(service) rp.set( -- GitLab