diff --git a/netmiko/lancom/__init__.py b/netmiko/lancom/__init__.py index 363453a01..96c2df6e0 100644 --- a/netmiko/lancom/__init__.py +++ b/netmiko/lancom/__init__.py @@ -1,3 +1,4 @@ from netmiko.lancom.lancom_lcossx4 import LancomLCOSSX4SSH +from netmiko.lancom.lancom_lcossx5 import LancomLCOSSX5SSH -__all__ = ["LancomLCOSSX4SSH"] +__all__ = ["LancomLCOSSX4SSH", "LancomLCOSSX5SSH"] diff --git a/netmiko/lancom/lancom_lcossx5.py b/netmiko/lancom/lancom_lcossx5.py new file mode 100644 index 000000000..13d3c7cbe --- /dev/null +++ b/netmiko/lancom/lancom_lcossx5.py @@ -0,0 +1,87 @@ +from netmiko.cisco_base_connection import CiscoSSHConnection + + +class LancomLCOSSX5SSH(CiscoSSHConnection): + def session_preparation(self) -> None: + """ + Prepare the session after the connection has been established. + + The connection will enter `Privileged EXEC` by default, as the `EXEC` mode + offers inconsistent command options + """ + self._test_channel_read() + self.enable(enable_pattern=r"#") + super().set_base_prompt() + super().disable_paging() + self.clear_buffer() + + def check_config_mode( + self, + check_string: str = "(Config)#", + pattern: str = "#", + force_regex: bool = False, + ) -> bool: + """ + Checks if the device is in configuration mode or not. + + :param check_string: Identification of configuration mode from the device + :type check_string: str + + :param pattern: Pattern to terminate reading of channel + :type pattern: str + + :param force_regex: Use regular expression pattern to find check_string in output + :type force_regex: bool + + :return: True if in configuration mode, False if not + """ + return super().check_config_mode( + check_string=check_string, pattern=pattern, force_regex=force_regex + ) + + def exit_enable_mode(self, exit_command: str = "end") -> str: + """Exits enable (privileged exec) mode.""" + return super().exit_enable_mode(exit_command=exit_command) + + def cleanup(self, command: str = "logout") -> None: + """ + Cleanup / Gracefully exit the SSH session + + :param command: LANCOM LCOS SX 5.x uses logout to exit the session + :type command: str + """ + # LANCOM does not allow running "Exec" commands in configuration mode + if self.check_config_mode(): + command = "do " + command + return super().cleanup(command) + + def save_config( + self, + cmd: str = "write memory confirm", + confirm: bool = False, + confirm_response: str = "y", + ) -> str: + """ + Save the running Config. + + :param cmd: The command to send to the device to save the configuration + :type cmd: str + + :param confirm: Whether to confirm the save or not + :type confirm: bool + + :param confirm_response: The response to send to the device to confirm the save + :type confirm_response: str + + :param output_pattern: The pattern to match the output of the save command + :type output_pattern: str + """ + + # LANCOM does not allow running "Exec" commands in configuration mode + if self.check_config_mode(): + cmd = "do " + cmd + return super().save_config( + cmd=cmd, + confirm=confirm, + confirm_response=confirm_response, + ) diff --git a/netmiko/ssh_dispatcher.py b/netmiko/ssh_dispatcher.py index 5a88cd30a..06a27d246 100644 --- a/netmiko/ssh_dispatcher.py +++ b/netmiko/ssh_dispatcher.py @@ -114,7 +114,7 @@ from netmiko.juniper import JuniperSSH, JuniperTelnet, JuniperScreenOsSSH from netmiko.juniper import JuniperFileTransfer from netmiko.keymile import KeymileSSH, KeymileNOSSSH -from netmiko.lancom import LancomLCOSSX4SSH +from netmiko.lancom import LancomLCOSSX4SSH, LancomLCOSSX5SSH from netmiko.linux import LinuxSSH, LinuxFileTransfer from netmiko.maipu import MaipuSSH from netmiko.maipu import MaipuTelnet @@ -294,6 +294,7 @@ "keymile": KeymileSSH, "keymile_nos": KeymileNOSSSH, "lancom_lcossx4": LancomLCOSSX4SSH, + "lancom_lcossx5": LancomLCOSSX5SSH, "linux": LinuxSSH, "mikrotik_routeros": MikrotikRouterOsSSH, "mikrotik_switchos": MikrotikSwitchOsSSH,