尝试使用 send_config_set 时无法在 Netmiko 中进入配置模式
Failed to enter configuration mode in Netmiko while trying to use send_config_set
我是 Python 和 Netmiko 的新手。我正在尝试使用 netmiko 登录到 aruba 交换机。当我使用 send_config_set 传递一些命令时,它错误地显示“无法进入配置模式”,我在这里遗漏了什么吗?
one solution was suggested to set "fast_cli to False" and global delay factor to 4 and even that did not work.
有人可以帮我解决这个问题吗?
from netmiko import ConnectHandler
network_device = {"host": "x.x.x.x",
"username": "admin",
"password": "password$",
"device_type": "aruba_os"}
with ConnectHandler(**network_device) as ssh_connect:
print(ssh_connect.find_prompt())
for vlan in range(1001,2000):
config_commands = ['Vlan ' + str(vlan), 'name: Private_Vlan ' + str(vlan)]
output = ssh_connect.send_config_set(config_commands)
print(output)
```Traceback (most recent call last):
File "/Users/vijayswaminathan/PycharmProjects/Taormina/switch_login.py", line 33, in <module>
output = ssh_connect.send_config_set(config_commands)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1876, in send_config_set
output += self.config_mode(*cfg_mode_args)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/aruba/aruba_ssh.py", line 52, in config_mode
return super().config_mode(config_command=config_command, pattern=pattern)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/cisco_base_connection.py", line 48, in config_mode
return super().config_mode(
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1766, in config_mode
raise ValueError("Failed to enter configuration mode.")
ValueError: Failed to enter configuration mode.
Process finished with exit code 1
我尝试 运行 netmiko 调试,看起来 netmiko 正在正确发出命令。 Netmiko 日志是:
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
DEBUG:netmiko:Pattern found: P2\-09 P2-09#
DEBUG:netmiko:write_channel: b'configure term\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data:
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
DEBUG:netmiko:Pattern found: P2\-09
P2-09#
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data:
P2-09#
DEBUG:netmiko:Pattern found: P2\-09
P2-09#
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data: configure term
P2-09(config)#
DEBUG:netmiko:Pattern found: P2\-09 configure term
P2-09(config)#
DEBUG:netmiko:write_channel: b'exit\r'
您可以使用我在下面编写的示例代码。更新一下提示部分就够了
try:
network_device = {
'device_type': 'aruba_os', 'ip': x.x.x.x, 'username':
username, 'password': password, }
net_connect = Netmiko(**network_device)
print("success enter")
except Exception as e:
print(e)
return
prompt_aruba_fnk = net_connect.find_prompt()
hostname_fnk = prompt_aruba_fnk.strip("<" + ">")
print(hostname_fnk)
net_connect.send_command_timing("enable")
net_connect.send_command_timing("undo smart")
output = net_connect.send_command_timing("config")
print("entered config mode")
net_connect.send_command_timing("acl 2010 ")
net_connect.send_command_timing("save")
print("islem tamamlandi")
with open("MDU_OK_2.txt", "a") as f:
f.write(nodeip + "\n")
f.close()
net_connect.disconnect()
我是 Python 和 Netmiko 的新手。我正在尝试使用 netmiko 登录到 aruba 交换机。当我使用 send_config_set 传递一些命令时,它错误地显示“无法进入配置模式”,我在这里遗漏了什么吗?
one solution was suggested to set "fast_cli to False" and global delay factor to 4 and even that did not work.
有人可以帮我解决这个问题吗?
from netmiko import ConnectHandler
network_device = {"host": "x.x.x.x",
"username": "admin",
"password": "password$",
"device_type": "aruba_os"}
with ConnectHandler(**network_device) as ssh_connect:
print(ssh_connect.find_prompt())
for vlan in range(1001,2000):
config_commands = ['Vlan ' + str(vlan), 'name: Private_Vlan ' + str(vlan)]
output = ssh_connect.send_config_set(config_commands)
print(output)
```Traceback (most recent call last):
File "/Users/vijayswaminathan/PycharmProjects/Taormina/switch_login.py", line 33, in <module>
output = ssh_connect.send_config_set(config_commands)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1876, in send_config_set
output += self.config_mode(*cfg_mode_args)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/aruba/aruba_ssh.py", line 52, in config_mode
return super().config_mode(config_command=config_command, pattern=pattern)
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/cisco_base_connection.py", line 48, in config_mode
return super().config_mode(
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1766, in config_mode
raise ValueError("Failed to enter configuration mode.")
ValueError: Failed to enter configuration mode.
Process finished with exit code 1
我尝试 运行 netmiko 调试,看起来 netmiko 正在正确发出命令。 Netmiko 日志是:
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
DEBUG:netmiko:Pattern found: P2\-09 P2-09#
DEBUG:netmiko:write_channel: b'configure term\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data:
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
DEBUG:netmiko:Pattern found: P2\-09
P2-09#
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data:
P2-09#
DEBUG:netmiko:Pattern found: P2\-09
P2-09#
DEBUG:netmiko:write_channel: b'\r'
DEBUG:netmiko:Pattern is: P2\-09
DEBUG:netmiko:_read_channel_expect read_data: configure term
P2-09(config)#
DEBUG:netmiko:Pattern found: P2\-09 configure term
P2-09(config)#
DEBUG:netmiko:write_channel: b'exit\r'
您可以使用我在下面编写的示例代码。更新一下提示部分就够了
try:
network_device = {
'device_type': 'aruba_os', 'ip': x.x.x.x, 'username':
username, 'password': password, }
net_connect = Netmiko(**network_device)
print("success enter")
except Exception as e:
print(e)
return
prompt_aruba_fnk = net_connect.find_prompt()
hostname_fnk = prompt_aruba_fnk.strip("<" + ">")
print(hostname_fnk)
net_connect.send_command_timing("enable")
net_connect.send_command_timing("undo smart")
output = net_connect.send_command_timing("config")
print("entered config mode")
net_connect.send_command_timing("acl 2010 ")
net_connect.send_command_timing("save")
print("islem tamamlandi")
with open("MDU_OK_2.txt", "a") as f:
f.write(nodeip + "\n")
f.close()
net_connect.disconnect()