From 3e045be1d90804ef4f41d15e97899326967dd7b9 Mon Sep 17 00:00:00 2001 From: alexquali Date: Wed, 3 Jul 2024 21:10:14 +0200 Subject: [PATCH 1/2] Fixed regex for outlets determination --- cloudshell/raritan/command_actions/system_actions.py | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudshell/raritan/command_actions/system_actions.py b/cloudshell/raritan/command_actions/system_actions.py index a20b2f0..69f103b 100644 --- a/cloudshell/raritan/command_actions/system_actions.py +++ b/cloudshell/raritan/command_actions/system_actions.py @@ -53,7 +53,7 @@ def get_outlets(self) -> dict[str, str]: ).execute_command() for outlet_id, outlet_state in re.findall( - r"Outlet\s+(?P\d+):\sPower state:\s+(?P\w+)", + r"Outlet\s+(?P\d+).*:\sPower state:\s+(?P\w+)", output, ): outlets_info.update({outlet_id: outlet_state}) diff --git a/version.txt b/version.txt index 3eefcb9..7dea76e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.0 +1.0.1 From 509937e6bd87e5e5c076da013e6749d66253af2e Mon Sep 17 00:00:00 2001 From: alexquali Date: Mon, 15 Jul 2024 16:32:17 +0200 Subject: [PATCH 2/2] Added raritan telnet and ssh sessions --- .../raritan/cli/raritan_cli_configurator.py | 8 +++--- cloudshell/raritan/cli/raritan_ssh_session.py | 28 +++++++++++++++++++ .../raritan/cli/raritan_telnet_session.py | 23 +++++++++++++++ version.txt | 2 +- 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 cloudshell/raritan/cli/raritan_ssh_session.py create mode 100644 cloudshell/raritan/cli/raritan_telnet_session.py diff --git a/cloudshell/raritan/cli/raritan_cli_configurator.py b/cloudshell/raritan/cli/raritan_cli_configurator.py index 440536a..a31abbf 100644 --- a/cloudshell/raritan/cli/raritan_cli_configurator.py +++ b/cloudshell/raritan/cli/raritan_cli_configurator.py @@ -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 @@ -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} diff --git a/cloudshell/raritan/cli/raritan_ssh_session.py b/cloudshell/raritan/cli/raritan_ssh_session.py new file mode 100644 index 0000000..17d8984 --- /dev/null +++ b/cloudshell/raritan/cli/raritan_ssh_session.py @@ -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) diff --git a/cloudshell/raritan/cli/raritan_telnet_session.py b/cloudshell/raritan/cli/raritan_telnet_session.py new file mode 100644 index 0000000..04d15dc --- /dev/null +++ b/cloudshell/raritan/cli/raritan_telnet_session.py @@ -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 diff --git a/version.txt b/version.txt index 7dea76e..6d7de6e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.1 +1.0.2