File tree Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 9191| regex_split | netutils.regex.regex_split |
9292| regex_sub | netutils.regex.regex_sub |
9393| longest_prefix_match | netutils.route.longest_prefix_match |
94+ | get_running_config_command | netutils.running_config.get_running_config_command |
9495| uptime_seconds_to_string | netutils.time.uptime_seconds_to_string |
9596| uptime_string_to_seconds | netutils.time.uptime_string_to_seconds |
9697| vlanconfig_to_list | netutils.vlan.vlanconfig_to_list |
Original file line number Diff line number Diff line change 300300 "vyos" : "vyos" ,
301301}
302302
303+ # Running config command
304+ RUNNING_CONFIG_MAPPER : t .Dict [str , str ] = {
305+ "cisco_ios" : "show run" ,
306+ "cisco_nxos" : "show run" ,
307+ "cisco_xr" : "show run" ,
308+ "juniper_junos" : "show configuration | display set" ,
309+ "arista_eos" : "show run" ,
310+ "checkpoint_gaia" : 'clish -c "show configuration"' ,
311+ }
312+
303313# PYTNC | Normalized
304314PYNTC_LIB_MAPPER : t .Dict [str , str ] = {
305315 "arista_eos_eapi" : "arista_eos" ,
Original file line number Diff line number Diff line change 1+ """Configuration command lookup."""
2+
3+ from netutils .lib_mapper import RUNNING_CONFIG_MAPPER
4+
5+
6+ def get_running_config_command (platform : str ) -> str :
7+ """
8+ Get the running config command for a specific network platform.
9+
10+ Args:
11+ platform: Platform name, like 'cisco_ios' or 'juniper_junos'.
12+
13+ Returns:
14+ The corresponding command as a string, or 'show run' by default.
15+ """
16+ return RUNNING_CONFIG_MAPPER .get (platform .lower (), "show run" )
Original file line number Diff line number Diff line change 9999 "version_metadata" : "os_version.version_metadata" ,
100100 "get_nist_urls" : "nist.get_nist_urls" ,
101101 "get_nist_vendor_platform_urls" : "nist.get_nist_vendor_platform_urls" ,
102+ "get_running_config_command" : "running_config.get_running_config_command" ,
102103}
103104
104105
Original file line number Diff line number Diff line change 1+ """Tests for the running configuration command mapping."""
2+
3+ import pytest
4+ from netutils import lib_mapper
5+ from netutils .running_config import get_running_config_command
6+
7+
8+ def test_running_config_mapper_keys_are_known ():
9+ """Ensure all keys in RUNNING_CONFIG_MAPPER are in MAIN_LIB_MAPPER values."""
10+ unknown_keys = [key for key in lib_mapper .RUNNING_CONFIG_MAPPER if key not in lib_mapper .MAIN_LIB_MAPPER .values ()]
11+ assert not unknown_keys , f"Unexpected keys in RUNNING_CONFIG_MAPPER: { unknown_keys } "
12+
13+
14+ @pytest .mark .parametrize ("platform,expected_command" , list (lib_mapper .RUNNING_CONFIG_MAPPER .items ()))
15+ def test_get_running_config_command_known_platforms (platform , expected_command ):
16+ """Test get_running_config_command returns correct command for known platforms."""
17+ assert get_running_config_command (platform ) == expected_command
18+ assert get_running_config_command (platform .upper ()) == expected_command # test case insensitivity
19+
20+
21+ def test_get_running_config_command_unknown_platform ():
22+ """Test get_running_config_command returns default 'show run' for unknown platforms."""
23+ assert get_running_config_command ("unknown_platform" ) == "show run"
24+ assert get_running_config_command ("checkpoint_gaiAA" ) == "show run"
You can’t perform that action at this time.
0 commit comments