From ab4e03e38bf70abe52d261c75b146829e8fc1fb5 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sat, 13 Apr 2019 13:38:06 +0200
Subject: [PATCH] save list of locations to redis cache

---
 inventory_provider/tasks/worker.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index 5335b0b5..045bef10 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -146,8 +146,10 @@ def update_equipment_locations():
 
     with db.connection(InventoryTask.config["ops-db"]) as cx:
         for h in _derive_router_hostnames(InventoryTask.config):
-            for ld in opsdb.lookup_pop_info(cx, h):
-                r.set('opsdb:location:%s' % h, json.dumps(ld))
+            # lookup_pop_info returns a list of locations
+            # (there can sometimes be more than one match)
+            locations = list(opsdb.lookup_pop_info(cx, h))
+            r.set('opsdb:location:%s' % h, json.dumps(locations))
 
     logger.debug('<<< update_equipment_locations')
 
-- 
GitLab