-
Notifications
You must be signed in to change notification settings - Fork 1.4k
ADD: Support for LANCOM LCOS SX 5 #3670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
334598b
98b0e6f
b9d7f7c
a46a7ff
fbcd501
af0da15
763b60f
c76f03a
3a1aadd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"] |
| 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( | ||
| "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: | ||
|
||
| """ | ||
| 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, | ||
| ) | ||
There was a problem hiding this comment.
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()?
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
However i was able to resolve this by passing the
enable_patternwhich results inself.enable(enable_pattern=r"#").Now its working as you suggested :)