moving into a vrf on a cisco device causes Netmiko to time out.
See original GitHub issueHello, so I have a scenario where I need to check some configuration in the global table and then in another vrf, however when doing this by sending multiple commands to netmiko I get a time out.
relevant code:
def ios_connector(i,q,ios_cmds,print_lock,outfile):
while True:
ip = q.get()
IOS = {
'device_type': 'cisco_ios',
'host': ip,
'username': conf.USERNAME,
'password': conf.PASSWORD,
#'secret': conf.SECRET,
}
# attempt to establish SSH session and quit with appropriate error if not successful
try:
starttime_time = datetime.now()
print('INFO: connecting to '+str(ip))
net_connect = ConnectHandler(**IOS)
# collect output
connection = net_connect.find_prompt()
res = []
for cmd in ios_cmds:
output = net_connect.send_command(cmd)
res.append(output)
with print_lock:
if len(res) > 0:
outfile.write(connection + " has returned the following output:\n\n")
for line in res:
outfile.write(line)
outfile.write('\n\n===\n\n')
else:
outfile.write(connection + "\nno matches\n\n===\n\n")
except (AuthenticationException):
print("ERROR: Authentication Failure to {}\n".format(ip))
q.task_done()
except (NetMikoTimeoutException):
print("ERROR: Timed out while trying to connect to {}\n".format(ip))
q.task_done()
except Exception as e:
print('ERROR: Connection refused by ' + ip +'\n' + e)
q.task_done()
except (OSError) as e:
print('ERROR: OSError\n' + e)
q.task_done()
except (EOFError) as e:
print('ERROR: EOF error\n' + e)
q.task_done()
finally:
net_connect.disconnect()
endtime = datetime.now()
print('Total time: {}'.format(endtime - starttime_time))
q.task_done()
from the debug it looks like it’s a problem with find_prompt() as the prompt changes to include the vrf name, however it still has the trailing # as you would expect.
debug:
DEBUG:paramiko.transport:starting thread (client mode): 0x3747ba30 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.1 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-Cisco-1.25 INFO:paramiko.transport:Connected (version 2.0, client -1.25) DEBUG:paramiko.transport:kex algos:[‘diffie-hellman-group-exchange-sha1’, ‘diffie-hellman-group14-sha1’] server key:[‘ssh-rsa’] client encrypt:[‘aes128-ctr’, ‘aes192-ctr’, ‘aes256-ctr’] server encrypt:[‘aes128-ctr’, ‘aes192-ctr’, ‘aes256-ctr’] client mac:[‘hmac-sha2-256’, ‘hmac-sha2-512’, ‘hmac-sha1’, ‘hmac-sha1-96’] server mac:[‘hmac-sha2-256’, ‘hmac-sha2-512’, ‘hmac-sha1’, ‘hmac-sha1-96’] client compress:[‘none’] server compress:[‘none’] client lang:[‘’] server lang:[‘’] kex follows?False DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha1 DEBUG:paramiko.transport:HostKey agreed: ssh-rsa DEBUG:paramiko.transport:Cipher agreed: aes128-ctr DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:Got server p (2048 bits) DEBUG:paramiko.transport:kex engine KexGex specified hash_algo <built-in function openssl_sha1> DEBUG:paramiko.transport:Switch to new keys … DEBUG:paramiko.transport:Adding ssh-rsa host key for redacted DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 4096 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:read_channel: THIS DEVICE IS PART OF A
------------------------ PRIVATE NETWORK --------------- ************************************************ * Unauthorised access or use of this equipment * * is prohibited and constitutes an offence * * under the Computer Misuse Act 1990. * * If you are not authorised to use this * * system, terminate this session now. * ************************************************
switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel:
switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:In disable_paging DEBUG:netmiko:Command: terminal length 0
DEBUG:netmiko:write_channel: b’terminal length 0\n’ DEBUG:netmiko:Pattern is: terminal\ length\ 0 DEBUG:netmiko:_read_channel_expect read_data: t DEBUG:netmiko:_read_channel_expect read_data: erminal length 0
switch-01# DEBUG:netmiko:Pattern found: terminal\ length\ 0 terminal length 0
switch-01# DEBUG:netmiko:terminal length 0
switch-01# DEBUG:netmiko:Exiting disable_paging DEBUG:netmiko:write_channel: b’terminal width 511\n’ DEBUG:netmiko:Pattern is: terminal\ width\ 511 DEBUG:netmiko:_read_channel_expect read_data: t DEBUG:netmiko:_read_channel_expect read_data: erminal width 511
switch-01# DEBUG:netmiko:Pattern found: terminal\ width\ 511 terminal width 511
switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel:
switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel:
switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is switch-01# DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’routing-context vrf vnName\n’ DEBUG:netmiko:Pattern is: routing-context\ vrf\ vnName DEBUG:netmiko:_read_channel_expect read_data: r DEBUG:netmiko:_read_channel_expect read_data: outing-context vrf vnName
switch-01%vnTrust# DEBUG:netmiko:Pattern found: routing-context\ vrf\ vnName routing-context vrf vnName
switch-01%vnTrust# DEBUG:netmiko:read_channel:
[repeated a lot]
DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:Pattern is: # DEBUG:netmiko:_read_channel_expect read_data:
switch-01%vnName# DEBUG:netmiko:Pattern found: #
switch-01%vnName# DEBUG:netmiko:exit_config_mode: DEBUG:netmiko:write_channel: b’exit\n’ DEBUG:paramiko.transport:EOF in transport thread
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
@ktbyers works like a charm! thank you.
@leearmitage I would try to execute the following:
So here I use the
expect_string
argument so it doesn’t care about the prompt changing (this should allow both commands to be executed).I then reset the base_prompt after the for-loop is done. In general, you probably need to execute that
set_base_prompt()
anytime the prompt fundamentally changes like that.Let me know if that works (or not).