With 3.7.0a1, you can follow the progress of a run, cancel it, and set time limits, with the tasks and the runner that you already use. Applications that run an event loop can also run async def tasks and load the inventory on that loop. Existing scripts keep working, and ThreadedRunner is still the default runner.
Note
3.7.0a1 is a pre-release. Install it with pip install "nornir==3.7.0a1". pip install --upgrade nornir does not install it. The new APIs can still change before 3.7.0, so do not use it in production.
Testing the 3.7 pre-releases explains how to install it, what to test, and where to send feedback.
New features
- Follow, cancel and time-limit runs. Follow each host with
nr.stream(). Start a run in the background withnr.submit(), and stop it withhandle.cancel(). Set a time limit for each host withper_host_timeout. This works with synchronous tasks onThreadedRunnerandSerialRunner(streamonly), and withAsyncioRunner. How-to guide (#1086, #1113) - Run
async deftasks. Select theasynciorunner and callawait nr.arun(...)to run tasks on the event loop of your application. Connection plugins can now support sync, asyncio or both. How-to guide (#1085, #1111) - Load the inventory from an async application.
nr = await AInitNornir(...)takes the same arguments asInitNornirand does not block the event loop. Existing inventory plugins work with it. How-to guide (#1087, #1112)
To test the async features against real systems, use the pre-releases of two plugins: nornir-scrapli==1.6.0a1 for network devices and nornir-infrahub==1.3.0a1 for the inventory. They are also examples for plugin developers. See Plugins that use the new APIs.
Behaviour changes
Nornir.runandTask.runnow raiseAsyncTaskOnSyncRunErrorfor anasync deftask. Before, the task did not run, but the host was reported as successful (#1111).- A task that contains
yieldnow runs. Before, the task did not run, but the host was reported as successful (#1113). InitNornirnow raisesTransformFunctionNotSyncErrorfor a transform function defined withasync def. Before, the transform function did not run (#1112).Host.close_connectionsnow tries to close every connection, then raises the first error. Before, it stopped at the first connection that it could not close (#1111).
Send feedback
Comment on the issue of the feature (#1085, #1086, #1087), or open a new issue for a bug. You can also write in the #nornir channel of the OpsMill Discord server or in the networktocode Slack team.
The changelog has the complete list of changes.
Full Changelog: v3.6.1...v3.7.0a1