This lesson is part of the Network Configuration with Netmiko Course.
In this lesson, we will cover:
- Review of single-threaded Netmiko execution.
- How to write a multiple threaded Netmiko script.
- Time testing and comparing single-threaded vs multi-threaded Netmiko execution.
The scripts and code for this lesson can be found within the Netmiko repo under the directory: examples/004_optimization/multithreading
.
Introduction
So far through this guide, we have run Netmiko against a single device. However, what about if we want to start running Netmiko across multiple devices? This section will look at how we can use multithreading to scale Netmiko to run across multiple devices.
Single-Threaded
Let's create a script to run a command against multiple devices. To do so, we use many of the commands and Netmiko methods that we have previously learnt, along with:
- defining a
list()
ofport
s anddevice_types
. - adding a timer to time how long the script takes using the
time
module. - iterating over our device
list()
, performing thesend_command
on each iteration, collects the output ofshow version
.