-
Notifications
You must be signed in to change notification settings - Fork 5
Add missing LinuxSer2Net class #1
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
Open
jrrech
wants to merge
5
commits into
evedovelli:main
Choose a base branch
from
jrrech:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from typing import Optional | ||
|
|
||
| from ..CoreCli import CoreCli | ||
| from ..connections.Ser2Net import Ser2Net | ||
| from ..connections.Ssh import Ssh, PTY_WINSIZE_COLS | ||
| from ..connections.Ssh import PTY_WINSIZE_COLS as SSH_PTY_WINSIZE_COLS | ||
|
|
||
|
|
@@ -42,20 +43,23 @@ def __init__(self, | |
| username: str, | ||
| password: str, | ||
| port: Optional[int]=22, | ||
| id_file: Optional[str]=None, | ||
| **opts): | ||
| """ Initialize Linux Shell. | ||
| @param ip IP address of target. Ex: '234.168.10.12' | ||
| @param username username for opening SSH connection | ||
| @param password String with password corresponding to the username to login into | ||
| the connection that provides access to the CLI. | ||
| @param port Port used for SSH connection. Defaults to 22 | ||
| @param id_file Path of file to be used as user identification (usually a private key) | ||
| @param opts Same options as CoreCli initializer. | ||
| """ | ||
| if not 'marker' in opts: | ||
| opts['marker'] = '#|>' | ||
|
|
||
| self.name = "Linux.SSH" | ||
| ssh = Ssh(ip, username, port=port) | ||
| self.has_id = id_file != None | ||
| ssh = Ssh(ip, username, port=port, identification=id_file) | ||
| Linux.__init__(self, | ||
| ssh, | ||
| username=username, | ||
|
|
@@ -83,3 +87,55 @@ def logout(self): | |
| """ Logout from CLI interface. | ||
| """ | ||
| self.connection.terminal.sendline('exit') | ||
|
|
||
|
|
||
| #################################################################################################### | ||
| ## Ser2NetLinux | ||
|
|
||
| class Ser2NetLinux(SshLinux): | ||
| """ Connects to a remote Linux Shell using SSH. | ||
| Core implementation is done by Ssh and Linux. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace SSH with Ser2Net in the comments above |
||
| """ | ||
|
|
||
| def __init__(self, | ||
| ip: str, | ||
| port: int, | ||
| username: str, | ||
| password: str, | ||
| **opts): | ||
| """ Initialize Linux Shell. | ||
| @param ip IP address of ser2net server. Ex: '234.168.10.12' | ||
| @param port Port used for ser2net connection. | ||
| @param username username for opening ser2net connection | ||
| @param password String with password corresponding to the username to login into | ||
| the connection that provides access to the CLI. | ||
|
|
||
| @param opts Same options as CoreCli initializer. | ||
| """ | ||
| if not 'marker' in opts: | ||
| opts['marker'] = '#|>' | ||
|
|
||
| self.name = "Linux.Ser2Net" | ||
| ser2net = Ser2Net(ip, port) | ||
| Linux.__init__(self, | ||
| ser2net, | ||
| username=username, | ||
| password=password, | ||
| pty_winsize_cols=SSH_PTY_WINSIZE_COLS, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you should import and use the PTY_WINSIZE_COLS from Ser2Net instead |
||
| **opts) | ||
|
|
||
| def login(self): | ||
| """ Login to CLI interface. | ||
| """ | ||
| while True: | ||
| index = self.connection.terminal.expect( | ||
| ['.ogin', '.assword', self.marker], | ||
| timeout=10) | ||
|
|
||
| if index == 0: | ||
| self.connection.terminal.sendline(self.username) | ||
| if index == 1: | ||
| self.connection.terminal.waitnoecho() | ||
| self.connection.terminal.sendline(self.password) | ||
| if index >= 2: | ||
| break | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is it extendind the SshLinux instead of Linux? Is it only for the implementation of the logout function? If so, move it to the Linux class and extend the Ser2NetLinux from Linux, because the SshLinux may have invalid methods for Ser2NetLinux in the future.
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.
At first I tried to reuse the login function as well, but it needed some tuning for Ser2Net in the end. It does make more sense extending
Linux, though.