I’m new to Python and Netmiko. I;m trying to use netmiko to login to aruba switches. while i pass on some commands using send_config_set, it is erroring out saying “failed to enter configuration mode” am i missing anything here.
JavaScript
x
2
1
one solution was suggested to set "fast_cli to False" and global delay factor to 4 and even that did not work.
2
can someone help me with this pls?
JavaScript
1
30
30
1
from netmiko import ConnectHandler
2
network_device = {"host": "x.x.x.x",
3
"username": "admin",
4
"password": "password$",
5
"device_type": "aruba_os"}
6
7
with ConnectHandler(**network_device) as ssh_connect:
8
print(ssh_connect.find_prompt())
9
10
for vlan in range(1001,2000):
11
config_commands = ['Vlan ' + str(vlan), 'name: Private_Vlan ' + str(vlan)]
12
output = ssh_connect.send_config_set(config_commands)
13
print(output)
14
15
16
```Traceback (most recent call last):
17
File "/Users/vijayswaminathan/PycharmProjects/Taormina/switch_login.py", line 33, in <module>
18
output = ssh_connect.send_config_set(config_commands)
19
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1876, in send_config_set
20
output += self.config_mode(*cfg_mode_args)
21
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/aruba/aruba_ssh.py", line 52, in config_mode
22
return super().config_mode(config_command=config_command, pattern=pattern)
23
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/cisco_base_connection.py", line 48, in config_mode
24
return super().config_mode(
25
File "/Users/vijayswaminathan/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1766, in config_mode
26
raise ValueError("Failed to enter configuration mode.")
27
ValueError: Failed to enter configuration mode.
28
29
Process finished with exit code 1
30
I tried to run netmiko debug and looks like netmiko is issuing the commands correctly. Netmiko logs are:
JavaScript
1
25
25
1
DEBUG:netmiko:write_channel: b'r'
2
DEBUG:netmiko:Pattern is: P2-09
3
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
4
DEBUG:netmiko:Pattern found: P2-09 P2-09#
5
DEBUG:netmiko:write_channel: b'configure termr'
6
DEBUG:netmiko:Pattern is: P2-09
7
DEBUG:netmiko:_read_channel_expect read_data:
8
9
DEBUG:netmiko:_read_channel_expect read_data: P2-09#
10
DEBUG:netmiko:Pattern found: P2-09
11
P2-09#
12
DEBUG:netmiko:write_channel: b'r'
13
DEBUG:netmiko:Pattern is: P2-09
14
DEBUG:netmiko:_read_channel_expect read_data:
15
P2-09#
16
DEBUG:netmiko:Pattern found: P2-09
17
P2-09#
18
DEBUG:netmiko:write_channel: b'r'
19
DEBUG:netmiko:Pattern is: P2-09
20
DEBUG:netmiko:_read_channel_expect read_data: configure term
21
P2-09(config)#
22
DEBUG:netmiko:Pattern found: P2-09 configure term
23
P2-09(config)#
24
DEBUG:netmiko:write_channel: b'exitr'
25
Advertisement
Answer
You can use the sample code I wrote below. It will be enough to update the prompt section.
JavaScript
1
27
27
1
try:
2
network_device = {
3
'device_type': 'aruba_os', 'ip': x.x.x.x, 'username':
4
username, 'password': password, }
5
net_connect = Netmiko(**network_device)
6
print("success enter")
7
except Exception as e:
8
print(e)
9
return
10
11
prompt_aruba_fnk = net_connect.find_prompt()
12
hostname_fnk = prompt_aruba_fnk.strip("<" + ">")
13
print(hostname_fnk)
14
net_connect.send_command_timing("enable")
15
net_connect.send_command_timing("undo smart")
16
output = net_connect.send_command_timing("config")
17
print("entered config mode")
18
net_connect.send_command_timing("acl 2010 ")
19
net_connect.send_command_timing("save")
20
21
print("islem tamamlandi")
22
with open("MDU_OK_2.txt", "a") as f:
23
f.write(nodeip + "n")
24
f.close()
25
26
net_connect.disconnect()
27