diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 3c4ffff2b153cb5b5fad1d2aa42b097e28093bc1..ff507dda2bee5d7578cb25cdfceb4d1ac2b90b5c 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -464,9 +464,10 @@ def launch_refresh_cache_all(config): subtasks = [ update_equipment_locations.apply_async(), ] - for hostname in _derive_router_hostnames(config): - logger.debug( - 'queueing router refresh jobs for %r' % hostname) + # for hostname in _derive_router_hostnames(config): + hostnames = _derive_router_hostnames(config) + for hostname in hostnames[0:2]: + logger.debug('queueing router refresh jobs for %r' % hostname) subtasks.append(reload_router_config.apply_async(args=[hostname])) pending_task_ids = [x.id for x in subtasks] @@ -511,6 +512,36 @@ def refresh_finalizer(self, pending_task_ids_json): task_ids = json.loads(pending_task_ids_json) assert jsonschema.validate(task_ids, input_schema) _wait_for_tasks(task_ids) + _build_subnet_db() + + logger.debug('<<< refresh_finalizer') + + +def _build_subnet_db(): + + r = get_next_redis(InventoryTask.config) + + subnets = {} + for k in r.scan_iter('reverse_interface_addresses:*'): + info = r.get(k.decode('utf-8')).decode('utf-8') + info = json.loads(info) + entry = subnets.setdefault('subnet', []) + entry.append({ + 'interface name': info['interface name'], + 'router': info['router'] + }) + + for k, v in subnets.items(): + r.set('subnets:' + k, json.dumps(v)) + + +def refresh_interface_address_lookups(hostname, netconf): + _refresh_peers( + hostname, + 'reverse_interface_addresses', + juniper.interface_addresses(netconf)) + + def check_task_status(task_id):