Pure functions for ServiceRoot, ComputerSystem (facts, power state, reset action and ActionInfo), Processors, Memory, Storage/Drives/SimpleStorage, Chassis Thermal and Power as well as ThermalSubsystem/PowerSubsystem/Sensors (with environment_sources to pick whichever exists), Manager, EthernetInterfaces, ManagerNetworkProtocol, accounts, firmware inventory and log services/entries.
74 lines
3.2 KiB
Python
74 lines
3.2 KiB
Python
"""ComputerSystem (``Systems/{id}``): the managed server, its power state and reset action."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Mapping
|
|
|
|
from .common import ident, integer, link_list, links, number, status, text
|
|
|
|
|
|
def parse_system(system: Mapping[str, Any]) -> dict[str, Any]:
|
|
"""Identity, summaries and links of the managed server."""
|
|
state, health = status(system)
|
|
cpus = system.get("ProcessorSummary") if isinstance(system.get("ProcessorSummary"),
|
|
Mapping) else {}
|
|
memory = system.get("MemorySummary") if isinstance(system.get("MemorySummary"),
|
|
Mapping) else {}
|
|
return {
|
|
"id": text(system.get("Id")),
|
|
"name": text(system.get("Name")),
|
|
"manufacturer": ident(system.get("Manufacturer")),
|
|
"model": ident(system.get("Model")),
|
|
"serial_number": ident(system.get("SerialNumber")),
|
|
"uuid": ident(system.get("UUID")),
|
|
"hostname": text(system.get("HostName")),
|
|
"sku": ident(system.get("SKU")),
|
|
"part_number": ident(system.get("PartNumber")),
|
|
"asset_tag": ident(system.get("AssetTag")),
|
|
"bios_version": text(system.get("BiosVersion")),
|
|
"system_type": text(system.get("SystemType")),
|
|
"power_state": parse_power_state(system),
|
|
"state": state,
|
|
"health": health,
|
|
"processor_count": integer(cpus.get("Count")),
|
|
"processor_model": text(cpus.get("Model")),
|
|
"memory_gib": number(memory.get("TotalSystemMemoryGiB")),
|
|
"links": links(system),
|
|
"chassis": link_list(system, "Links", "Chassis"),
|
|
"managed_by": link_list(system, "Links", "ManagedBy"),
|
|
}
|
|
|
|
|
|
def parse_power_state(system: Mapping[str, Any]) -> str | None:
|
|
"""``PowerState``: On, Off, PoweringOn, PoweringOff or Paused; ``None`` if not reported."""
|
|
return text(system.get("PowerState"))
|
|
|
|
|
|
def parse_reset_action(resource: Mapping[str, Any],
|
|
action: str = "#ComputerSystem.Reset") -> dict[str, Any]:
|
|
"""Target and allowed ``ResetType`` values of a reset action.
|
|
|
|
``allowed`` is ``None`` when the service does not list the values inline. Then
|
|
``action_info`` may name the ActionInfo resource that does (see ``parse_action_info``).
|
|
Works for ``#Manager.Reset`` too.
|
|
"""
|
|
actions = resource.get("Actions")
|
|
entry = actions.get(action) if isinstance(actions, Mapping) else None
|
|
if not isinstance(entry, Mapping):
|
|
return {"target": None, "allowed": None, "action_info": None}
|
|
allowed = entry.get("ResetType@Redfish.AllowableValues")
|
|
return {
|
|
"target": text(entry.get("target")),
|
|
"allowed": [str(v) for v in allowed] if isinstance(allowed, list) else None,
|
|
"action_info": text(entry.get("@Redfish.ActionInfo")),
|
|
}
|
|
|
|
|
|
def parse_action_info(info: Mapping[str, Any], parameter: str = "ResetType") -> list[str] | None:
|
|
"""``AllowableValues`` of one parameter in an ActionInfo resource."""
|
|
for param in info.get("Parameters") or []:
|
|
if isinstance(param, Mapping) and param.get("Name") == parameter:
|
|
values = param.get("AllowableValues")
|
|
return [str(v) for v in values] if isinstance(values, list) else None
|
|
return None
|