Skip to content
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
23 changes: 17 additions & 6 deletions nodescraper/base/oobsshdataplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,32 @@
# SOFTWARE.
#
###############################################################################
from __future__ import annotations

from typing import Generic

from nodescraper.connection.inband import InBandConnectionManager, SSHConnectionParams
from nodescraper.connection.redfish import (
RedfishConnectionManager,
RedfishConnectionParams,
)
from nodescraper.generictypes import TAnalyzeArg, TCollectArg, TDataModel
from nodescraper.interfaces import DataPlugin


class OOBSSHDataPlugin(
DataPlugin[InBandConnectionManager, SSHConnectionParams, TDataModel, TCollectArg, TAnalyzeArg],
DataPlugin[
RedfishConnectionManager,
RedfishConnectionParams,
TDataModel,
TCollectArg,
TAnalyzeArg,
],
Generic[TDataModel, TCollectArg, TAnalyzeArg],
):
"""Base class for out-of-band (OOB) plugins that use BMC SSH.
"""Base class for out-of-band (OOB) plugins that run shell commands on the BMC.

Mirrors OOBandDataPlugin but wires InBandConnectionManager so collectors can
inherit from InBandDataCollector and use _run_sut_cmd() unchanged.
Configure the BMC using ``RedfishConnectionManager`` in the connection config.
Commands are executed over SSH (port 22) using the same host/username/password.
"""

CONNECTION_TYPE = InBandConnectionManager
CONNECTION_TYPE = RedfishConnectionManager
28 changes: 28 additions & 0 deletions nodescraper/connection/oob_ssh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
###############################################################################
#
# MIT License
#
# Copyright (c) 2026 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
###############################################################################
from .oob_ssh_connection_manager import OobSshConnectionManager

__all__ = ["OobSshConnectionManager"]
124 changes: 124 additions & 0 deletions nodescraper/connection/oob_ssh/oob_ssh_connection_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
###############################################################################
#
# MIT License
#
# Copyright (c) 2026 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
###############################################################################
from __future__ import annotations

from logging import Logger
from typing import Optional, Union

from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus
from nodescraper.interfaces.connectionmanager import ConnectionManager
from nodescraper.interfaces.taskresulthook import TaskResultHook
from nodescraper.models import SystemInfo, TaskResult
from nodescraper.utils import get_exception_traceback

from ..inband.inband import InBandConnection
from ..inband.inbandremote import RemoteShell, SSHConnectionError
from ..redfish.redfish_params import RedfishConnectionParams, redfish_params_to_ssh


class OobSshConnectionManager(ConnectionManager[InBandConnection, RedfishConnectionParams]):
"""SSH to the BMC using the same host and credentials as Redfish (OOB shell)."""

def __init__(
self,
system_info: SystemInfo,
logger: Optional[Logger] = None,
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
parent: Optional[str] = None,
task_result_hooks: Optional[list[TaskResultHook]] = None,
connection_args: Optional[RedfishConnectionParams] = None,
**kwargs,
):
super().__init__(
system_info,
logger,
max_event_priority_level,
parent,
task_result_hooks,
connection_args,
**kwargs,
)

def connect(self) -> TaskResult:
if not self.connection_args:
self._log_event(
category=EventCategory.RUNTIME,
description="No Redfish connection parameters provided for OOB SSH",
priority=EventPriority.CRITICAL,
console_log=True,
)
self.result.status = ExecutionStatus.EXECUTION_FAILURE
return self.result

raw = self.connection_args
if isinstance(raw, dict):
params = RedfishConnectionParams.model_validate(raw)
elif isinstance(raw, RedfishConnectionParams):
params = raw
else:
self._log_event(
category=EventCategory.RUNTIME,
description="Redfish connection_args must be dict or RedfishConnectionParams",
priority=EventPriority.CRITICAL,
console_log=True,
)
self.result.status = ExecutionStatus.EXECUTION_FAILURE
return self.result

try:
ssh_params = redfish_params_to_ssh(params)
self.logger.info("Initializing OOB SSH to BMC host %s", ssh_params.hostname)
self.connection = RemoteShell(ssh_params)
self.connection.connect_ssh()
except SSHConnectionError as exception:
self._log_event(
category=EventCategory.SSH,
description=str(exception),
priority=EventPriority.CRITICAL,
console_log=True,
)
self.result.status = ExecutionStatus.EXECUTION_FAILURE
self.connection = None
except Exception as exception:
self._log_event(
category=EventCategory.SSH,
description=f"Exception during OOB SSH: {exception!s}",
data=get_exception_traceback(exception),
priority=EventPriority.CRITICAL,
console_log=True,
)
self.result.status = ExecutionStatus.EXECUTION_FAILURE
self.connection = None
return self.result

def disconnect(self) -> None:
conn = self.connection
super().disconnect()
if isinstance(conn, RemoteShell):
try:
conn.client.close()
except Exception:
pass
3 changes: 2 additions & 1 deletion nodescraper/connection/redfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
collect_oem_diagnostic_data,
get_oem_diagnostic_allowable_values,
)
from .redfish_params import RedfishConnectionParams
from .redfish_params import RedfishConnectionParams, redfish_params_to_ssh
from .redfish_path import RedfishPath

__all__ = [
Expand All @@ -48,6 +48,7 @@
"RedfishGetResult",
"RedfishConnectionManager",
"RedfishConnectionParams",
"redfish_params_to_ssh",
"RedfishPath",
"collect_oem_diagnostic_data",
"get_oem_diagnostic_allowable_values",
Expand Down
29 changes: 29 additions & 0 deletions nodescraper/connection/redfish/redfish_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
# SOFTWARE.
#
###############################################################################
from __future__ import annotations

from typing import Optional, Union

from pydantic import BaseModel, ConfigDict, Field, SecretStr
from pydantic.networks import IPvAnyAddress

from nodescraper.connection.inband.sshparams import SSHConnectionParams

from .redfish_connection import DEFAULT_REDFISH_API_ROOT


Expand All @@ -51,3 +55,28 @@ class RedfishConnectionParams(BaseModel):
default=DEFAULT_REDFISH_API_ROOT,
description="Redfish API path (e.g. 'redfish/v1'). Override for a different API version.",
)


def redfish_params_to_ssh(
params: Union[RedfishConnectionParams, dict],
*,
ssh_port: Optional[int] = None,
key_filename: Optional[str] = None,
) -> SSHConnectionParams:
"""Map Redfish BMC credentials to SSH connection params for shell access."""
if isinstance(params, dict):
data = dict(params)
ssh_port = data.pop("ssh_port", ssh_port if ssh_port is not None else 22)
key_filename = data.pop("key_filename", key_filename)
params = RedfishConnectionParams.model_validate(data)
else:
if ssh_port is None:
ssh_port = 22

return SSHConnectionParams(
hostname=str(params.host),
username=params.username,
password=params.password,
port=ssh_port,
key_filename=key_filename,
)
26 changes: 13 additions & 13 deletions nodescraper/interfaces/dataplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,19 @@ def run(
ExecutionStatus.EXECUTION_FAILURE,
ExecutionStatus.WARNING,
]:
if self.analysis_result.status > self.collection_result.status:
message = (
f"Analysis warning: {self.analysis_result.message}"
if self.analysis_result.status == ExecutionStatus.WARNING
else f"Analysis error: {self.analysis_result.message}"
)
else:

message = (
f"Collection warning: {self.collection_result.message}"
if self.collection_result.status == ExecutionStatus.WARNING
else f"Collection error: {self.collection_result.message}"
)
failure_parts: list[str] = []
for label, task_result in (
("Collection", self.collection_result),
("Analysis", self.analysis_result),
):
if task_result.status == ExecutionStatus.WARNING:
failure_parts.append(f"{label} warning: {task_result.message}")
elif task_result.status in (
ExecutionStatus.ERROR,
ExecutionStatus.EXECUTION_FAILURE,
):
failure_parts.append(f"{label} error: {task_result.message}")
message = "; ".join(failure_parts)
else:
message = "Plugin tasks completed successfully"

Expand Down
75 changes: 48 additions & 27 deletions nodescraper/pluginexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

from pydantic import BaseModel

from nodescraper.base.oobsshdataplugin import OOBSSHDataPlugin
from nodescraper.connection.oob_ssh import OobSshConnectionManager
from nodescraper.constants import DEFAULT_LOGGER
from nodescraper.interfaces import ConnectionManager, DataPlugin, PluginInterface
from nodescraper.models import PluginConfig, SystemInfo
Expand Down Expand Up @@ -81,6 +83,9 @@ def __init__(
self.plugin_config = self.merge_configs(plugin_configs)

self.connection_library: dict[type[ConnectionManager], ConnectionManager] = {}
self.connection_configs: dict[str, Union[dict, BaseModel]] = (
dict(connections) if connections else {}
)

self.log_path = log_path

Expand Down Expand Up @@ -175,40 +180,56 @@ def run_queue(self) -> list[PluginResult]:
}

if plugin_class.CONNECTION_TYPE:
connection_manager_class: Type[ConnectionManager] = plugin_class.CONNECTION_TYPE
if (
connection_manager_class.__name__
in self.plugin_registry.connection_managers
):
mgr_impl = self.plugin_registry.connection_managers[
connection_manager_class.__name__
]
elif (
inspect.isclass(connection_manager_class)
and issubclass(connection_manager_class, ConnectionManager)
and not inspect.isabstract(connection_manager_class)
):
# External packages set CONNECTION_TYPE on the plugin;
# use it when not listed under nodescraper.connection_managers entry points.
mgr_impl = connection_manager_class
if issubclass(plugin_class, OOBSSHDataPlugin):
mgr_impl = OobSshConnectionManager
connection_args = self.connection_configs.get("RedfishConnectionManager")
if connection_args is None:
self.logger.error(
"%s requires RedfishConnectionManager in the connection config",
plugin_name,
)
continue
else:
self.logger.error(
"Unable to find registered connection manager class for %s that is required by",
connection_manager_class.__name__,
connection_manager_class: Type[ConnectionManager] = (
plugin_class.CONNECTION_TYPE
)
continue
if (
connection_manager_class.__name__
in self.plugin_registry.connection_managers
):
mgr_impl = self.plugin_registry.connection_managers[
connection_manager_class.__name__
]
elif (
inspect.isclass(connection_manager_class)
and issubclass(connection_manager_class, ConnectionManager)
and not inspect.isabstract(connection_manager_class)
):
# External packages set CONNECTION_TYPE on the plugin;
# use it when not listed under nodescraper.connection_managers entry points.
mgr_impl = connection_manager_class
else:
self.logger.error(
"Unable to find registered connection manager class for %s that is required by",
connection_manager_class.__name__,
)
continue
connection_args = None

if mgr_impl not in self.connection_library:
self.logger.info(
"Initializing connection manager for %s with default args",
"Initializing connection manager for %s",
mgr_impl.__name__,
)
self.connection_library[mgr_impl] = mgr_impl(
system_info=self.system_info,
logger=self.logger,
task_result_hooks=self.connection_result_hooks,
session_id=self.session_id,
)
init_kwargs = {
"system_info": self.system_info,
"logger": self.logger,
"task_result_hooks": self.connection_result_hooks,
"session_id": self.session_id,
}
if connection_args is not None:
init_kwargs["connection_args"] = connection_args
self.connection_library[mgr_impl] = mgr_impl(**init_kwargs)

init_payload["connection_manager"] = self.connection_library[mgr_impl]

Expand Down
Loading
Loading