Search code examples
pythonnetmiko

Failed to enter configuration mode in Netmiko while trying to use send_config_set


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.

one solution was suggested to set "fast_cli to False" and global delay factor to 4 and even that did not work.

can someone help me with this pls?

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

I tried to run netmiko debug and looks like netmiko is issuing the commands correctly. Netmiko logs are:


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'

Solution

  • You can use the sample code I wrote below. It will be enough to update the prompt section.

    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()