Extend parsers for the driver
parse_power_supply also reads items of the legacy Power.PowerSupplies array, parse_ethernet_interface exposes the raw LinkStatus, and parse_network_protocol reports protocols that carry a Port without a ProtocolEnabled flag.
This commit is contained in:
4 files changed
+38
-14
No files matched your search
@@ -134,16 +134,12 @@ def parse_power(power: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"""``Chassis/{id}/Power``: ``power`` (supplies), ``voltages``, ``consumed_watts``."""
|
||||
supplies: dict[str, Any] = {}
|
||||
for index, item in _members(power, "PowerSupplies"):
|
||||
if not present(item):
|
||||
psu = parse_power_supply(item)
|
||||
if not psu["present"]:
|
||||
continue
|
||||
name = unique_name(supplies, _name(item, "Name"), item.get("MemberId", index))
|
||||
capacity = number(item.get("PowerCapacityWatts"))
|
||||
output = number(item.get("LastPowerOutputWatts"))
|
||||
supplies[name] = {
|
||||
"status": _ok(item),
|
||||
"capacity": capacity if capacity is not None else -1.0,
|
||||
"output": output if output is not None else -1.0,
|
||||
}
|
||||
name = unique_name(supplies, psu["name"], item.get("MemberId", index))
|
||||
supplies[name] = {"status": psu["status"], "capacity": psu["capacity"],
|
||||
"output": psu["output"]}
|
||||
|
||||
voltages: dict[str, Any] = {}
|
||||
for index, item in _members(power, "Voltages"):
|
||||
@@ -210,12 +206,18 @@ def parse_fan(fan: Mapping[str, Any]) -> dict[str, Any]:
|
||||
|
||||
def parse_power_supply(supply: Mapping[str, Any],
|
||||
metrics: Mapping[str, Any] | None = None) -> dict[str, Any]:
|
||||
"""One member of ``PowerSubsystem/PowerSupplies``, with its ``Metrics`` if read."""
|
||||
"""One member of ``PowerSubsystem/PowerSupplies``, with its ``Metrics`` if read.
|
||||
|
||||
An item of the legacy ``Power.PowerSupplies`` array parses too (``MemberId`` as id,
|
||||
``LastPowerOutputWatts`` as output).
|
||||
"""
|
||||
state, health = status(supply)
|
||||
capacity = number(supply.get("PowerCapacityWatts"))
|
||||
output = _excerpt(metrics, "OutputPowerWatts") if metrics else None
|
||||
if output is None:
|
||||
output = number(supply.get("LastPowerOutputWatts"))
|
||||
return {
|
||||
"id": text(supply.get("Id")),
|
||||
"id": text(supply.get("Id")) or text(supply.get("MemberId")),
|
||||
"name": _name(supply, "Name"),
|
||||
"present": present(supply),
|
||||
"status": _ok(supply),
|
||||
|
||||
@@ -99,6 +99,7 @@ def parse_ethernet_interface(iface: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"ipv6": _ipv6(iface.get("IPv6Addresses")),
|
||||
"hostname": text(iface.get("HostName")),
|
||||
"fqdn": text(iface.get("FQDN")),
|
||||
"link_status": link_status,
|
||||
"vlan": vlan_id,
|
||||
"permanent_mac_address": _mac(iface.get("PermanentMACAddress")) or None,
|
||||
}
|
||||
@@ -107,13 +108,13 @@ def parse_ethernet_interface(iface: Mapping[str, Any]) -> dict[str, Any]:
|
||||
def parse_network_protocol(proto: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"""``Managers/{id}/NetworkProtocol``: which services the BMC runs, NTP and SNMP.
|
||||
|
||||
``protocols`` holds every property with a ``ProtocolEnabled`` flag, so OEM-free services
|
||||
the schema adds later show up without code changes. NTP servers and the SNMP details
|
||||
``protocols`` holds every property with a ``ProtocolEnabled`` flag or a ``Port``, so
|
||||
services the schema adds later show up without code changes. NTP servers and the SNMP details
|
||||
exist only in newer schema versions; missing values are ``None``.
|
||||
"""
|
||||
protocols = {}
|
||||
for key, value in proto.items():
|
||||
if isinstance(value, Mapping) and "ProtocolEnabled" in value:
|
||||
if isinstance(value, Mapping) and ("ProtocolEnabled" in value or "Port" in value):
|
||||
protocols[key] = {
|
||||
"enabled": boolean(value.get("ProtocolEnabled")),
|
||||
"port": integer(value.get("Port")),
|
||||
|
||||
Reference in new issue
Block a user