Skip to content

RedfishResource

RedfishResource

Redfish API for DMTF BMC compatibility.

Redfish does not use the standard PiKVM response format, so it calls :pymethod:PiKVM.request directly.

Source code in src/aiopikvm/resources/redfish.py
class RedfishResource(BaseResource):
    """Redfish API for DMTF BMC compatibility.

    Redfish does not use the standard PiKVM response format,
    so it calls :pymethod:`PiKVM.request` directly.
    """

    async def _redfish_request(
        self,
        method: str,
        path: str,
        *,
        json: dict[str, Any] | None = None,
    ) -> dict[str, Any]:
        """Send a Redfish request and parse the JSON response.

        Args:
            method: HTTP method.
            path: URL path.
            json: Optional JSON body.

        Returns:
            Parsed JSON response.
        """
        response = await self._client.request(method, path, json=json)
        try:
            result: dict[str, Any] = response.json()
        except (ValueError, TypeError) as exc:
            raise APIError(f"Invalid JSON response: {response.text[:200]}") from exc
        return result

    async def get_root(self) -> dict[str, Any]:
        """Get the Redfish service root.

        Returns:
            Service root document.
        """
        return await self._redfish_request("GET", "/api/redfish/v1")

    async def get_systems(self) -> dict[str, Any]:
        """Get the systems collection.

        Returns:
            Systems collection document.
        """
        return await self._redfish_request("GET", "/api/redfish/v1/Systems")

    async def get_system(self, system_id: int = 0) -> dict[str, Any]:
        """Get details for a specific system.

        Args:
            system_id: System index (default ``0``).

        Returns:
            System resource document.
        """
        return await self._redfish_request(
            "GET", f"/api/redfish/v1/Systems/{system_id}"
        )

    async def update_system(self, system_id: int = 0, **attrs: Any) -> dict[str, Any]:
        """Update system configuration.

        Args:
            system_id: System index (default ``0``).
            **attrs: Redfish attributes to update
                (e.g. ``IndicatorLED="Lit"``).

        Returns:
            Updated system resource document.
        """
        return await self._redfish_request(
            "PATCH", f"/api/redfish/v1/Systems/{system_id}", json=attrs
        )

    async def reset(self, reset_type: str = "ForceRestart") -> dict[str, Any]:
        """Send a Redfish ComputerSystem.Reset action.

        Args:
            reset_type: The reset type (default ``"ForceRestart"``).

        Returns:
            The JSON response body.
        """
        return await self._redfish_request(
            "POST",
            "/api/redfish/v1/Systems/0/Actions/ComputerSystem.Reset",
            json={"ResetType": reset_type},
        )

get_root() async

Get the Redfish service root.

Returns:

Type Description
dict[str, Any]

Service root document.

Source code in src/aiopikvm/resources/redfish.py
async def get_root(self) -> dict[str, Any]:
    """Get the Redfish service root.

    Returns:
        Service root document.
    """
    return await self._redfish_request("GET", "/api/redfish/v1")

get_systems() async

Get the systems collection.

Returns:

Type Description
dict[str, Any]

Systems collection document.

Source code in src/aiopikvm/resources/redfish.py
async def get_systems(self) -> dict[str, Any]:
    """Get the systems collection.

    Returns:
        Systems collection document.
    """
    return await self._redfish_request("GET", "/api/redfish/v1/Systems")

get_system(system_id=0) async

Get details for a specific system.

Parameters:

Name Type Description Default
system_id int

System index (default 0).

0

Returns:

Type Description
dict[str, Any]

System resource document.

Source code in src/aiopikvm/resources/redfish.py
async def get_system(self, system_id: int = 0) -> dict[str, Any]:
    """Get details for a specific system.

    Args:
        system_id: System index (default ``0``).

    Returns:
        System resource document.
    """
    return await self._redfish_request(
        "GET", f"/api/redfish/v1/Systems/{system_id}"
    )

update_system(system_id=0, **attrs) async

Update system configuration.

Parameters:

Name Type Description Default
system_id int

System index (default 0).

0
**attrs Any

Redfish attributes to update (e.g. IndicatorLED="Lit").

{}

Returns:

Type Description
dict[str, Any]

Updated system resource document.

Source code in src/aiopikvm/resources/redfish.py
async def update_system(self, system_id: int = 0, **attrs: Any) -> dict[str, Any]:
    """Update system configuration.

    Args:
        system_id: System index (default ``0``).
        **attrs: Redfish attributes to update
            (e.g. ``IndicatorLED="Lit"``).

    Returns:
        Updated system resource document.
    """
    return await self._redfish_request(
        "PATCH", f"/api/redfish/v1/Systems/{system_id}", json=attrs
    )

reset(reset_type='ForceRestart') async

Send a Redfish ComputerSystem.Reset action.

Parameters:

Name Type Description Default
reset_type str

The reset type (default "ForceRestart").

'ForceRestart'

Returns:

Type Description
dict[str, Any]

The JSON response body.

Source code in src/aiopikvm/resources/redfish.py
async def reset(self, reset_type: str = "ForceRestart") -> dict[str, Any]:
    """Send a Redfish ComputerSystem.Reset action.

    Args:
        reset_type: The reset type (default ``"ForceRestart"``).

    Returns:
        The JSON response body.
    """
    return await self._redfish_request(
        "POST",
        "/api/redfish/v1/Systems/0/Actions/ComputerSystem.Reset",
        json={"ResetType": reset_type},
    )