Network Automation: Multithreading in Netmiko Script for Concurrent command execution

Publicado el: 07 enero 2024
en el canal de: NetworkEvolution
859
18

#networkautomation #networkengineers #pythontutorial
𝗙𝗼𝗿 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲 𝗣𝘆𝘁𝗵𝗼𝗻 𝗳𝗼𝗿 𝗡𝗲𝘁𝘄𝗼𝗿𝗸 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝘀 𝗧𝘂𝘁𝗼𝗿𝗶𝗮𝗹𝘀:
𝗘𝗻𝗿𝗼𝗹𝗹 𝗶𝗻 𝘁𝗵𝗲 𝗯𝗲𝗹𝗼𝘄 𝗨𝗱𝗲𝗺𝘆 𝗖𝗼𝘂𝗿𝘀𝗲:

https://www.udemy.com/course/python-f...

𝗣𝗹𝗮𝘆𝗹𝗶𝘀𝘁: 𝗣𝘆𝘁𝗵𝗼𝗻 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗳𝗼𝗿 𝗡𝗲𝘁𝘄𝗼𝗿𝗸 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝘀(𝟭𝟮𝟬+ 𝗩𝗶𝗱𝗲𝗼𝘀)
   • Welcome to NetworkEvolution !!  

☸𝗣𝗹𝗲𝗮𝘀𝗲 𝗳𝗼𝗹𝗹𝗼𝘄 𝗯𝗲𝗹𝗼𝘄 𝗚𝗶𝘁𝗛𝘂𝗯 𝗣𝗮𝗴𝗲 𝗳𝗼𝗿 𝘁𝗵𝗲 𝗹𝗮𝘁𝗲𝘀𝘁 𝗰𝗼𝗱𝗲𝘀:
https://github.com/network-evolution

𝗣𝗹𝗮𝘆𝗹𝗶𝘀𝘁: 𝗖𝗶𝘀𝗰𝗼 𝗡𝗫𝗔𝗣𝗜-𝗖𝗟𝗜 𝗣𝘆𝘁𝗵𝗼𝗻 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻: 𝗡𝗲𝘅𝘂𝘀 𝟵𝗸 :𝗣𝗮𝗿𝘀𝗲 𝗷𝘀𝗼𝗻 𝗫𝗠𝗟 𝗖𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻 𝗗𝗮𝘁𝗮
   • Cisco Nexus 9K installation and API setup ...  

𝗣𝗹𝗮𝘆𝗹𝗶𝘀𝘁: 𝗟𝗲𝗮𝗿𝗻 𝘁𝗼 𝗣𝗮𝗿𝘀𝗲 𝗖𝗶𝘀𝗰𝗼 𝗖𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻 𝘂𝘀𝗶𝗻𝗴 𝗣𝘆𝘁𝗵𝗼𝗻 𝗥𝗲𝗴𝗘𝘅:𝗿𝗲 𝗧𝘂𝘁𝗼𝗿𝗶𝗮𝗹(𝟭𝟱+ 𝗩𝗶𝗱𝗲𝗼𝘀)
   • Learn to write your own RegEx Parser :Cisc...  

In this video, we're going to learn how to use the Python threading module to executecommands concurrently on multiple devices. This will allow us to create network automation scripts that are fast and efficient.

Netmiko is a powerful network automation platform that makes it easy to create and manage network commands. In this video, we're going to learn how to use the Python threading module to create network automation scripts that are fast and efficient.
###################################################################
network automation tutorial
exception hadling in netmiko
python for network automation
create function in python, network automation python example
python threading examples
how to use python threading module for network automation
netmiko concurrent task execution on multiple devices
paralelly execute tasks in the device
run same task paralelly on multiple devices, network automation example
network automation multi threading
netmiko device configuration multithreading example

Script
from netmiko import ConnectHandler, exceptions
from datetime import datetime
import threading

lab_csr = {
'device_type': 'cisco_ios',
'host': '192.168.0.63',
'username': 'admin',
'password': 'admin'
}
vIOS1 = {
'device_type': 'cisco_ios',
'host': '192.168.0.61',
'username': 'admin',
'password': 'admin'
}
vIOS2 = {
'device_type': 'cisco_ios',
'host': '192.168.0.62',
'username': 'admin',
'password': 'admin'
}
hosts = [lab_csr, vIOS1, vIOS2]
start_time = datetime.now()

def netmiko_connect(**device):
try:
net_connect = ConnectHandler(**device)
print(f"Connected Successfully to the Device: {device['host']}")
output = net_connect.send_command('show version')
print(output)
print(f"Writing output to the File: {device['host']}.txt")
with open(f"{device['host']}.txt", 'w') as data:
data.write(output)
net_connect.disconnect()
except exceptions.NetmikoAuthenticationException:
print(f"Authentication failed on {device['host']}")
except exceptions.NetmikoTimeoutException:
print(f"Session timeout on {device['host']}")


cisco_config_threads = []
for host in hosts:
config_thread = threading.Thread(target=netmiko_connect, kwargs=host)
config_thread.start()
cisco_config_threads.append(config_thread)
for thread in cisco_config_threads:
thread.join()

end_time = datetime.now()
print(end_time - start_time)


En esta página del sitio puede ver el video en línea Network Automation: Multithreading in Netmiko Script for Concurrent command execution de Duración hora minuto segunda en buena calidad , que subió el usuario NetworkEvolution 07 enero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 859 veces y le gustó 18 a los espectadores. Disfruta viendo!