Thursday, March 18, 2021

Netmiko and threading

I'm looking for a bit of assistance with Python. I wrote this script to log on to each device in my network then ping all of the other devices. It can take a long time though so I am looking to be able to use threading to speed this up. My script iterates through a list of routers, then in each iteration/loop it pings all the other routers in the list. I have tried to look at various threading examples online but they have been simple examples with one command, e.g. 'show run' I'm struggling to incorporate that functionality into my current script because I need to pass in multiple varibles and do a for loop etc. I also want to be able to specify the number of threads. (I have seen some examples where you can do this and some seem to just try every device in the list at once)

I have pasted my code below. Ignore everything to do with the csv file, I know I need to either move to a DB or use a Dataframe if I'm going to use threading but I can take care of that. I just want to know how I can have each iteration/for loop run separately. E.g. if I have 200 devices in the list, I want it to connect to the first 20 in the list and then ping all the other 199 routers.

Thank you very much

Edit: I removed the code and put it on Github gist as it looked horrible here.

https://gist.github.com/tars01/eaf9bb99b8002de7d4fd5037ee9e5c8e



No comments:

Post a Comment