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

added job to update redis ims:interface_service info

parent 84d0c1cc
Branches
Tags
No related merge requests found
...@@ -3,6 +3,7 @@ import json ...@@ -3,6 +3,7 @@ import json
import logging import logging
import subprocess import subprocess
import tempfile import tempfile
from collections import defaultdict
from datetime import datetime from datetime import datetime
from enum import IntFlag from enum import IntFlag
from pathlib import Path from pathlib import Path
...@@ -21,6 +22,41 @@ environment.setup_logging() ...@@ -21,6 +22,41 @@ environment.setup_logging()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@app.task(
base=InventoryTask, bind=True, name='update_interfaces_to_services_ims')
@log_task_entry_and_exit
def update_interfaces_to_services_ims(self, use_current=False):
interface_services = defaultdict(list)
c = InventoryTask.config["ims"]
ds = IMS(c['api'], c['username'], c['password'])
for service in ims_data.get_interface_services(ds):
equipment_interface = '%s:%s' % (
service['equipment'], service['interface_name'])
interface_services[equipment_interface].append(service)
if use_current:
r = get_current_redis(InventoryTask.config)
# scan with bigger batches, to mitigate network latency effects
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:interface_services:*', count=1000):
rp.delete(key)
rp.execute()
rp = r.pipeline()
for equipment_interface, services in interface_services.items():
rp.set(
f'ims:interface_services:{equipment_interface}',
json.dumps(services))
rp.execute()
@app.task(base=InventoryTask, bind=True, name='update_circuit_hierarchy_ims') @app.task(base=InventoryTask, bind=True, name='update_circuit_hierarchy_ims')
@log_task_entry_and_exit @log_task_entry_and_exit
def update_circuit_hierarchy_ims(self, use_current=False): def update_circuit_hierarchy_ims(self, use_current=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment