Closed ferberat closed 2 years ago
Netmiko should automatically do this here (to a certain extent):
https://github.com/ktbyers/netmiko/blob/develop/netmiko/cisco/cisco_ios.py#L41
It looks like that Cisco IOS/IOS-XE prompt
command is incompatible with Netmiko:
cisco3-STP-1234#conf t
Enter configuration commands, one per line. End with CNTL/Z.
cisco3(config)#do show run | inc prompt
prompt %h-STP-1234%p
Basically config mode reverts to having the prompt just be "hostname(config)" whereas outside of config mode it is what prompt
is defined as.
So abbreviating it by, search_pattern[0:14]
or by base_prompt[:16]
won't fix it.
So you would probably need to either:
prompt command
config_mode(), send_command(), exit_config_mode()
to send configurations or write your own custom function to do this.Hi Kirk,
thanks, this works with netmiko:
show_hostname=net_connect.send_command('sh run | in hostname ')
search_pattern=show_hostname.split()[1]
net_connect.config_mode(pattern=search_pattern)
for line in config:
net_connect.send_command(line, expect_string=search_pattern)
net_connect.exit_config_mode()
I need the serach_pattern option in config_mode command
I tried also napalm, I think napalm use netmiko. with napalm i have the same problem. If i use a hostname > len 16 i got an error. But currently I didn' t use napalm and the workaround is ok.
I think it is better to remove the prompt command on router :-)
Thanks, BR Franz
...
- Not use send_config_set and instead use
config_mode(), send_command(), exit_config_mode()
to send configurations or write your own custom function to do this.
This worked perfect for say interface range commands on IOSXE..
If we define the prompt with hostname and prompt command on IOS, we run in a problem with the search pattern. This occurs with send_config_set.
Config: hostname Loc-S123987345 prompt %h-STP-1234%p
The "Pattern not detected: 'Loc\-S123987345\-S.*' in output." doesn 't match the message in ssh channel: Loc-S123987345(config)#
I found a workaround: search_pattern=net_connect.find_prompt() net_connect.config_mode(pattern=search_pattern[0:14]) net_connect.send_config_set(config)
BR Franz
########################### Logfile:
DEBUG:netmiko:read_channel: Loc-S123987345-STP-1234# Loc-S123987345-STP-1234# DEBUG:netmiko:Pattern found: (#|>) Loc-S123987345-STP-1234# DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is Loc-S123987345-STP-1234# DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: Loc-S123987345-STP-1234# DEBUG:netmiko:Pattern found: ([>#]) Loc-S123987345-STP-1234# DEBUG:netmiko:write_channel: b'configure terminal\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: configure terminal
DEBUG:netmiko:Pattern found: (configure\ terminal) configure terminal DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: Enter configuration commands, one per line. End with CNTL/Z. Loc-S123987345(config)# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel
################################# Routerlogs:
Pattern not detected: 'Loc\-S123987345\-S.*' in output.
Things you might try to fix this:
You can also look at the Netmiko session_log or debug log for more information.