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

handle different storage controller responses #58

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
23 changes: 15 additions & 8 deletions prometheus_hardware_exporter/collectors/redfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _storage_root_uri(cls, system_id: str, storage_name: str) -> str:
system_id: "S1"
storage_name" "Storage"
"""
return cls.systems_root_uri + f"{system_id}/{storage_name}/"
return cls.systems_root_uri + f"{system_id}/{storage_name}"

def get_storage_controller_data(self) -> Tuple[Dict[str, int], Dict[str, List]]:
"""Return storage controller data and count.
Expand Down Expand Up @@ -287,21 +287,28 @@ def get_storage_controller_data(self) -> Tuple[Dict[str, int], Dict[str, List]]:
for storage_id in storage_ids:
# eg: /redfish/v1/Systems/1/Storage/XYZ123
curr_storage_uri = (
RedfishHelper._storage_root_uri(system_id, storage_name) + storage_id
RedfishHelper._storage_root_uri(system_id, storage_name) + "/" + storage_id
)

# list of storage controllers for that storage id
storage_controllers_list: List[Dict] = self.redfish_obj.get(curr_storage_uri).dict[
"StorageControllers"
]
storage_controller_count[system_id] += len(storage_controllers_list)
storage_controllers = self.redfish_obj.get(curr_storage_uri).dict
if "StorageControllers" in storage_controllers:
storage_controllers_list: List[Dict] = storage_controllers.get("StorageControllers")
if "Controllers" in storage_controllers:
rgildein marked this conversation as resolved.
Show resolved Hide resolved
storage_controllers_list: List[Dict] = []
controller_list = storage_controllers.get("Controllers")
for controller in controller_list.values():
all_controller_data = self.redfish_obj.get(controller).dict
for controller in all_controller_data["Members"]:
storage_controllers_list.append(self.redfish_obj.get(controller["@odata.id"]).dict)
rgildein marked this conversation as resolved.
Show resolved Hide resolved


# picking out the required data from each storage controller in the list
for data in storage_controllers_list:
storage_controller_data_in_curr_system.append(
{
"storage_id": storage_id,
"controller_id": data["MemberId"],
"controller_id": data["MemberId"] if data.get("MemberId", None) else data.get("Id"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs: A comment here as well mentioning that Id is what we expect if the key being used is Controllers in the storage data would be helpful

"state": data["Status"]["State"],
"health": data["Status"]["Health"] or "NA",
}
Expand Down Expand Up @@ -455,7 +462,7 @@ def get_storage_drive_data(self) -> Tuple[Dict[str, int], Dict[str, List]]:
for storage_id in storage_ids:
# eg: /redfish/v1/Systems/1/Storage/XYZ123/
curr_storage_uri = (
RedfishHelper._storage_root_uri(system_id, storage_name) + storage_id
RedfishHelper._storage_root_uri(system_id, storage_name) + "/" + storage_id
)

# list of storage drives for that storage id
Expand Down
Loading