diff --git a/inventory_provider/storage/external_inventory.py b/inventory_provider/storage/external_inventory.py index 4e53893032b09f5390ea53d758ae14fd97df6819..a32fed4a0eba4c5582c69a8f070468ada68b686d 100644 --- a/inventory_provider/storage/external_inventory.py +++ b/inventory_provider/storage/external_inventory.py @@ -12,6 +12,7 @@ service_parent_to_children_key = "inv_service_parent_to_children" def update_services_to_monitor(services): r = db.get_redis() relevant_types = ('path', 'service', 'l2circuit') + r.delete(services_key) for service in services: if service['circuit_type'].lower() in relevant_types: r.hset(services_key, service['id'], json.dumps(service)) @@ -20,6 +21,7 @@ def update_services_to_monitor(services): def update_interfaces_to_services(services): r = db.get_redis() mapped_interfaces = {} + r.delete(interfaces_key) for service in services: key = "{}::{}".format( service['equipment'], @@ -42,13 +44,18 @@ def update_service_hierarchy(records): parents_to_children[parent_id].append(relation) children_to_parents[child_id].append(relation) + + r.delete(service_child_to_parents_key) for child, parents in children_to_parents.items(): r.hset(service_child_to_parents_key, child, json.dumps(parents)) + + r.delete(service_parent_to_children_key) for parent, children in parents_to_children.items(): r.hset(service_parent_to_children_key, parent, json.dumps(children)) def update_equipment_locations(equipment_location_data): r = db.get_redis() + r.delete(equipment_locations_key) for ld in equipment_location_data: r.hset(equipment_locations_key, ld['equipment_name'], json.dumps(ld))