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

added update_interfaces_tio_services

parent 0136eb04
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,13 @@ def flushdb():
# IMS routes
@routes.route("update-interfaces-to-services", methods=['GET', 'POST'])
def update_interfaces_to_services_ims():
worker.update_interfaces_to_services.delay(use_current=True)
return Response('OK')
@routes.route("update-fibre-spans", methods=['GET', 'POST'])
def update_fibre_spans_ims():
worker.update_fibre_spans.delay(use_current=True)
......@@ -33,7 +40,7 @@ def update_interfaces_to_port_id_ims():
@routes.route("update-port-ids-to-services", methods=['GET', 'POST'])
def update_interfaces_to_services_ims():
def update_port_ids_to_services_ims():
worker.update_port_ids_to_services.delay(use_current=True)
return Response('OK')
......
......@@ -450,6 +450,7 @@ def internal_refresh_phase_2(self):
subtasks = [
update_circuit_hierarchy.apply_async(),
update_interfaces_to_services.apply_asynch(),
update_interfaces_to_port_ids.apply_async(),
update_port_ids_to_services.apply_async(),
import_unmanaged_interfaces.apply_async()
......@@ -533,6 +534,63 @@ def update_interfaces_to_port_ids(self, use_current=False):
rp.execute()
@app.task(
base=InventoryTask, bind=True, name='update_interfaces_to_services')
@log_task_entry_and_exit
def update_interfaces_to_services(self, use_current=False):
port_id_services = defaultdict(list)
c = InventoryTask.config["ims"]
ds = IMS(c['api'], c['username'], c['password'])
if use_current:
r = get_current_redis(InventoryTask.config)
else:
r = get_next_redis(InventoryTask.config)
rp = r.pipeline()
# scan with bigger batches, to mitigate network latency effects
for key in r.scan_iter('ims:port_id_services:*', count=2000):
rp.delete(key)
rp.execute()
locations = {k: v for k, v in ims_data.get_node_locations(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
s['card_d'] = '' # this is redundant I believe
s['port'] = port # this is redundant I believe
s['logical_unit'] = '' # this is redundant I believe
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']
services = []
for service in port_id_services[port_info['port_id']]:
_format_service(service, port_info['interface_name'], location)
services.append(service)
rp.set(
f'ims:interface_services:{port_info["equipment_name"]}:'
f'{port_info["interface_name"]}',
json.dumps(services))
rp.execute()
@app.task(
base=InventoryTask, bind=True, name='update_port_ids_to_services')
@log_task_entry_and_exit
......
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