Netmiko 基础提示更改

问题描述 投票:0回答:1

我正在尝试创建一个管理 Avocent ACS800/8000 和 Avocent ACS600/6000 控制台服务器的自动化系统。我选择 Netmiko 作为 SSH 库。现在我的问题是,Netmiko 并不专门支持这些设备,但它一般支持 Linux。这些服务器上有一个嵌入式Linux系统。 我的主要问题是,这些设备上的基本提示如下所示:

--:- / cli->
。 Netmiko 期望“#”或“$”作为提示的最后一个字符。

from netmiko import ConnectHandler
from cfslibconfig import CfsLibConfig

def get_session(config):
    device= {
        "host": config.get_config_key('console_host'),
        "username": config.get_config_key('console_username'),
        "password": config.get_config_key('console_password'),
        "device_type": "linux",
        "session_log": "netmiko_session.log",
        "auto_connect": False
    }
    session = ConnectHandler(**device)
    session.establish_connection()
    session.set_base_prompt(alt_prompt_terminator=">")

我试图这样做,但总是在最后一行得到这个异常:

**Exception has occurred: ReadTimeout


Pattern not detected: '[\\$\\#]' in output.

Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.

  File "/local/repo/console-port/scripts/common.py", line 19, in get_session
    session.set_base_prompt(alt_prompt_terminator=">")
  File "/local/repo/console-port/scripts/new_group.py", line 6, in <module>
    session = get_session(config)
              ^^^^^^^^^^^^^^^^^^^
netmiko.exceptions.ReadTimeout: 

Pattern not detected: '[\\$\\#]' in output.

Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.**


Isn't the entire purpose of the set_base_prompt function to change that pattern??
python ssh console paramiko netmiko
1个回答
0
投票

尝试稍微不同的方法。您可以尝试使用

set_base_prompt
方法来动态检测提示,而不是使用
find_prompt
显式设置基本提示。 示例:

from netmiko import ConnectHandler

def get_session():
    device = {
        "device_type": "linux",
        "ip": "your_console_host",
        "username": "your_username",
        "password": "your_password",
        "session_log": "netmiko_session.log",
        "auto_connect": False
    }
    
    session = ConnectHandler(**device)
    session.establish_connection()

    # Dynamically detect the prompt
    prompt = session.find_prompt()
    print(f"Detected prompt: {prompt}")

    return session

session = get_session()
© www.soinside.com 2019 - 2024. All rights reserved.