Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // Copyright (c) 2018 Ampere Computing LLC |
| 4 | / |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | */ |
| 17 | #pragma once |
| 18 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 19 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 20 | #include "dbus_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "query.hpp" |
| 22 | #include "registries/privilege_registry.hpp" |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 23 | #include "sensors.hpp" |
Zhenwei Chen | 0d7702c | 2022-07-12 16:42:08 +0000 | [diff] [blame] | 24 | #include "utils/chassis_utils.hpp" |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 25 | |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 26 | #include <sdbusplus/asio/property.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 27 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 28 | #include <array> |
| 29 | #include <string_view> |
| 30 | |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 31 | namespace redfish |
| 32 | { |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 33 | inline void setPowerCapOverride( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 34 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
| 35 | std::vector<nlohmann::json>& powerControlCollections) |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 36 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 37 | auto getChassisPath = |
| 38 | [sensorsAsyncResp, powerControlCollections]( |
| 39 | const std::optional<std::string>& chassisPath) mutable { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 40 | if (!chassisPath) |
| 41 | { |
Gunnar Mills | a7405d5 | 2023-02-22 13:23:23 -0600 | [diff] [blame] | 42 | BMCWEB_LOG_WARNING << "Don't find valid chassis path "; |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 43 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 44 | "Chassis", sensorsAsyncResp->chassisId); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | if (powerControlCollections.size() != 1) |
| 49 | { |
Gunnar Mills | a7405d5 | 2023-02-22 13:23:23 -0600 | [diff] [blame] | 50 | BMCWEB_LOG_WARNING << "Don't support multiple hosts at present "; |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 51 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 52 | "Power", "PowerControl"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | auto& item = powerControlCollections[0]; |
| 57 | |
| 58 | std::optional<nlohmann::json> powerLimit; |
| 59 | if (!json_util::readJson(item, sensorsAsyncResp->asyncResp->res, |
| 60 | "PowerLimit", powerLimit)) |
| 61 | { |
| 62 | return; |
| 63 | } |
| 64 | if (!powerLimit) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | std::optional<uint32_t> value; |
| 69 | if (!json_util::readJson(*powerLimit, sensorsAsyncResp->asyncResp->res, |
| 70 | "LimitInWatts", value)) |
| 71 | { |
| 72 | return; |
| 73 | } |
| 74 | if (!value) |
| 75 | { |
| 76 | return; |
| 77 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 78 | sdbusplus::asio::getProperty<bool>( |
| 79 | *crow::connections::systemBus, "xyz.openbmc_project.Settings", |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 80 | "/xyz/openbmc_project/control/host0/power_cap", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 81 | "xyz.openbmc_project.Control.Power.Cap", "PowerCapEnable", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 82 | [value, sensorsAsyncResp](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 83 | bool powerCapEnable) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 84 | if (ec) |
| 85 | { |
| 86 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
| 87 | BMCWEB_LOG_ERROR << "powerCapEnable Get handler: Dbus error " |
| 88 | << ec; |
| 89 | return; |
| 90 | } |
| 91 | if (!powerCapEnable) |
| 92 | { |
| 93 | messages::actionNotSupported( |
| 94 | sensorsAsyncResp->asyncResp->res, |
| 95 | "Setting LimitInWatts when PowerLimit feature is disabled"); |
| 96 | BMCWEB_LOG_ERROR << "PowerLimit feature is disabled "; |
| 97 | return; |
| 98 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 99 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 100 | sdbusplus::asio::setProperty( |
| 101 | *crow::connections::systemBus, "xyz.openbmc_project.Settings", |
| 102 | "/xyz/openbmc_project/control/host0/power_cap", |
| 103 | "xyz.openbmc_project.Control.Power.Cap", "PowerCap", *value, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 104 | [sensorsAsyncResp](const boost::system::error_code& ec2) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 105 | if (ec2) |
| 106 | { |
| 107 | BMCWEB_LOG_DEBUG << "Power Limit Set: Dbus error: " << ec2; |
| 108 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
| 109 | return; |
| 110 | } |
| 111 | sensorsAsyncResp->asyncResp->res.result( |
| 112 | boost::beast::http::status::no_content); |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 113 | }); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 114 | }); |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 115 | }; |
Zhenwei Chen | 0d7702c | 2022-07-12 16:42:08 +0000 | [diff] [blame] | 116 | redfish::chassis_utils::getValidChassisPath(sensorsAsyncResp->asyncResp, |
| 117 | sensorsAsyncResp->chassisId, |
| 118 | std::move(getChassisPath)); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 119 | } |
| 120 | inline void requestRoutesPower(App& app) |
| 121 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 122 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 123 | .privileges(redfish::privileges::getPower) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 124 | .methods(boost::beast::http::verb::get)( |
| 125 | [&app](const crow::Request& req, |
| 126 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 127 | const std::string& chassisName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 128 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 129 | { |
| 130 | return; |
| 131 | } |
| 132 | asyncResp->res.jsonValue["PowerControl"] = nlohmann::json::array(); |
| 133 | |
| 134 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 135 | asyncResp, chassisName, sensors::dbus::powerPaths, |
| 136 | sensors::node::power); |
| 137 | |
| 138 | getChassisData(sensorAsyncResp); |
| 139 | |
| 140 | // This callback verifies that the power limit is only provided |
| 141 | // for the chassis that implements the Chassis inventory item. |
| 142 | // This prevents things like power supplies providing the |
| 143 | // chassis power limit |
| 144 | |
| 145 | using Mapper = dbus::utility::MapperGetSubTreePathsResponse; |
| 146 | auto chassisHandler = |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 147 | [sensorAsyncResp](const boost::system::error_code& e, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 148 | const Mapper& chassisPaths) { |
| 149 | if (e) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 150 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 151 | BMCWEB_LOG_ERROR |
| 152 | << "Power Limit GetSubTreePaths handler Dbus error " << e; |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 153 | return; |
| 154 | } |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 155 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 156 | bool found = false; |
| 157 | for (const std::string& chassis : chassisPaths) |
| 158 | { |
| 159 | size_t len = std::string::npos; |
| 160 | size_t lastPos = chassis.rfind('/'); |
| 161 | if (lastPos == std::string::npos) |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 162 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 163 | continue; |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 166 | if (lastPos == chassis.size() - 1) |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 167 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 168 | size_t end = lastPos; |
| 169 | lastPos = chassis.rfind('/', lastPos - 1); |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 170 | if (lastPos == std::string::npos) |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 171 | { |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 172 | continue; |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 175 | len = end - (lastPos + 1); |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 176 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 177 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 178 | std::string interfaceChassisName = chassis.substr(lastPos + 1, |
| 179 | len); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 180 | if (interfaceChassisName == sensorAsyncResp->chassisId) |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 181 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 182 | found = true; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (!found) |
| 188 | { |
| 189 | BMCWEB_LOG_DEBUG << "Power Limit not present for " |
| 190 | << sensorAsyncResp->chassisId; |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | auto valueHandler = |
| 195 | [sensorAsyncResp]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 196 | const boost::system::error_code& ec, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 197 | const dbus::utility::DBusPropertiesMap& properties) { |
| 198 | if (ec) |
| 199 | { |
| 200 | messages::internalError(sensorAsyncResp->asyncResp->res); |
| 201 | BMCWEB_LOG_ERROR |
| 202 | << "Power Limit GetAll handler: Dbus error " << ec; |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 206 | nlohmann::json& tempArray = |
| 207 | sensorAsyncResp->asyncResp->res.jsonValue["PowerControl"]; |
| 208 | |
| 209 | // Put multiple "sensors" into a single PowerControl, 0, |
| 210 | // so only create the first one |
| 211 | if (tempArray.empty()) |
| 212 | { |
| 213 | // Mandatory properties odata.id and MemberId |
| 214 | // A warning without a odata.type |
| 215 | nlohmann::json::object_t powerControl; |
| 216 | powerControl["@odata.type"] = "#Power.v1_0_0.PowerControl"; |
| 217 | powerControl["@odata.id"] = "/redfish/v1/Chassis/" + |
| 218 | sensorAsyncResp->chassisId + |
| 219 | "/Power#/PowerControl/0"; |
| 220 | powerControl["Name"] = "Chassis Power Control"; |
| 221 | powerControl["MemberId"] = "0"; |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 222 | tempArray.emplace_back(std::move(powerControl)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | nlohmann::json& sensorJson = tempArray.back(); |
| 226 | bool enabled = false; |
| 227 | double powerCap = 0.0; |
| 228 | int64_t scale = 0; |
| 229 | |
| 230 | for (const std::pair<std::string, |
| 231 | dbus::utility::DbusVariantType>& property : |
| 232 | properties) |
| 233 | { |
| 234 | if (property.first == "Scale") |
| 235 | { |
| 236 | const int64_t* i = |
| 237 | std::get_if<int64_t>(&property.second); |
| 238 | |
| 239 | if (i != nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 240 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 241 | scale = *i; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 242 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 243 | } |
| 244 | else if (property.first == "PowerCap") |
| 245 | { |
| 246 | const double* d = std::get_if<double>(&property.second); |
| 247 | const int64_t* i = |
| 248 | std::get_if<int64_t>(&property.second); |
| 249 | const uint32_t* u = |
| 250 | std::get_if<uint32_t>(&property.second); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 251 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 252 | if (d != nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 253 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 254 | powerCap = *d; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 255 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 256 | else if (i != nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 257 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 258 | powerCap = static_cast<double>(*i); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 259 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 260 | else if (u != nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 261 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 262 | powerCap = *u; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 263 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 264 | } |
| 265 | else if (property.first == "PowerCapEnable") |
| 266 | { |
| 267 | const bool* b = std::get_if<bool>(&property.second); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 268 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 269 | if (b != nullptr) |
| 270 | { |
| 271 | enabled = *b; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 276 | // LimitException is Mandatory attribute as per OCP |
| 277 | // Baseline Profile – v1.0.0, so currently making it |
| 278 | // "NoAction" as default value to make it OCP Compliant. |
| 279 | sensorJson["PowerLimit"]["LimitException"] = "NoAction"; |
| 280 | |
| 281 | if (enabled) |
| 282 | { |
| 283 | // Redfish specification indicates PowerLimit should |
| 284 | // be null if the limit is not enabled. |
George Liu | d4413c5 | 2023-01-28 09:27:19 +0800 | [diff] [blame] | 285 | sensorJson["PowerLimit"]["LimitInWatts"] = |
| 286 | powerCap * std::pow(10, scale); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 287 | } |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 288 | }; |
| 289 | |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 290 | sdbusplus::asio::getAllProperties( |
| 291 | *crow::connections::systemBus, "xyz.openbmc_project.Settings", |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 292 | "/xyz/openbmc_project/control/host0/power_cap", |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 293 | "xyz.openbmc_project.Control.Power.Cap", |
| 294 | std::move(valueHandler)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 297 | constexpr std::array<std::string_view, 2> interfaces = { |
| 298 | "xyz.openbmc_project.Inventory.Item.Board", |
| 299 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 300 | |
| 301 | dbus::utility::getSubTreePaths("/xyz/openbmc_project/inventory", 0, |
| 302 | interfaces, std::move(chassisHandler)); |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 303 | }); |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 304 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 305 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 306 | .privileges(redfish::privileges::patchPower) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 307 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 308 | [&app](const crow::Request& req, |
| 309 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 310 | const std::string& chassisName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 311 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 312 | { |
| 313 | return; |
| 314 | } |
| 315 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 316 | asyncResp, chassisName, sensors::dbus::powerPaths, |
| 317 | sensors::node::power); |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 318 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 319 | std::optional<std::vector<nlohmann::json>> voltageCollections; |
| 320 | std::optional<std::vector<nlohmann::json>> powerCtlCollections; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 321 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 322 | if (!json_util::readJsonPatch(req, sensorAsyncResp->asyncResp->res, |
| 323 | "PowerControl", powerCtlCollections, |
| 324 | "Voltages", voltageCollections)) |
| 325 | { |
| 326 | return; |
| 327 | } |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 328 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 329 | if (powerCtlCollections) |
| 330 | { |
| 331 | setPowerCapOverride(sensorAsyncResp, *powerCtlCollections); |
| 332 | } |
| 333 | if (voltageCollections) |
| 334 | { |
| 335 | std::unordered_map<std::string, std::vector<nlohmann::json>> |
| 336 | allCollections; |
| 337 | allCollections.emplace("Voltages", *std::move(voltageCollections)); |
| 338 | setSensorsOverride(sensorAsyncResp, allCollections); |
| 339 | } |
| 340 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 341 | } |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 342 | |
| 343 | } // namespace redfish |