diff --git a/inventory_provider/config.py b/inventory_provider/config.py index d8ce6e9f5ba1200789cb74ad565c947632f2d6a9..2ddd10ee4957f549742900d8460da25a4e8e386f 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -108,6 +108,10 @@ CONFIG_SCHEMA = { "items": {"type": "integer"} }, "managed-routers": {"type": "string"}, + "lab-routers": { + "type": "array", + "items": {"type": "string"} + }, "unmanaged-interfaces": { "type": "array", "items": {"$ref": "#/definitions/interface-address"} diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 9102731490f31548ccb06818d5e109196635dce2..00595f41fe70a93c07aa805288f8ef86d4b25647 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -469,6 +469,32 @@ def refresh_juniper_interface_list(hostname, netconf): rp.execute() +@app.task(base=InventoryTask, bind=True, name='reload_router_config') +@log_task_entry_and_exit +def reload_lab_router_config(self, hostname): + self.log_info(f'loading netconf data for lab {hostname}') + + # load new netconf data, in this thread + netconf_refresh_config.apply(args=[hostname]) + + netconf_doc = load_netconf_data(hostname) + + # load snmp indexes + community = juniper.snmp_community_string(netconf_doc) + if not community: + raise InventoryTaskError( + f'error extracting community string for {hostname}') + else: + self.log_info(f'refreshing snmp interface indexes for {hostname}') + logical_systems = juniper.logical_systems(netconf_doc) + + # load snmp data, in this thread + snmp_refresh_interfaces.apply( + args=[hostname, community, logical_systems]) + + self.log_info(f'updated configuration for lab {hostname}') + + @app.task(base=InventoryTask, bind=True, name='reload_router_config') @log_task_entry_and_exit def reload_router_config(self, hostname): @@ -483,6 +509,8 @@ def reload_router_config(self, hostname): logger.debug( 'current netconf timestamp: %r' % current_netconf_timestamp) except InventoryTaskError: + # NOTE: should always reach here, + # since we always erase everything before starting pass # ok at this point if not found # load new netconf data, in this thread @@ -562,6 +590,11 @@ def internal_refresh_phase_2(self): logger.debug('queueing router refresh jobs for %r' % hostname) subtasks.append(reload_router_config.apply_async(args=[hostname])) + lab_routers = InventoryTask.config.get('lab-routers', []) + for hostname in lab_routers: + logger.debug('queueing router refresh jobs for lab %r' % hostname) + subtasks.append(reload_lab_router_config.apply_async(args=[hostname])) + pending_task_ids = [x.id for x in subtasks] refresh_finalizer.apply_async(args=[json.dumps(pending_task_ids)])