interface gigabitethernet 0/2
switchport access vlan 2
shutdown
no shutdown
This code is based on the class CiscoBaseConnection because the prompt output from the device resembles Cisco IOS.
However, when modifying the configuration, an "!" is outputted at the beginning of the prompt.
Therefore, the acquisition of base_prompt is adjusted.
example_device_output.log
switch(config)# interface gigabitethernet 0/2
switch(config-if)# shutdown
!switch(config-if)# no shutdown
!switch(config-if)#
I will send the test results.
test_result.log
(netmiko-py3.10) vd-0@test-vm:~/dev-1/netmiko/tests/test_alaxala_ax36s$ ./test_alaxala_.sh
Starting tests...good luck:
AlaxalA AX Seriex
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.3.0 -- /home/vd-0/dev-1/netmiko/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/vd-0/dev-1/netmiko, configfile: setup.cfg
plugins: pylama-8.3.8
collected 25 items
test_netmiko_show.py::test_failed_key SKIPPED (Not using SSH-keys)
test_netmiko_show.py::test_disable_paging PASSED
test_netmiko_show.py::test_terminal_width PASSED
test_netmiko_show.py::test_ssh_connect PASSED
test_netmiko_show.py::test_ssh_connect_cm PASSED
test_netmiko_show.py::test_send_command_timing PASSED
test_netmiko_show.py::test_send_command_timing_no_cmd_verify SKIPPED
test_netmiko_show.py::test_send_command PASSED
test_netmiko_show.py::test_send_command_no_cmd_verify SKIPPED
test_netmiko_show.py::test_complete_on_space_disabled SKIPPED
test_netmiko_show.py::test_send_command_textfsm SKIPPED (TextFSM/ntc...)
test_netmiko_show.py::test_send_command_ttp SKIPPED (TTP template no...)
test_netmiko_show.py::test_send_command_genie SKIPPED (Genie not sup...)
test_netmiko_show.py::test_send_multiline_timing SKIPPED
test_netmiko_show.py::test_send_multiline SKIPPED
test_netmiko_show.py::test_send_multiline_prompt SKIPPED
test_netmiko_show.py::test_send_multiline_simple SKIPPED
test_netmiko_show.py::test_base_prompt PASSED
test_netmiko_show.py::test_strip_prompt PASSED
test_netmiko_show.py::test_strip_command PASSED
test_netmiko_show.py::test_normalize_linefeeds PASSED
test_netmiko_show.py::test_clear_buffer PASSED
test_netmiko_show.py::test_enable_mode PASSED
test_netmiko_show.py::test_disconnect PASSED
test_netmiko_show.py::test_disconnect_no_enable SKIPPED
=========================== short test summary info ============================
SKIPPED [1] test_netmiko_show.py:25: Not using SSH-keys
SKIPPED [1] test_netmiko_show.py:88: Skipped
SKIPPED [1] test_netmiko_show.py:106: Skipped
SKIPPED [1] test_netmiko_show.py:128: Skipped
SKIPPED [1] test_netmiko_show.py:149: TextFSM/ntc-templates not supported on this platform
SKIPPED [1] test_netmiko_show.py:171: TTP template not existing for this platform
SKIPPED [1] test_netmiko_show.py:211: Genie not supported on this platform
SKIPPED [1] test_netmiko_show.py:231: Skipped
SKIPPED [1] test_netmiko_show.py:247: Skipped
SKIPPED [1] test_netmiko_show.py:272: Skipped
SKIPPED [1] test_netmiko_show.py:296: Skipped
SKIPPED [1] test_netmiko_show.py:401: Skipped
======================= 13 passed, 12 skipped in 27.71s ========================
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.3.0 -- /home/vd-0/dev-1/netmiko/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/vd-0/dev-1/netmiko, configfile: setup.cfg
plugins: pylama-8.3.8
collected 13 items
test_netmiko_config.py::test_ssh_connect PASSED
test_netmiko_config.py::test_enable_mode PASSED
test_netmiko_config.py::test_config_mode PASSED
test_netmiko_config.py::test_exit_config_mode PASSED
test_netmiko_config.py::test_config_set PASSED
test_netmiko_config.py::test_config_set_generator PASSED
test_netmiko_config.py::test_config_set_longcommand PASSED
test_netmiko_config.py::test_config_hostname PASSED
test_netmiko_config.py::test_config_from_file PASSED
test_netmiko_config.py::test_config_error_pattern SKIPPED (No error_...)
test_netmiko_config.py::test_banner SKIPPED (No banner defined.)
test_netmiko_config.py::test_global_cmd_verify SKIPPED (No banner de...)
test_netmiko_config.py::test_disconnect PASSED
=========================== short test summary info ============================
SKIPPED [1] test_netmiko_config.py:175: No error_pattern defined.
SKIPPED [1] test_netmiko_config.py:209: No banner defined.
SKIPPED [1] test_netmiko_config.py:242: No banner defined.
=================== 10 passed, 3 skipped in 77.68s (0:01:17) ===================
(netmiko-py3.10) vd-0@test-vm:~/dev-1/netmiko/tests/test_alaxala_ax36s$
I also conducted tests for autodetection.
sample code
test-code-autodetect.py
from netmiko.ssh_autodetect import SSHDetect
from netmiko.ssh_dispatcher import ConnectHandler
import logging
I further added support for the AlaxalA AX switch series. https://www.alaxala.com/en/
Only AX3600S series and AX2600S series box switches are supported by this code. Some command structures are different for chassis-type switches.
Test configuration:
test_devices.yml
commands.yml
responses.yml
alaxala_ax36s_commands.txt
This code is based on the class CiscoBaseConnection because the prompt output from the device resembles Cisco IOS.
However, when modifying the configuration, an "!" is outputted at the beginning of the prompt. Therefore, the acquisition of base_prompt is adjusted.
example_device_output.log
I will send the test results. test_result.log
I also conducted tests for autodetection.
logging.basicConfig(filename="netmiko_test-code.log", level=logging.DEBUG) logger = logging.getLogger("netmiko")
remote_device = { "ip": "192.168.1.30", "username": "test", "password": "test", "secret": "test", "device_type": "autodetect", "global_delay_factor": 3, "session_log": "test-code.log", "fast_cli": False, }
guesser = SSHDetect(**remote_device) best_match = guesser.autodetect() print(best_match) print(guesser.potential_matches)
remote_device["device_type"] = best_match connection = ConnectHandler(**remote_device)
enable = connection.enable()
result = connection.send_command(command_string="show version") print(result)
config = connection.config_mode() print(config)
configure = connection.send_config_from_file( "./tests/test_alaxala_ax36s/alaxala_ax36s_commands.txt") indent = connection.send_command('\n') print(configure)
save = connection.save_config() print(save)
showrun = connection.send_command('show running-config') print(showrun)
connection.disconnect()
I look forward to having these codes reviewed. Thank you!