MCPcopy Create free account
hub / github.com/ceph/ceph / build_data

Function build_data

src/ceph-node-proxy/ceph_node_proxy/redfish.py:234–265  ·  view source on GitHub ↗
(
    data: Dict[str, Any],
    fields: List[str],
    log: Any,
    attribute: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

232
233
234def build_data(
235 data: Dict[str, Any],
236 fields: List[str],
237 log: Any,
238 attribute: Optional[str] = None,
239) -> Dict[str, Dict[str, Dict]]:
240 result: Dict[str, Dict[str, Optional[Dict]]] = dict()
241
242 def process_data(m_id: str, flds: List[str], d: Dict[str, Any]) -> Dict[str, Any]:
243 out: Dict[str, Any] = {}
244 for field in flds:
245 try:
246 out[to_snake_case(field)] = d[field]
247 except KeyError:
248 log.debug(f"Could not find field: {field} in data: {d}")
249 out[to_snake_case(field)] = None
250 return out
251
252 try:
253 if attribute is not None:
254 data_items = data[attribute]
255 else:
256 data_items = [{"MemberId": k, **v} for k, v in data.items()]
257 log.debug(f"build_data: data_items count={len(data_items)}")
258 for d in data_items:
259 member_id = d.get("MemberId")
260 result[member_id] = {}
261 result[member_id] = process_data(member_id, fields, d)
262 except (KeyError, TypeError, AttributeError) as e:
263 log.error(f"Can't build data: {e}")
264 raise
265 return normalize_dict(result)
266
267
268def _resolve_path(endpoint: Endpoint, path: str) -> Endpoint:

Callers 1

get_component_dataFunction · 0.85

Calls 6

normalize_dictFunction · 0.90
process_dataFunction · 0.85
itemsMethod · 0.45
debugMethod · 0.45
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected