from ceph_node_proxy.baseredfishsystem import BaseRedfishSystem
from ceph_node_proxy.util import get_logger
-from typing import Any, Dict
+from typing import Any
class AtollonSystem(BaseRedfishSystem):
def __init__(self, **kw: Any) -> None:
super().__init__(**kw)
self.log = get_logger(__name__)
-
- def get_component_spec_overrides(self) -> Dict[str, Dict[str, Any]]:
- return {'power': {'path': 'PowerSubsystem'}}
'network': ComponentUpdateSpec('systems', 'EthernetInterfaces', NETWORK_FIELDS, None),
'processors': ComponentUpdateSpec('systems', 'Processors', PROCESSORS_FIELDS, None),
'memory': ComponentUpdateSpec('systems', 'Memory', MEMORY_FIELDS, None),
- 'power': ComponentUpdateSpec('chassis', 'Power', POWER_FIELDS, 'PowerSupplies'),
+ # Power supplies: Chassis/.../PowerSubsystem/PowerSupplies (not like other components: like Systems/.../Memory)
+ 'power': ComponentUpdateSpec('chassis', 'PowerSubsystem/PowerSupplies', POWER_FIELDS, None),
'fans': ComponentUpdateSpec('chassis', 'Thermal', FANS_FIELDS, 'Fans'),
'firmwares': ComponentUpdateSpec('update_service', 'FirmwareInventory', FIRMWARES_FIELDS, None),
}
return normalize_dict(result)
+def _resolve_path(endpoint: Endpoint, path: str) -> Endpoint:
+ """Resolve an endpoint by traversing path segments (example: 'PowerSubsystem/PowerSupplies')."""
+ parts = [p for p in path.split('/') if p]
+ current = endpoint
+ for part in parts:
+ current = current[part]
+ return current
+
+
def update_component(
endpoints: EndpointMgr,
collection: str,
log: Any,
attribute: Optional[str] = None,
) -> None:
- """Update _sys[component] from Redfish endpoints using the given spec."""
+ """Update _sys[component] from Redfish endpoints using the given spec.
+ path can be a single segment ('Memory') or multiple ('PowerSubsystem/PowerSupplies').
+ """
members: List[str] = endpoints[collection].get_members_names()
result: Dict[str, Any] = {}
if not members:
- data = endpoints[collection][path].get_members_data()
+ ep = _resolve_path(endpoints[collection], path)
+ data = ep.get_members_data()
result = build_data(data=data, fields=fields, log=log, attribute=attribute)
else:
for member in members:
try:
+ ep = _resolve_path(endpoints[collection][member], path)
if attribute is None:
- data = endpoints[collection][member][path].get_members_data()
+ data = ep.get_members_data()
else:
- data = endpoints[collection][member][path].data
+ data = ep.data
+ result[member] = build_data(data=data, fields=fields, log=log, attribute=attribute)
except HTTPError as e:
log.error(f'Error while updating {component}: {e}')
continue
- result[member] = build_data(data=data, fields=fields, log=log, attribute=attribute)
_sys[component] = result