Thursday, December 13, 2018

Paramiko no existing connection on reconnect

Have any of you ran into this specific problem on network python scripts:

I have a script that makes a device list from a text file with ip addresses, loops through that list and logs into the devices, pushes configs, commits, logs out, and moves on to the next device. Simple stuff, and it works great.

But there was a very high demand from my coworkers to add commit confirmed safety to my script.

So I tried to modify it a bit. Instead of commit, exit, and move to next device, I put in a new function where it will commit confirmed, exit the cli completely and then try to log back in the device, and commit check if it succeeds. Then finally exit and move to the new device.

Blizzare thing is I have so far utterly failed to make paramiko successfully log back in the same device after it logged out. The script gets all the way up to commit confirmed and exits, but then it fails every time to log back into the device. It throws an exception every time that terminates the script. The exception is as follows:

paramiko.SSHException: No existing session 

Weird thing is it’s part of a try/except statement but still crashes and ignored the except: clause anyway.

I realize I haven’t shared any specific code but I’m hoping this is something super common all network guys run into when they first start tangling with python that has a common fix that will seem obvious once you explain it to me.

Thanks!



No comments:

Post a Comment