Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContainedByChassis to inventory catalog #85

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions redfish_utilities/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_system_inventory( context ):
for chassis_id in chassis_ids:
chassis_instance = {
"ChassisName": chassis_id,
"ContainedByChassis": None,
"Chassis": [],
"Processors": [],
"Memory": [],
Expand Down Expand Up @@ -126,6 +127,28 @@ def catalog_collection( context, resource, name, inventory, chassis_id ):
raise
catalog_array( context, collection.dict, "Members", inventory, chassis_id )

def update_chassis_property( context, property_value, property_name, inventory, chassis_id ):
"""
Updates a property for a chassis_id in the inventory list

Args:
context: The Redfish client object with an open session
property_value: The property value
property_name: The property name
inventory: The inventory to update
chassis_id: The identifier for the chassis being updated
"""
# Find the inventory instance to update based on the chassis identifier
inventory_instance = None
for chassis_inventory in inventory:
if chassis_inventory["ChassisName"] == chassis_id:
inventory_instance = chassis_inventory
if inventory_instance is None:
# No matching entry in the inventory to update
return
inventory_instance[property_name] = property_value


def catalog_resource( context, resource, inventory, chassis_id ):
"""
Catalogs a resource for the inventory list
Expand All @@ -151,6 +174,9 @@ def catalog_resource( context, resource, inventory, chassis_id ):
catalog_array( context, resource["Links"], "PCIeDevices", inventory, chassis_id )
catalog_array( context, resource["Links"], "Switches", inventory, chassis_id )
catalog_array( context, resource["Links"], "ComputerSystems", inventory, chassis_id )
if "ContainedBy" in resource["Links"]:
if "@odata.id" in resource["Links"]["ContainedBy"]:
update_chassis_property( context, resource["Links"]["ContainedBy"]["@odata.id"], "ContainedByChassis", inventory, chassis_id)
elif resource_type == "ComputerSystem":
# Catalog all of the components within the system
catalog_collection( context, resource, "Processors", inventory, chassis_id )
Expand Down