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() of ports and device_types.
  • adding a timer to time how long the script takes using the time module.
  • iterating over our device list(), performing the send_command on each iteration, collects the output of show version.
Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.