Skip to content
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

Feature raritan sessions #3

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions cloudshell/raritan/cli/raritan_cli_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from cloudshell.cli.service.command_mode_helper import CommandModeHelper
from cloudshell.cli.session.console_ssh import ConsoleSSHSession
from cloudshell.cli.session.console_telnet import ConsoleTelnetSession
from cloudshell.cli.session.ssh_session import SSHSession
from cloudshell.cli.session.telnet_session import TelnetSession

from cloudshell.raritan.cli.raritan_command_modes import (
ConfigCommandMode,
EnableCommandMode,
)
from cloudshell.raritan.cli.raritan_ssh_session import RaritanSSHSession
from cloudshell.raritan.cli.raritan_telnet_session import RaritanTelnetSession

if TYPE_CHECKING:
from cloudshell.cli.service.cli import CLI
Expand All @@ -33,8 +33,8 @@
@define
class RaritanCliConfigurator(AbstractModeConfigurator):
REGISTERED_SESSIONS: ClassVar[tuple[SessionFactory]] = (
CloudInfoAccessKeySessionFactory(SSHSession),
GenericSessionFactory(TelnetSession),
CloudInfoAccessKeySessionFactory(RaritanSSHSession),
GenericSessionFactory(RaritanTelnetSession),
ConsoleSessionFactory(ConsoleSSHSession),
ConsoleSessionFactory(
ConsoleTelnetSession, session_kwargs={"start_with_new_line": False}
Expand Down
28 changes: 28 additions & 0 deletions cloudshell/raritan/cli/raritan_ssh_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from cloudshell.cli.session.ssh_session import SSHSession

if TYPE_CHECKING:
from logging import Logger


class RaritanSSHSession(SSHSession):
def _connect_actions(self, prompt: str, logger: Logger) -> None:
action_map = dict()
cli_action_key = r"Restricted Service Agreement"

def action(session: RaritanSSHSession, sess_logger: Logger) -> None:
session.send_line("y", sess_logger)
del action_map[cli_action_key]

action_map[cli_action_key] = action
self.hardware_expect(
None,
expected_string=prompt,
action_map=action_map,
timeout=self._timeout,
logger=logger,
)
self._on_session_start(logger)
23 changes: 23 additions & 0 deletions cloudshell/raritan/cli/raritan_telnet_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from cloudshell.cli.session.telnet_session import TelnetSession

if TYPE_CHECKING:
from logging import Logger
from cloudshell.cli.types import T_ACTION_MAP


class RaritanTelnetSession(TelnetSession):
def _connect_action_map(self) -> T_ACTION_MAP:
am = super()._connect_action_map
cli_action_key = r"Restricted Service Agreement"

def action(session: RaritanTelnetSession, sess_logger: Logger) -> None:
session.send_line("y", sess_logger)
del am[cli_action_key]

am[cli_action_key] = action

return am
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
Loading