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

added population of equipment location data and testing route to call it

parent 530dbd6e
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,11 @@ def flushdb():
# IMS routes
@routes.route("update-equipment-locations-ims", methods=['GET', 'POST'])
def update_equipment_locations_ims():
ims_worker.update_equipment_locations_ims.delay(use_current=True)
return Response('OK')
@routes.route("update-lg-routers-ims", methods=['GET', 'POST'])
def update_lg_routers_ims():
ims_worker.update_lg_routers_ims.delay(use_current=True)
......
......@@ -21,6 +21,35 @@ environment.setup_logging()
logger = logging.getLogger(__name__)
@app.task(base=InventoryTask, bind=True, name='update_equipment_locations_ims')
@log_task_entry_and_exit
def update_equipment_locations_ims(self, use_current=False):
r = get_current_redis(InventoryTask.config)
if use_current:
r = get_current_redis(InventoryTask.config)
rp = r.pipeline()
# scan with bigger batches, to mitigate network latency effects
for k in r.scan_iter('ims:location:*', count=1000):
rp.delete(k)
rp.execute()
else:
r = get_next_redis(InventoryTask.config)
c = InventoryTask.config["ims"]
ds = IMS(c['api'], c['username'], c['password'])
rp = r.pipeline()
hostnames_found = set()
for h, d in ims_data.get_node_locations(ds):
# put into a list to match non-IMS version
rp.set(f'ims:location:{h}', json.dumps([d]))
if h in hostnames_found:
print(f'Multiple entries for {h}')
hostnames_found.add(h)
rp.execute()
@app.task(base=InventoryTask, bind=True, name='update_lg_routers_ims')
@log_task_entry_and_exit
def update_lg_routers_ims(self, use_current=False):
......
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