Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion netmiko/lancom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from netmiko.lancom.lancom_lcossx4 import LancomLCOSSX4SSH
from netmiko.lancom.lancom_lcossx5 import LancomLCOSSX5SSH

__all__ = ["LancomLCOSSX4SSH"]
__all__ = ["LancomLCOSSX4SSH", "LancomLCOSSX5SSH"]
98 changes: 98 additions & 0 deletions netmiko/lancom/lancom_lcossx5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from netmiko.cisco_base_connection import CiscoSSHConnection
from typing import Any


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()
super().send_command_timing(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you are calling send_command for this instead of just using self.enable()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested multiple versions with self.enable(), and i wasn't able to get it working. I think it has to do with LANCOM not prompting for enable passwords at all.
Therefore i chose to use this workaround.

Copy link
Contributor Author

@Nivispluma Nivispluma Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*EDIT: i had the following Error:

ValueError: Failed to enter enable mode. Please ensure you pass the 'secret' argument to ConnectHandler.

However i was able to resolve this by passing the enable_pattern which results in self.enable(enable_pattern=r"#").
Now its working as you suggested :)

"enable",
strip_prompt=False,
strip_command=False,
)
super().set_base_prompt()
super().disable_paging()
self.clear_buffer()

def set_terminal_width(self, *args: Any, **kwargs: Any) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to override the set_terminal_width. It's only ever called from session_preparation which you already override. If you do really want to keep it, you should have it raise NotImplementedError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have removed the redundant function

"""
LCOS SX 5 does not support 'terminal width', therefore skip it.
"""
return ""

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,
)
3 changes: 2 additions & 1 deletion netmiko/ssh_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -289,6 +289,7 @@
"keymile": KeymileSSH,
"keymile_nos": KeymileNOSSSH,
"lancom_lcossx4": LancomLCOSSX4SSH,
"lancom_lcossx5": LancomLCOSSX5SSH,
"linux": LinuxSSH,
"mikrotik_routeros": MikrotikRouterOsSSH,
"mikrotik_switchos": MikrotikSwitchOsSSH,
Expand Down