ktbyers / netmiko

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

Alcatel OmniSwitches default prompt problem and solution suggestion. #921

Closed pstolpe closed 3 years ago

pstolpe commented 6 years ago

When connecting to a Alcatel AOS 6 switch (6450-48) I get the error "ValueError: Router prompt not found: 'LAB-1'". Of course we could change the prompts on all our switches but everyone is ending differently and ALE does not yet have a system default suffix on their prompts. We also set the prompt to the name of the system and the name is taken from DHCP option 12 right now and changing the DHCP requires a reboot of the switch.

But there is an option and that is to change the code to set the prompt to a well defined string during setup of the session. This is done differently on the AOS 6 vs AOS 8. I have made some changes to the alcatel_aos_ssh.py connection module to test for AOS 6:

class AlcatelAosSSH(CiscoSSHConnection):
    """Alcatel-Lucent Enterprise AOS6 support."""
    def session_preparation(self):
        # Prompt can be anything, but best practice is to end with > or #
        self._test_channel_read(pattern=r'')
        # Set the prompt for the session to ">#"
        self.send_command('prompt string >#\n', expect_string='>#')
        self._test_channel_read(pattern=r'>#')
        self.set_base_prompt()
        # Clear the read buffer
        time.sleep(.3 * self.global_delay_factor)
        self.clear_buffer()

For AOS 8 that runs busybox we instead need to set the bash prompt accordingly.

export PS1='># '

This makes us have a well defined prompt to look after in the further processing. I do ask for feedback on problems I haven't thought about before submitting any pull requests.

ktbyers commented 6 years ago

@pstolpe Can you post the exception you are getting during the failure?

So your current prompt is LAB-1 with no terminating character?

I wouldn't want Netmiko to set the prompt, so we could possibly do something like:

    def session_preparation(self):
        # Prompt can be anything, but best practice is to end with > or #
        self._test_channel_read(pattern=r'.')       # read any single character
        self.set_base_prompt()
        # Clear the read buffer
        time.sleep(.3 * self.global_delay_factor)
        self.clear_buffer()

We also would probably have to write a custom set_base_prompt() method as the current method is going to look for a prompt terminating character (defaults to '#' or '>').

pstolpe commented 6 years ago

Hi, the prompts are the system name without terminating characters.

  File "c:/Users/.../skript/NetworkAutomation/netmiko-test.py", 
        line 15, in <module> net_connect = ConnectHandler(**a_device)
  File "C:\Users\...\Python\Python36\site-packages\netmiko\ssh_dispatcher.py", 
        line 190, in ConnectHandler return ConnectionClass(*args, **kwargs) 
  File "C:\Users\...\Python\Python36\site-packages\netmiko\base_connection.py", 
        line 246, in __init__ self.session_preparation()
  File "C:\Users\...\Python\Python36\site-packages\netmiko\alcatel\alcatel_aos_ssh.py",
        line 13, in session_preparation self.set_base_prompt()
  File "C:\Users\...\Python\Python36\site-packages\netmiko\base_connection.py", 
        line 915, in set_base_prompt 
        raise ValueError("Router prompt not found: {0}".format(repr(prompt)))
        ValueError: Router prompt not found: 'OOBM-LAB-1'

Alcatel permits any kind of prompt and my proposed solution setting the prompt is only doing that for the current session. Even with bash AOS8 it is the current session prompt that is modified. Any new connections are getting the system default prompt. To change the prompt for all the sessions you need to use other commands.

AOS 8 also supports VRF and prefixes the prompt with the VRF name as: vrfname::Prompt

pstolpe commented 5 years ago

Getting back to this issue after some months. :-)

So if I have understood you correctly your suggestion is to write a set_base_prompt() function that may set the session prompt accordingly and then later match on that prompt?

That might me a good way of just setting prompts on systems that needs it. The new base prompt should maybe be a parameter to the function?

ktbyers commented 5 years ago

@pstolpe Can you show me an example of what the prompt / CLI session looks like on AOS6 and AOS8?

I see a lot of references to something like this online:

device-name ->
pstolpe commented 5 years ago

Hi the prompts are as follows from the CLI

##################################################### Default prompt on AOS 6 ##################################################### login : admin password :

Welcome to the Alcatel-Lucent Enterprise OmniSwitch 6450 Software Version 6.7.2.107.R03 GA, December 05, 2017.

Copyright(c), ALE USA Inc., 2017. All Rights reserved.

OmniSwitch(TM) is a trademark of Alcatel-Lucent Enterprise registered in the United States Patent and Trademark Office.

->

##################################################### Prompt set to system name (with default system name vxTarget) A logout and login again is needed for the prompt to change. Then I set the prompt for the session to something (not more than 4 chars apparently) ##################################################### -> session prompt default system-name -> exit Changes in the running configuration have been made but not saved! Confirm exit (Y/N)? login : admin password :

Welcome to the Alcatel-Lucent Enterprise OmniSwitch 6450 Software Version 6.7.2.107.R03 GA, December 05, 2017.

Copyright(c), ALE USA Inc., 2017. All Rights reserved.

OmniSwitch(TM) is a trademark of Alcatel-Lucent Enterprise registered in the United States Patent and Trademark Office.

vxTarget vxTarget prompt string -> ->

##################################################### Default Prompt AOS8 on an 6860 (It's the same for other AOS8 devices) ##################################################### OS6860 login: admin Password:

Fri Oct 26 21:53:42 : AAA Switch-Warning WARN message: +++ WARNING! Switch Access Vulnerability. Welcome to the Alcatel-Lucent Enterprise OS6860E-U28 8.5.255.R02 GA, August 29, 2018.

Copyright (c) 1994-2014 Alcatel-Lucent. All Rights Reserved. Copyright (c) 2014-2018 Alcatel-Lucent Enterprise. All Rights Reserved.

OmniSwitch(tm) is a trademark of Alcatel-Lucent, registered in the United States Patent and Trademark Office.

+++ WARNING! Admin user authentication using default password. ->

##################################################### AOS 8 Prompt when set to prefered prompt for the session. A logout and login is needed to get the new prompt. The I set the prompt for the session by modifying the bash prompt PS1 ##################################################### -> session prompt default "the prompt we set" -> exit Changes in the running configuration have been made but not saved! Confirm exit (Y/N)? ylog OS6860 login: admin Password: the stupid prompt the stupid prompt PS1="#> "

>

#####################################################

One can argue a long time about the prompts but as long we are able to log in to the system and execute commands we may set it hard but as it's okay to set the prompts "stupidly" you end up with a mess to try to regexp-match. I thought it would be nice just set it at first for the session and match on the well known prompt.

pstolpe commented 5 years ago

Any comments on my comment?

pstolpe commented 5 years ago

So I come back to this after some months to see if we can move forward, I know ALE is not the biggest player on the market... :-)

ktbyers commented 5 years ago

Yes, the code (as it is currently is) will break if the prompt doesn't end in a > or a #.

Is this a common pattern with the Alcatel to not have any prompt terminating character? In other words, do people do this in practice very often on Alcatel?

For example this:

vxTarget

or this:

the stupid prompt
pstolpe commented 5 years ago

I don't actually know the practise, for now we have the hostnames set via dhcp options so I guess changing all of them would make life easier but the default prompt without any config on the box (where one probably would like to start automation) is vxTarget. Maybe one could walk around the problem in some nice way?

ktbyers commented 3 years ago

Closing as no one is actively working on this. If someone is still working on this, just re-open.