ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.56k stars 1.3k forks source link

set_base_prompt for ubiquiti_edge #499

Closed jftuga closed 7 years ago

jftuga commented 7 years ago

I am using device_type=ubiquiti_edge but my edge router has a different default prompt. I just installed the latest firmware on my EgdeRouter Lite 3 (v1.9.1.1).

obj = {'username': 'ubnt', 'ip': '192.16.1.1', 'verbose': True, 'port': 22, 'password': b'whatever', 'device_type': 'ubiquiti_edge'}

When I ssh in, my shell prompt look like this:

ubnt@ubnt:~$

I can then type 'configure' which will change the prompt:

ubnt@ubnt:~$ configure
[edit]
ubnt@ubnt# run terminal length 9999
[edit]
ubnt@ubnt#

I am initiating a connection like this:

net_connect = ConnectHandler(**obj)

I get this error:

ValueError: Router prompt not found: ubnt@ubnt:~$

How can I call something like the code below before the ConnectHandler actually makes the SSH connection so that the prompt is set correctly beforehand?

net_connect.base_prompt = "$"
# or:
net_connect.set_base_prompt("$")

Ideally, the full set of commands I want to run are:

configure
run terminal length 9999
run show configuration all
exit

Notice that after the 'configure' command, the prompt changes and then it will change back after the 'exit' command is issued. The 'exit' command does not log off, it just exits the configure mode.

ktbyers commented 7 years ago

Okay, looking into this...

lykinsbd commented 7 years ago

After looking at this in conversation with @ktbyers on Slack, I can confirm that EdgeOS is behaviorally similar to VyOS, and we'd need to have similar behavior as listed in the VyOS class where we don't attempt to Enable, etc. The # prompt only appears in Configure mode (configure) and when sudo'ed to root (sudo su).

The existing Ubiquiti child class doesn't override the default actions around entering Enable mode as shown in the parent Cisco Base Connection class.

One potential solution would just be to have the EdgeOS class inherit from VyOS instead of the Cisco Base Class. The behaviors of EdgeOS and VyOS are functionally very similar as they both came from the same root software, Vyatta.

jftuga commented 7 years ago

I can confirm the prompt issue is now fixed. Thank you.

The next issue is that my script will hang after this:

cmd = "configure"
net_connect.send_command(cmd)

I believe this is because the prompt changes from '$' to '#' and netmiko is waiting for a '$' but will never get it. How can I fix this?

  File "C:\Python35\lib\site-packages\netmiko\base_connection.py", line 815, in send_command
search_pattern))
OSError: Search pattern never detected in send_command_expect: ubnt\@ubnt\:\~\$
lykinsbd commented 7 years ago

@jftuga You don't want to send configure as a command, you need to use the other method on net_connect, net_connect.send_config_set(), to get into configuration mode, Example:

config_list = ['set interface ethernet eth1 blah']
net_connect.send_config_set(config_list)

If you just want to view config that's when you'd use net_connect.send_command():

command_list = ['terminal length 9999','show configuration all']
for command in command_list:
    net_connect.send_command(command)

If you use send_config_set it has handling for $ vs # built in.

jftuga commented 7 years ago

Using send_config_set work for me. I am now able to output the config.

Thank you!

sconrod-tester commented 1 year ago

How can I drop into vshell with netmiko on viptela?