Hi All,
have recently started learning python and was able to get to scrape through to get a script going for sending config to multiple devices. but it seems that i messed up somewhere and am unable to SSH/Telnet to the cisco devices when running the script and on checking different forums i am drawing a blank now.
here is the script if someone could please help me find the issue.
@rohitarora25 This is too generic a description.
You need to post a more clear description of the problem you are running into (the exception you get)? And what you have tried to do to resolve it.
Regards,
Kirk
sorry for the trouble, but i think i am not able to call the username and password correctly. here is the essential part(sorry for the formatting):-
```python
def credentials():
usern = input('Enter Username: ')
pwd = None
while not pwd:
pwd = getpass()
pwd_verify = getpass('Retype the password to verify: ')
if pwd != pwd_verify:
print('Password do not match')
pwd = None
return usern, pwd
usern, pwd = credentials()
def main_thread(TEST):
with open('errors.txt', 'w') as f1:
try:
Routers = {
'device_type': 'cisco_ios_ssh', 'ip': TEST, 'username': usern, 'password': pwd, 'secret': pwd, 'verbose': False
}
net_connect = ConnectHandler(**Routers)
hostname = net_connect.find_prompt()
'''
there is no device_type "cisco_ios_ssh," please refer to the examples for proper Cisco IOS device_type, such as "cisco_ios"
cisco_ios_ssh is perfectly fine for device_type. Netmiko allows vendor_platform_transport it just happens to default to ssh for the transport so cisco_ios and cisco_ios_ssh are identical.
@rohitarora25 In a simple Netmiko test case, where you eliminate your threading code, what happens?
@ktbyers i have a simple script up and running and it works flawlessly.. the only problem is that it took me 3hrs to push a change config on 350 devices.. hence i decided reading about threading and threadpool.
now as i have to run the code in a VM which doesnt have python installed hence i have to compile the code using pyinstaller.. and then run on there...
the output that i get is SSH successful log message.. and then 10seconds later i get SSH failed Writing logs and that's it..
i am pretty much stuck here.. :(
P.S. for some reason i wasnt able to copy the entire code here properly despite using '''python so have uploaded my entire updated code
threading.txt
as .txt file
So Netmiko is working fine. You are having a threading issue.
You might want to look at Nornir which has Netmiko integrated into it and use the threading built into Nornir.
Did you resolve the issue? I am having a similar problem where the executable (pyinstaller) runs in to problem to establish connections (both SSH and Telnet). The python script works, but the executable does not work reliably.
@rohitarora25 , did Nornir solve the issue? @ktbyers , what could be the reason that default Python threading does not work for executable but works perfectly for the script?
@m6461
what could be the reason that default Python threading does not work for executable but works perfectly for the script?
The most likely cause is that the individual mis-implemented the threading.
Threading can easily introduce race conditions so it might work in one context and fail in another context (once again likely do the given user's code). Note, this is not a comment on your code (which I haven't seen), but a general comment for what is by far the most common cause of problems similar to this.
Nornir implements threading and allows the use of Netmiko (and has been used/tested by a lot of people). Consequently, it is highly advisable to use this instead of implementing your own threading solution.
Thanks. It helps.
Most helpful comment
So Netmiko is working fine. You are having a threading issue.
You might want to look at Nornir which has Netmiko integrated into it and use the threading built into Nornir.