Skip to content

Commit a6d3210

Browse files
committed
Add ContainedByChassisUri and ContainsChassisUris to inventory catalog
Signed-off-by: Derek Chan <[email protected]>
1 parent 9b2f961 commit a6d3210

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

redfish_utilities/inventory.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def catalog_resource( context, resource, inventory, chassis_id ):
207207
"AssetTag": resource.get( "AssetTag", None ),
208208
"Label": resource.get( location_prop, {} ).get( "PartLocation", {} ).get( "ServiceLabel", None ),
209209
"State": resource.get( "Status", {} ).get( "State", None ),
210-
"Description": None
210+
"Description": None,
211+
"ContainedByChassisUri": None,
212+
"ContainsChassisUris": []
211213
}
212214

213215
# If no label was found, build a default name
@@ -284,6 +286,31 @@ def catalog_resource( context, resource, inventory, chassis_id ):
284286
description_str = description_str + " Storage Controller"
285287
catalog["Description"] = description_str.strip()
286288

289+
# Determine the chassis containment links:
290+
# Chassis resources have explicit ContainedBy and Contains Links
291+
if resource_type == "Chassis":
292+
if "Links" in resource:
293+
if "ContainedBy" in resource["Links"] and "@odata.id" in resource["Links"]["ContainedBy"]:
294+
catalog["ContainedByChassisUri"] = resource["Links"]["ContainedBy"]["@odata.id"]
295+
if "Contains" in resource["Links"]:
296+
for contains_link in [contained["@odata.id"] for contained in resource["Links"]["Contains"] if "@odata.id" in contained]:
297+
catalog["ContainsChassisUris"].append(contains_link)
298+
299+
# Processor, Memory, and Drive resources have Chassis Links
300+
elif resource_type == "Processor" or resource_type == "Memory" or resource_type == "Drive":
301+
if "Links" in resource and "Chassis" in resource["Links"] and "@odata.id" in resource["Links"]["Chassis"]:
302+
catalog["ContainedByChassisUri"] = resource["Links"]["Chassis"]["@odata.id"]
303+
304+
# These remaining types do not have explicit links yet
305+
elif resource_type == "PCIeDevice":
306+
pass
307+
elif resource_type == "StorageController":
308+
pass
309+
elif resource_type == "NetworkAdapter":
310+
pass
311+
elif resource_type == "Switch":
312+
pass
313+
287314
# Find the inventory instance to update based on the chassis identifier
288315
inventory_instance = None
289316
for chassis_inventory in inventory:

0 commit comments

Comments
 (0)