summaryrefslogtreecommitdiff
path: root/redfish-core/include/utils/fan_utils.hpp
AgeCommit message (Collapse)AuthorFilesLines
2026-08-17Refactor fan_utils getFanPaths lambdaYuvakumar Selvamani1-16/+20
The getFanPaths function contained an inline lambda that triggered the long-lambda ast-grep rule, requiring an inline suppression (// ast-grep-ignore: long-lambda). This commit extracts the lambda into a separate afterGetFanPaths function and uses std::bind_front to handle the asynchronous callback. This aligns the code with the preferred bmcweb pattern for D-Bus callbacks, improves readability, and allows the removal of the static analysis suppression. Change-Id: Ibb72a939590077f1f8b4f19dfc5809d3411d0742 Signed-off-by: Yuvakumar Selvamani <yuvakumars@ami.com>
2026-07-01Flag long lambdasEd Tanous1-0/+1
Long lambdas have been documented as an anti-pattern for some time.[1] Despite this being generally understood, bmcweb has a long ways to go cleaning these up, and routinely code is submitted in violation of this anti-pattern. Invent an ast-grep rule that can identify when new examples of this anti-pattern are added, and ignore the existing 200+ examples that are in the codebase already using ast-grep ignore. These flags will give us something to search for as we clean this up, and will help to prevent new instances from being added unintentionally. [1] https://github.com/openbmc/docs/blob/master/anti-patterns.md#very-long-lambda-callbacks Tested: Comment only change. ast-grep passes. Manually removing an ast-grep ignore flag shows as a failure in ast-grep scan Change-Id: I77d634a393884969f184d2c39c02cc08288d5a29 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-15sdbusplus: use shorter type aliasesPatrick Williams1-8/+6
The sdbusplus headers provide shortened aliases for many types. Switch to using them to provide better code clarity and shorter lines. Possible replacements are for: * bus_t * exception_t * manager_t * match_t * message_t * object_t * slot_t * object_path Change-Id: Iace20f9ad26e8d9dc234979e7a4087d599da2641 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2026-02-25Add FanSpeedsPercent for EnvironmentMetricsGeorge Liu1-4/+62
Adds FanSpeedsPercent information according to the Redfish EnvironmentMetrics schema [1]. The schema only allows fans of ReadingType Percent to be included in the FanSpeedsPercent array. The Redfish Uri supports retrieval of the metrics for a specific chassis: ``` /redfish/v1/Chassis/<chassisId>/EnvironmentMetrics ``` The fan sensors connected to the chassis are found by: 1) Find all fans associated to the chassis using the 'cooled_by' endpoint. [3]. 2) Find all sensors associated to each fan using the 'sensors' endpoint. [4] 3) Retrieve the sensor excerpt data for each sensor. A similar approach to retrieving the sensor data is used here as for the proposed implementation for ThermalSubsystem/Fans [2]. [1] https://redfish.dmtf.org/schemas/v1/EnvironmentMetrics.v1_3_2.json [2] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/57657 [3] https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/58300 [4] https://github.com/openbmc/docs/blob/master/architecture/sensor-architecture.md#association-type-2-linking-a-low-level-hardware-item-to-its-sensors Implementation notes: - The utility function objectExcerptToJson() is used to populate the SensorFanArrayExcerpt. - Altered the objectExcerptToJson() function to take a sensor::ReadingType value for the optional expected sensor type. Tested: (using hardware simulator) - Redfish Validator passes. - With redfish-allow-rotational-fans disabled: (Note fans that percent cannot be computed have null for Reading property.) ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics", "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics", "FanSpeedsPercent": [ { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "Reading": 100, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_1", "Reading": 60, "SpeedRPM": 12036.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_0", "Reading": 50, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_1", "Reading": 32, "SpeedRPM": 12036.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_0", "Reading": 50, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_1", "Reading": 25, "SpeedRPM": 12036.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_0", "Reading": null, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_1", "Reading": null, "SpeedRPM": 12036.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_0", "Reading": null, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_1", "Reading": null, "SpeedRPM": 12036.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan5_0", "Reading": null, "SpeedRPM": 18000.0 }, { "DataSourceUri": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan5_1", "Reading": null, "SpeedRPM": 12036.0 } ], "FanSpeedsPercent@odata.count": 12, "Id": "EnvironmentMetrics", "Name": "Chassis Environment Metrics" } ``` - Can see DataSourceUri match Sensors fan paths of ReadingType Percent: ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors | grep fan "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_1" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan1_1" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan2_1" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan3_1" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan4_1" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan5_0" "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan5_1" // E.g. curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan0_0", ... "ReadingType": "Percent", ... ``` - With redfish-allow-rotational-fans enabled the only fans are not Percent ReadingType so are not added to the FanSpeedsPercent array : ``` curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/EnvironmentMetrics { "@odata.id": "/redfish/v1/Chassis/chassis/EnvironmentMetrics", "@odata.type": "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics", "FanSpeedsPercent": [], "FanSpeedsPercent@odata.count": 0, "Id": "EnvironmentMetrics", "Name": "Chassis Environment Metrics" } // E.g. curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0 { "@odata.id": "/redfish/v1/Chassis/chassis/Sensors/fantach_fan0_0", "@odata.type": "#Sensor.v1_11_1.Sensor", "Id": "fantach_fan0_0", ... "ReadingType": "Rotational", ... ``` Signed-off-by: George Liu <liuxiwei@inspur.com> Signed-off-by: Janet Adkins <janeta@us.ibm.com> Change-Id: I4cfc0aa28d68e7e0fa947251363deb6f06e36225
2025-12-03Fans: Create utility class for fansJanet Adkins1-0/+60
Support for fans from separate routes of ThermalSubsystem and EnvironmentMetrics will need the same utility functions. By moving these shared functions into single file will help with build time by not needing to included full fan support in all of the related locations. Initially only the getFanPaths() is moved. Expectation is more functions will be added as the expanded support is added. Tested: - Compiles - Verified ThermalSubsystem/Fans output unchanged Change-Id: I22c22bdf38155e93aa13e259dd8c904a977f8a07 Signed-off-by: Janet Adkins <janeta@us.ibm.com>