Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 19 | #include "node.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 20 | #include "redfish_util.hpp" |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 21 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 22 | #include <boost/algorithm/string/replace.hpp> |
Santosh Puranik | af5d6058 | 2019-03-20 18:16:36 +0530 | [diff] [blame] | 23 | #include <boost/date_time.hpp> |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 24 | #include <dbus_utility.hpp> |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 25 | #include <memory> |
Santosh Puranik | af5d6058 | 2019-03-20 18:16:36 +0530 | [diff] [blame] | 26 | #include <sstream> |
Andrew Geissler | e90c505 | 2019-06-28 13:52:27 -0500 | [diff] [blame] | 27 | #include <utils/fw_utils.hpp> |
Bernard Wong | 7bffdb7 | 2019-03-20 16:17:21 +0800 | [diff] [blame] | 28 | #include <utils/systemd_utils.hpp> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 29 | #include <variant> |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 30 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 31 | namespace redfish |
| 32 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * ManagerActionsReset class supports handle POST method for Reset action. |
| 36 | * The class retrieves and sends data directly to dbus. |
| 37 | */ |
| 38 | class ManagerActionsReset : public Node |
| 39 | { |
| 40 | public: |
| 41 | ManagerActionsReset(CrowApp& app) : |
| 42 | Node(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") |
| 43 | { |
| 44 | entityPrivileges = { |
| 45 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 46 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 47 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 48 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 49 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 50 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | /** |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 55 | * Function handles POST method request. |
| 56 | * Analyzes POST body message before sends Reset request data to dbus. |
| 57 | * OpenBMC allows for ResetType is GracefulRestart only. |
| 58 | */ |
| 59 | void doPost(crow::Response& res, const crow::Request& req, |
| 60 | const std::vector<std::string>& params) override |
| 61 | { |
| 62 | std::string resetType; |
| 63 | |
| 64 | if (!json_util::readJson(req, res, "ResetType", resetType)) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | if (resetType != "GracefulRestart") |
| 70 | { |
| 71 | res.result(boost::beast::http::status::bad_request); |
| 72 | messages::actionParameterNotSupported(res, resetType, "ResetType"); |
| 73 | BMCWEB_LOG_ERROR << "Request incorrect action parameter: " |
| 74 | << resetType; |
| 75 | res.end(); |
| 76 | return; |
| 77 | } |
| 78 | doBMCGracefulRestart(res, req, params); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Function transceives data with dbus directly. |
| 83 | * All BMC state properties will be retrieved before sending reset request. |
| 84 | */ |
| 85 | void doBMCGracefulRestart(crow::Response& res, const crow::Request& req, |
| 86 | const std::vector<std::string>& params) |
| 87 | { |
| 88 | const char* processName = "xyz.openbmc_project.State.BMC"; |
| 89 | const char* objectPath = "/xyz/openbmc_project/state/bmc0"; |
| 90 | const char* interfaceName = "xyz.openbmc_project.State.BMC"; |
| 91 | const std::string& propertyValue = |
| 92 | "xyz.openbmc_project.State.BMC.Transition.Reboot"; |
| 93 | const char* destProperty = "RequestedBMCTransition"; |
| 94 | |
| 95 | // Create the D-Bus variant for D-Bus call. |
| 96 | VariantType dbusPropertyValue(propertyValue); |
| 97 | |
| 98 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
| 99 | |
| 100 | crow::connections::systemBus->async_method_call( |
| 101 | [asyncResp](const boost::system::error_code ec) { |
| 102 | // Use "Set" method to set the property value. |
| 103 | if (ec) |
| 104 | { |
| 105 | BMCWEB_LOG_ERROR << "[Set] Bad D-Bus request error: " << ec; |
| 106 | messages::internalError(asyncResp->res); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | messages::success(asyncResp->res); |
| 111 | }, |
| 112 | processName, objectPath, "org.freedesktop.DBus.Properties", "Set", |
| 113 | interfaceName, destProperty, dbusPropertyValue); |
| 114 | } |
| 115 | }; |
| 116 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 117 | static constexpr const char* objectManagerIface = |
| 118 | "org.freedesktop.DBus.ObjectManager"; |
| 119 | static constexpr const char* pidConfigurationIface = |
| 120 | "xyz.openbmc_project.Configuration.Pid"; |
| 121 | static constexpr const char* pidZoneConfigurationIface = |
| 122 | "xyz.openbmc_project.Configuration.Pid.Zone"; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 123 | static constexpr const char* stepwiseConfigurationIface = |
| 124 | "xyz.openbmc_project.Configuration.Stepwise"; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 125 | static constexpr const char* thermalModeIface = |
| 126 | "xyz.openbmc_project.Control.ThermalMode"; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 127 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 128 | static void asyncPopulatePid(const std::string& connection, |
| 129 | const std::string& path, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 130 | const std::string& currentProfile, |
| 131 | const std::vector<std::string>& supportedProfiles, |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 132 | std::shared_ptr<AsyncResp> asyncResp) |
| 133 | { |
| 134 | |
| 135 | crow::connections::systemBus->async_method_call( |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 136 | [asyncResp, currentProfile, supportedProfiles]( |
| 137 | const boost::system::error_code ec, |
| 138 | const dbus::utility::ManagedObjectType& managedObj) { |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 139 | if (ec) |
| 140 | { |
| 141 | BMCWEB_LOG_ERROR << ec; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 142 | asyncResp->res.jsonValue.clear(); |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 143 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | nlohmann::json& configRoot = |
| 147 | asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; |
| 148 | nlohmann::json& fans = configRoot["FanControllers"]; |
| 149 | fans["@odata.type"] = "#OemManager.FanControllers"; |
| 150 | fans["@odata.context"] = |
| 151 | "/redfish/v1/$metadata#OemManager.FanControllers"; |
| 152 | fans["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/" |
| 153 | "Fan/FanControllers"; |
| 154 | |
| 155 | nlohmann::json& pids = configRoot["PidControllers"]; |
| 156 | pids["@odata.type"] = "#OemManager.PidControllers"; |
| 157 | pids["@odata.context"] = |
| 158 | "/redfish/v1/$metadata#OemManager.PidControllers"; |
| 159 | pids["@odata.id"] = |
| 160 | "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; |
| 161 | |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 162 | nlohmann::json& stepwise = configRoot["StepwiseControllers"]; |
| 163 | stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; |
| 164 | stepwise["@odata.context"] = |
| 165 | "/redfish/v1/$metadata#OemManager.StepwiseControllers"; |
| 166 | stepwise["@odata.id"] = |
| 167 | "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; |
| 168 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 169 | nlohmann::json& zones = configRoot["FanZones"]; |
| 170 | zones["@odata.id"] = |
| 171 | "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; |
| 172 | zones["@odata.type"] = "#OemManager.FanZones"; |
| 173 | zones["@odata.context"] = |
| 174 | "/redfish/v1/$metadata#OemManager.FanZones"; |
| 175 | configRoot["@odata.id"] = |
| 176 | "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; |
| 177 | configRoot["@odata.type"] = "#OemManager.Fan"; |
| 178 | configRoot["@odata.context"] = |
| 179 | "/redfish/v1/$metadata#OemManager.Fan"; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 180 | configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; |
| 181 | |
| 182 | if (!currentProfile.empty()) |
| 183 | { |
| 184 | configRoot["Profile"] = currentProfile; |
| 185 | } |
| 186 | BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 187 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 188 | for (const auto& pathPair : managedObj) |
| 189 | { |
| 190 | for (const auto& intfPair : pathPair.second) |
| 191 | { |
| 192 | if (intfPair.first != pidConfigurationIface && |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 193 | intfPair.first != pidZoneConfigurationIface && |
| 194 | intfPair.first != stepwiseConfigurationIface) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 195 | { |
| 196 | continue; |
| 197 | } |
| 198 | auto findName = intfPair.second.find("Name"); |
| 199 | if (findName == intfPair.second.end()) |
| 200 | { |
| 201 | BMCWEB_LOG_ERROR << "Pid Field missing Name"; |
Jason M. Bills | a08b46c | 2018-11-06 15:01:08 -0800 | [diff] [blame] | 202 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 203 | return; |
| 204 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 205 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 206 | const std::string* namePtr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 207 | std::get_if<std::string>(&findName->second); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 208 | if (namePtr == nullptr) |
| 209 | { |
| 210 | BMCWEB_LOG_ERROR << "Pid Name Field illegal"; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 211 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 212 | return; |
| 213 | } |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 214 | std::string name = *namePtr; |
| 215 | dbus::utility::escapePathForDbus(name); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 216 | |
| 217 | auto findProfiles = intfPair.second.find("Profiles"); |
| 218 | if (findProfiles != intfPair.second.end()) |
| 219 | { |
| 220 | const std::vector<std::string>* profiles = |
| 221 | std::get_if<std::vector<std::string>>( |
| 222 | &findProfiles->second); |
| 223 | if (profiles == nullptr) |
| 224 | { |
| 225 | BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; |
| 226 | messages::internalError(asyncResp->res); |
| 227 | return; |
| 228 | } |
| 229 | if (std::find(profiles->begin(), profiles->end(), |
| 230 | currentProfile) == profiles->end()) |
| 231 | { |
| 232 | BMCWEB_LOG_INFO |
| 233 | << name << " not supported in current profile"; |
| 234 | continue; |
| 235 | } |
| 236 | } |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 237 | nlohmann::json* config = nullptr; |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 238 | |
| 239 | const std::string* classPtr = nullptr; |
| 240 | auto findClass = intfPair.second.find("Class"); |
| 241 | if (findClass != intfPair.second.end()) |
| 242 | { |
| 243 | classPtr = std::get_if<std::string>(&findClass->second); |
| 244 | } |
| 245 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 246 | if (intfPair.first == pidZoneConfigurationIface) |
| 247 | { |
| 248 | std::string chassis; |
| 249 | if (!dbus::utility::getNthStringFromPath( |
| 250 | pathPair.first.str, 5, chassis)) |
| 251 | { |
| 252 | chassis = "#IllegalValue"; |
| 253 | } |
| 254 | nlohmann::json& zone = zones[name]; |
| 255 | zone["Chassis"] = { |
| 256 | {"@odata.id", "/redfish/v1/Chassis/" + chassis}}; |
| 257 | zone["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/" |
| 258 | "OpenBmc/Fan/FanZones/" + |
| 259 | name; |
| 260 | zone["@odata.type"] = "#OemManager.FanZone"; |
| 261 | zone["@odata.context"] = |
| 262 | "/redfish/v1/$metadata#OemManager.FanZone"; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 263 | config = &zone; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 264 | } |
| 265 | |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 266 | else if (intfPair.first == stepwiseConfigurationIface) |
| 267 | { |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 268 | if (classPtr == nullptr) |
| 269 | { |
| 270 | BMCWEB_LOG_ERROR << "Pid Class Field illegal"; |
| 271 | messages::internalError(asyncResp->res); |
| 272 | return; |
| 273 | } |
| 274 | |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 275 | nlohmann::json& controller = stepwise[name]; |
| 276 | config = &controller; |
| 277 | |
| 278 | controller["@odata.id"] = |
| 279 | "/redfish/v1/Managers/bmc#/Oem/" |
| 280 | "OpenBmc/Fan/StepwiseControllers/" + |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 281 | name; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 282 | controller["@odata.type"] = |
| 283 | "#OemManager.StepwiseController"; |
| 284 | |
| 285 | controller["@odata.context"] = |
| 286 | "/redfish/v1/" |
| 287 | "$metadata#OemManager.StepwiseController"; |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 288 | controller["Direction"] = *classPtr; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // pid and fans are off the same configuration |
| 292 | else if (intfPair.first == pidConfigurationIface) |
| 293 | { |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 294 | |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 295 | if (classPtr == nullptr) |
| 296 | { |
| 297 | BMCWEB_LOG_ERROR << "Pid Class Field illegal"; |
| 298 | messages::internalError(asyncResp->res); |
| 299 | return; |
| 300 | } |
| 301 | bool isFan = *classPtr == "fan"; |
| 302 | nlohmann::json& element = |
| 303 | isFan ? fans[name] : pids[name]; |
| 304 | config = &element; |
| 305 | if (isFan) |
| 306 | { |
| 307 | element["@odata.id"] = |
| 308 | "/redfish/v1/Managers/bmc#/Oem/" |
| 309 | "OpenBmc/Fan/FanControllers/" + |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 310 | name; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 311 | element["@odata.type"] = |
| 312 | "#OemManager.FanController"; |
| 313 | |
| 314 | element["@odata.context"] = |
| 315 | "/redfish/v1/" |
| 316 | "$metadata#OemManager.FanController"; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | element["@odata.id"] = |
| 321 | "/redfish/v1/Managers/bmc#/Oem/" |
| 322 | "OpenBmc/Fan/PidControllers/" + |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 323 | name; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 324 | element["@odata.type"] = |
| 325 | "#OemManager.PidController"; |
| 326 | element["@odata.context"] = |
| 327 | "/redfish/v1/$metadata" |
| 328 | "#OemManager.PidController"; |
| 329 | } |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | BMCWEB_LOG_ERROR << "Unexpected configuration"; |
| 334 | messages::internalError(asyncResp->res); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | // used for making maps out of 2 vectors |
| 339 | const std::vector<double>* keys = nullptr; |
| 340 | const std::vector<double>* values = nullptr; |
| 341 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 342 | for (const auto& propertyPair : intfPair.second) |
| 343 | { |
| 344 | if (propertyPair.first == "Type" || |
| 345 | propertyPair.first == "Class" || |
| 346 | propertyPair.first == "Name") |
| 347 | { |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | // zones |
| 352 | if (intfPair.first == pidZoneConfigurationIface) |
| 353 | { |
Ed Tanous | 1b6b96c | 2018-11-30 11:35:41 -0800 | [diff] [blame] | 354 | const double* ptr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 355 | std::get_if<double>(&propertyPair.second); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 356 | if (ptr == nullptr) |
| 357 | { |
| 358 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 359 | << propertyPair.first; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 360 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 361 | return; |
| 362 | } |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 363 | (*config)[propertyPair.first] = *ptr; |
| 364 | } |
| 365 | |
| 366 | if (intfPair.first == stepwiseConfigurationIface) |
| 367 | { |
| 368 | if (propertyPair.first == "Reading" || |
| 369 | propertyPair.first == "Output") |
| 370 | { |
| 371 | const std::vector<double>* ptr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 372 | std::get_if<std::vector<double>>( |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 373 | &propertyPair.second); |
| 374 | |
| 375 | if (ptr == nullptr) |
| 376 | { |
| 377 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 378 | << propertyPair.first; |
| 379 | messages::internalError(asyncResp->res); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | if (propertyPair.first == "Reading") |
| 384 | { |
| 385 | keys = ptr; |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | values = ptr; |
| 390 | } |
| 391 | if (keys && values) |
| 392 | { |
| 393 | if (keys->size() != values->size()) |
| 394 | { |
| 395 | BMCWEB_LOG_ERROR |
| 396 | << "Reading and Output size don't " |
| 397 | "match "; |
| 398 | messages::internalError(asyncResp->res); |
| 399 | return; |
| 400 | } |
| 401 | nlohmann::json& steps = (*config)["Steps"]; |
| 402 | steps = nlohmann::json::array(); |
| 403 | for (size_t ii = 0; ii < keys->size(); ii++) |
| 404 | { |
| 405 | steps.push_back( |
| 406 | {{"Target", (*keys)[ii]}, |
| 407 | {"Output", (*values)[ii]}}); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | if (propertyPair.first == "NegativeHysteresis" || |
| 412 | propertyPair.first == "PositiveHysteresis") |
| 413 | { |
| 414 | const double* ptr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 415 | std::get_if<double>(&propertyPair.second); |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 416 | if (ptr == nullptr) |
| 417 | { |
| 418 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 419 | << propertyPair.first; |
| 420 | messages::internalError(asyncResp->res); |
| 421 | return; |
| 422 | } |
| 423 | (*config)[propertyPair.first] = *ptr; |
| 424 | } |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | // pid and fans are off the same configuration |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 428 | if (intfPair.first == pidConfigurationIface || |
| 429 | intfPair.first == stepwiseConfigurationIface) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 430 | { |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 431 | |
| 432 | if (propertyPair.first == "Zones") |
| 433 | { |
| 434 | const std::vector<std::string>* inputs = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 435 | std::get_if<std::vector<std::string>>( |
Ed Tanous | 1b6b96c | 2018-11-30 11:35:41 -0800 | [diff] [blame] | 436 | &propertyPair.second); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 437 | |
| 438 | if (inputs == nullptr) |
| 439 | { |
| 440 | BMCWEB_LOG_ERROR |
| 441 | << "Zones Pid Field Illegal"; |
Jason M. Bills | a08b46c | 2018-11-06 15:01:08 -0800 | [diff] [blame] | 442 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 443 | return; |
| 444 | } |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 445 | auto& data = (*config)[propertyPair.first]; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 446 | data = nlohmann::json::array(); |
| 447 | for (std::string itemCopy : *inputs) |
| 448 | { |
| 449 | dbus::utility::escapePathForDbus(itemCopy); |
| 450 | data.push_back( |
| 451 | {{"@odata.id", |
| 452 | "/redfish/v1/Managers/bmc#/Oem/" |
| 453 | "OpenBmc/Fan/FanZones/" + |
| 454 | itemCopy}}); |
| 455 | } |
| 456 | } |
| 457 | // todo(james): may never happen, but this |
| 458 | // assumes configuration data referenced in the |
| 459 | // PID config is provided by the same daemon, we |
| 460 | // could add another loop to cover all cases, |
| 461 | // but I'm okay kicking this can down the road a |
| 462 | // bit |
| 463 | |
| 464 | else if (propertyPair.first == "Inputs" || |
| 465 | propertyPair.first == "Outputs") |
| 466 | { |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 467 | auto& data = (*config)[propertyPair.first]; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 468 | const std::vector<std::string>* inputs = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 469 | std::get_if<std::vector<std::string>>( |
Ed Tanous | 1b6b96c | 2018-11-30 11:35:41 -0800 | [diff] [blame] | 470 | &propertyPair.second); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 471 | |
| 472 | if (inputs == nullptr) |
| 473 | { |
| 474 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 475 | << propertyPair.first; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 476 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | data = *inputs; |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 480 | } |
| 481 | else if (propertyPair.first == "SetPointOffset") |
| 482 | { |
| 483 | const std::string* ptr = |
| 484 | std::get_if<std::string>( |
| 485 | &propertyPair.second); |
| 486 | |
| 487 | if (ptr == nullptr) |
| 488 | { |
| 489 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 490 | << propertyPair.first; |
| 491 | messages::internalError(asyncResp->res); |
| 492 | return; |
| 493 | } |
| 494 | // translate from dbus to redfish |
| 495 | if (*ptr == "WarningHigh") |
| 496 | { |
| 497 | (*config)["SetPointOffset"] = |
| 498 | "UpperThresholdNonCritical"; |
| 499 | } |
| 500 | else if (*ptr == "WarningLow") |
| 501 | { |
| 502 | (*config)["SetPointOffset"] = |
| 503 | "LowerThresholdNonCritical"; |
| 504 | } |
| 505 | else if (*ptr == "CriticalHigh") |
| 506 | { |
| 507 | (*config)["SetPointOffset"] = |
| 508 | "UpperThresholdCritical"; |
| 509 | } |
| 510 | else if (*ptr == "CriticalLow") |
| 511 | { |
| 512 | (*config)["SetPointOffset"] = |
| 513 | "LowerThresholdCritical"; |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | BMCWEB_LOG_ERROR << "Value Illegal " |
| 518 | << *ptr; |
| 519 | messages::internalError(asyncResp->res); |
| 520 | return; |
| 521 | } |
| 522 | } |
| 523 | // doubles |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 524 | else if (propertyPair.first == |
| 525 | "FFGainCoefficient" || |
| 526 | propertyPair.first == "FFOffCoefficient" || |
| 527 | propertyPair.first == "ICoefficient" || |
| 528 | propertyPair.first == "ILimitMax" || |
| 529 | propertyPair.first == "ILimitMin" || |
James Feist | aad1a25 | 2019-02-19 10:13:52 -0800 | [diff] [blame] | 530 | propertyPair.first == |
| 531 | "PositiveHysteresis" || |
| 532 | propertyPair.first == |
| 533 | "NegativeHysteresis" || |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 534 | propertyPair.first == "OutLimitMax" || |
| 535 | propertyPair.first == "OutLimitMin" || |
| 536 | propertyPair.first == "PCoefficient" || |
James Feist | 7625cb8 | 2019-01-23 11:58:21 -0800 | [diff] [blame] | 537 | propertyPair.first == "SetPoint" || |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 538 | propertyPair.first == "SlewNeg" || |
| 539 | propertyPair.first == "SlewPos") |
| 540 | { |
| 541 | const double* ptr = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 542 | std::get_if<double>(&propertyPair.second); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 543 | if (ptr == nullptr) |
| 544 | { |
| 545 | BMCWEB_LOG_ERROR << "Field Illegal " |
| 546 | << propertyPair.first; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 547 | messages::internalError(asyncResp->res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 548 | return; |
| 549 | } |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 550 | (*config)[propertyPair.first] = *ptr; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | }, |
| 557 | connection, path, objectManagerIface, "GetManagedObjects"); |
| 558 | } |
Jennifer Lee | ca53792 | 2018-08-10 10:07:30 -0700 | [diff] [blame] | 559 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 560 | enum class CreatePIDRet |
| 561 | { |
| 562 | fail, |
| 563 | del, |
| 564 | patch |
| 565 | }; |
| 566 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 567 | static bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response, |
| 568 | std::vector<nlohmann::json>& config, |
| 569 | std::vector<std::string>& zones) |
| 570 | { |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 571 | if (config.empty()) |
| 572 | { |
| 573 | BMCWEB_LOG_ERROR << "Empty Zones"; |
| 574 | messages::propertyValueFormatError(response->res, |
| 575 | nlohmann::json::array(), "Zones"); |
| 576 | return false; |
| 577 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 578 | for (auto& odata : config) |
| 579 | { |
| 580 | std::string path; |
| 581 | if (!redfish::json_util::readJson(odata, response->res, "@odata.id", |
| 582 | path)) |
| 583 | { |
| 584 | return false; |
| 585 | } |
| 586 | std::string input; |
James Feist | 61adbda | 2019-03-25 13:03:51 -0700 | [diff] [blame] | 587 | |
| 588 | // 8 below comes from |
| 589 | // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left |
| 590 | // 0 1 2 3 4 5 6 7 8 |
| 591 | if (!dbus::utility::getNthStringFromPath(path, 8, input)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 592 | { |
| 593 | BMCWEB_LOG_ERROR << "Got invalid path " << path; |
| 594 | BMCWEB_LOG_ERROR << "Illegal Type Zones"; |
| 595 | messages::propertyValueFormatError(response->res, odata.dump(), |
| 596 | "Zones"); |
| 597 | return false; |
| 598 | } |
| 599 | boost::replace_all(input, "_", " "); |
| 600 | zones.emplace_back(std::move(input)); |
| 601 | } |
| 602 | return true; |
| 603 | } |
| 604 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 605 | static const dbus::utility::ManagedItem* |
| 606 | findChassis(const dbus::utility::ManagedObjectType& managedObj, |
| 607 | const std::string& value, std::string& chassis) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 608 | { |
| 609 | BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; |
| 610 | |
| 611 | std::string escaped = boost::replace_all_copy(value, " ", "_"); |
| 612 | escaped = "/" + escaped; |
| 613 | auto it = std::find_if( |
| 614 | managedObj.begin(), managedObj.end(), [&escaped](const auto& obj) { |
| 615 | if (boost::algorithm::ends_with(obj.first.str, escaped)) |
| 616 | { |
| 617 | BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; |
| 618 | return true; |
| 619 | } |
| 620 | return false; |
| 621 | }); |
| 622 | |
| 623 | if (it == managedObj.end()) |
| 624 | { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 625 | return nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 626 | } |
| 627 | // 5 comes from <chassis-name> being the 5th element |
| 628 | // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 629 | if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) |
| 630 | { |
| 631 | return &(*it); |
| 632 | } |
| 633 | |
| 634 | return nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 635 | } |
| 636 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 637 | static CreatePIDRet createPidInterface( |
| 638 | const std::shared_ptr<AsyncResp>& response, const std::string& type, |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 639 | nlohmann::json::iterator it, const std::string& path, |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 640 | const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, |
| 641 | boost::container::flat_map<std::string, dbus::utility::DbusVariantType>& |
| 642 | output, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 643 | std::string& chassis, const std::string& profile) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 644 | { |
| 645 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 646 | // common deleter |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 647 | if (it.value() == nullptr) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 648 | { |
| 649 | std::string iface; |
| 650 | if (type == "PidControllers" || type == "FanControllers") |
| 651 | { |
| 652 | iface = pidConfigurationIface; |
| 653 | } |
| 654 | else if (type == "FanZones") |
| 655 | { |
| 656 | iface = pidZoneConfigurationIface; |
| 657 | } |
| 658 | else if (type == "StepwiseControllers") |
| 659 | { |
| 660 | iface = stepwiseConfigurationIface; |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type " |
| 665 | << type; |
| 666 | messages::propertyUnknown(response->res, type); |
| 667 | return CreatePIDRet::fail; |
| 668 | } |
| 669 | // delete interface |
| 670 | crow::connections::systemBus->async_method_call( |
| 671 | [response, path](const boost::system::error_code ec) { |
| 672 | if (ec) |
| 673 | { |
| 674 | BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; |
| 675 | messages::internalError(response->res); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 676 | return; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 677 | } |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 678 | messages::success(response->res); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 679 | }, |
| 680 | "xyz.openbmc_project.EntityManager", path, iface, "Delete"); |
| 681 | return CreatePIDRet::del; |
| 682 | } |
| 683 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 684 | const dbus::utility::ManagedItem* managedItem = nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 685 | if (!createNewObject) |
| 686 | { |
| 687 | // if we aren't creating a new object, we should be able to find it on |
| 688 | // d-bus |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 689 | managedItem = findChassis(managedObj, it.key(), chassis); |
| 690 | if (managedItem == nullptr) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 691 | { |
| 692 | BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; |
| 693 | messages::invalidObject(response->res, it.key()); |
| 694 | return CreatePIDRet::fail; |
| 695 | } |
| 696 | } |
| 697 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 698 | if (profile.size() && |
| 699 | (type == "PidControllers" || type == "FanControllers" || |
| 700 | type == "StepwiseControllers")) |
| 701 | { |
| 702 | if (managedItem == nullptr) |
| 703 | { |
| 704 | output["Profiles"] = std::vector<std::string>{profile}; |
| 705 | } |
| 706 | else |
| 707 | { |
| 708 | std::string interface; |
| 709 | if (type == "StepwiseControllers") |
| 710 | { |
| 711 | interface = stepwiseConfigurationIface; |
| 712 | } |
| 713 | else |
| 714 | { |
| 715 | interface = pidConfigurationIface; |
| 716 | } |
| 717 | auto findConfig = managedItem->second.find(interface); |
| 718 | if (findConfig == managedItem->second.end()) |
| 719 | { |
| 720 | BMCWEB_LOG_ERROR |
| 721 | << "Failed to find interface in managed object"; |
| 722 | messages::internalError(response->res); |
| 723 | return CreatePIDRet::fail; |
| 724 | } |
| 725 | auto findProfiles = findConfig->second.find("Profiles"); |
| 726 | if (findProfiles != findConfig->second.end()) |
| 727 | { |
| 728 | const std::vector<std::string>* curProfiles = |
| 729 | std::get_if<std::vector<std::string>>( |
| 730 | &(findProfiles->second)); |
| 731 | if (curProfiles == nullptr) |
| 732 | { |
| 733 | BMCWEB_LOG_ERROR << "Illegal profiles in managed object"; |
| 734 | messages::internalError(response->res); |
| 735 | return CreatePIDRet::fail; |
| 736 | } |
| 737 | if (std::find(curProfiles->begin(), curProfiles->end(), |
| 738 | profile) == curProfiles->end()) |
| 739 | { |
| 740 | std::vector<std::string> newProfiles = *curProfiles; |
| 741 | newProfiles.push_back(profile); |
| 742 | output["Profiles"] = newProfiles; |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 748 | if (type == "PidControllers" || type == "FanControllers") |
| 749 | { |
| 750 | if (createNewObject) |
| 751 | { |
| 752 | output["Class"] = type == "PidControllers" ? std::string("temp") |
| 753 | : std::string("fan"); |
| 754 | output["Type"] = std::string("Pid"); |
| 755 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 756 | |
| 757 | std::optional<std::vector<nlohmann::json>> zones; |
| 758 | std::optional<std::vector<std::string>> inputs; |
| 759 | std::optional<std::vector<std::string>> outputs; |
| 760 | std::map<std::string, std::optional<double>> doubles; |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 761 | std::optional<std::string> setpointOffset; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 762 | if (!redfish::json_util::readJson( |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 763 | it.value(), response->res, "Inputs", inputs, "Outputs", outputs, |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 764 | "Zones", zones, "FFGainCoefficient", |
| 765 | doubles["FFGainCoefficient"], "FFOffCoefficient", |
| 766 | doubles["FFOffCoefficient"], "ICoefficient", |
| 767 | doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], |
| 768 | "ILimitMin", doubles["ILimitMin"], "OutLimitMax", |
| 769 | doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], |
| 770 | "PCoefficient", doubles["PCoefficient"], "SetPoint", |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 771 | doubles["SetPoint"], "SetPointOffset", setpointOffset, |
| 772 | "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], |
| 773 | "PositiveHysteresis", doubles["PositiveHysteresis"], |
| 774 | "NegativeHysteresis", doubles["NegativeHysteresis"])) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 775 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 776 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 777 | << it.value().dump(); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 778 | return CreatePIDRet::fail; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 779 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 780 | if (zones) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 781 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 782 | std::vector<std::string> zonesStr; |
| 783 | if (!getZonesFromJsonReq(response, *zones, zonesStr)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 784 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 785 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones"; |
| 786 | return CreatePIDRet::fail; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 787 | } |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 788 | if (chassis.empty() && |
| 789 | !findChassis(managedObj, zonesStr[0], chassis)) |
| 790 | { |
| 791 | BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; |
| 792 | messages::invalidObject(response->res, it.key()); |
| 793 | return CreatePIDRet::fail; |
| 794 | } |
| 795 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 796 | output["Zones"] = std::move(zonesStr); |
| 797 | } |
| 798 | if (inputs || outputs) |
| 799 | { |
| 800 | std::array<std::optional<std::vector<std::string>>*, 2> containers = |
| 801 | {&inputs, &outputs}; |
| 802 | size_t index = 0; |
| 803 | for (const auto& containerPtr : containers) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 804 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 805 | std::optional<std::vector<std::string>>& container = |
| 806 | *containerPtr; |
| 807 | if (!container) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 808 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 809 | index++; |
| 810 | continue; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 811 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 812 | |
| 813 | for (std::string& value : *container) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 814 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 815 | boost::replace_all(value, "_", " "); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 816 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 817 | std::string key; |
| 818 | if (index == 0) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 819 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 820 | key = "Inputs"; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 821 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 822 | else |
| 823 | { |
| 824 | key = "Outputs"; |
| 825 | } |
| 826 | output[key] = *container; |
| 827 | index++; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 828 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 829 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 830 | |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 831 | if (setpointOffset) |
| 832 | { |
| 833 | // translate between redfish and dbus names |
| 834 | if (*setpointOffset == "UpperThresholdNonCritical") |
| 835 | { |
| 836 | output["SetPointOffset"] = std::string("WarningLow"); |
| 837 | } |
| 838 | else if (*setpointOffset == "LowerThresholdNonCritical") |
| 839 | { |
| 840 | output["SetPointOffset"] = std::string("WarningHigh"); |
| 841 | } |
| 842 | else if (*setpointOffset == "LowerThresholdCritical") |
| 843 | { |
| 844 | output["SetPointOffset"] = std::string("CriticalLow"); |
| 845 | } |
| 846 | else if (*setpointOffset == "UpperThresholdCritical") |
| 847 | { |
| 848 | output["SetPointOffset"] = std::string("CriticalHigh"); |
| 849 | } |
| 850 | else |
| 851 | { |
| 852 | BMCWEB_LOG_ERROR << "Invalid setpointoffset " |
| 853 | << *setpointOffset; |
| 854 | messages::invalidObject(response->res, it.key()); |
| 855 | return CreatePIDRet::fail; |
| 856 | } |
| 857 | } |
| 858 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 859 | // doubles |
| 860 | for (const auto& pairs : doubles) |
| 861 | { |
| 862 | if (!pairs.second) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 863 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 864 | continue; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 865 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 866 | BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; |
| 867 | output[pairs.first] = *(pairs.second); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 868 | } |
| 869 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 870 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 871 | else if (type == "FanZones") |
| 872 | { |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 873 | output["Type"] = std::string("Pid.Zone"); |
| 874 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 875 | std::optional<nlohmann::json> chassisContainer; |
| 876 | std::optional<double> failSafePercent; |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 877 | std::optional<double> minThermalOutput; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 878 | if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 879 | chassisContainer, "FailSafePercent", |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 880 | failSafePercent, "MinThermalOutput", |
| 881 | minThermalOutput)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 882 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 883 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 884 | << it.value().dump(); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 885 | return CreatePIDRet::fail; |
| 886 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 887 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 888 | if (chassisContainer) |
| 889 | { |
| 890 | |
| 891 | std::string chassisId; |
| 892 | if (!redfish::json_util::readJson(*chassisContainer, response->res, |
| 893 | "@odata.id", chassisId)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 894 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 895 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
| 896 | << chassisContainer->dump(); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 897 | return CreatePIDRet::fail; |
| 898 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 899 | |
AppaRao Puli | 717794d | 2019-10-18 22:54:53 +0530 | [diff] [blame] | 900 | // /redfish/v1/chassis/chassis_name/ |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 901 | if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) |
| 902 | { |
| 903 | BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; |
| 904 | messages::invalidObject(response->res, chassisId); |
| 905 | return CreatePIDRet::fail; |
| 906 | } |
| 907 | } |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 908 | if (minThermalOutput) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 909 | { |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 910 | output["MinThermalOutput"] = *minThermalOutput; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 911 | } |
| 912 | if (failSafePercent) |
| 913 | { |
| 914 | output["FailSafePercent"] = *failSafePercent; |
| 915 | } |
| 916 | } |
| 917 | else if (type == "StepwiseControllers") |
| 918 | { |
| 919 | output["Type"] = std::string("Stepwise"); |
| 920 | |
| 921 | std::optional<std::vector<nlohmann::json>> zones; |
| 922 | std::optional<std::vector<nlohmann::json>> steps; |
| 923 | std::optional<std::vector<std::string>> inputs; |
| 924 | std::optional<double> positiveHysteresis; |
| 925 | std::optional<double> negativeHysteresis; |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 926 | std::optional<std::string> direction; // upper clipping curve vs lower |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 927 | if (!redfish::json_util::readJson( |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 928 | it.value(), response->res, "Zones", zones, "Steps", steps, |
| 929 | "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 930 | "NegativeHysteresis", negativeHysteresis, "Direction", |
| 931 | direction)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 932 | { |
| 933 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 934 | << it.value().dump(); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 935 | return CreatePIDRet::fail; |
| 936 | } |
| 937 | |
| 938 | if (zones) |
| 939 | { |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 940 | std::vector<std::string> zonesStrs; |
| 941 | if (!getZonesFromJsonReq(response, *zones, zonesStrs)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 942 | { |
| 943 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones"; |
| 944 | return CreatePIDRet::fail; |
| 945 | } |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 946 | if (chassis.empty() && |
| 947 | !findChassis(managedObj, zonesStrs[0], chassis)) |
| 948 | { |
| 949 | BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; |
| 950 | messages::invalidObject(response->res, it.key()); |
| 951 | return CreatePIDRet::fail; |
| 952 | } |
| 953 | output["Zones"] = std::move(zonesStrs); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 954 | } |
| 955 | if (steps) |
| 956 | { |
| 957 | std::vector<double> readings; |
| 958 | std::vector<double> outputs; |
| 959 | for (auto& step : *steps) |
| 960 | { |
| 961 | double target; |
Ed Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 962 | double output; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 963 | |
| 964 | if (!redfish::json_util::readJson(step, response->res, "Target", |
Ed Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 965 | target, "Output", output)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 966 | { |
| 967 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 968 | << ", Illegal Property " |
| 969 | << it.value().dump(); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 970 | return CreatePIDRet::fail; |
| 971 | } |
| 972 | readings.emplace_back(target); |
Ed Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 973 | outputs.emplace_back(output); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 974 | } |
| 975 | output["Reading"] = std::move(readings); |
| 976 | output["Output"] = std::move(outputs); |
| 977 | } |
| 978 | if (inputs) |
| 979 | { |
| 980 | for (std::string& value : *inputs) |
| 981 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 982 | boost::replace_all(value, "_", " "); |
| 983 | } |
| 984 | output["Inputs"] = std::move(*inputs); |
| 985 | } |
| 986 | if (negativeHysteresis) |
| 987 | { |
| 988 | output["NegativeHysteresis"] = *negativeHysteresis; |
| 989 | } |
| 990 | if (positiveHysteresis) |
| 991 | { |
| 992 | output["PositiveHysteresis"] = *positiveHysteresis; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 993 | } |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 994 | if (direction) |
| 995 | { |
| 996 | constexpr const std::array<const char*, 2> allowedDirections = { |
| 997 | "Ceiling", "Floor"}; |
| 998 | if (std::find(allowedDirections.begin(), allowedDirections.end(), |
| 999 | *direction) == allowedDirections.end()) |
| 1000 | { |
| 1001 | messages::propertyValueTypeError(response->res, "Direction", |
| 1002 | *direction); |
| 1003 | return CreatePIDRet::fail; |
| 1004 | } |
| 1005 | output["Class"] = *direction; |
| 1006 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1007 | } |
| 1008 | else |
| 1009 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1010 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type " << type; |
Jason M. Bills | 35a62c7 | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1011 | messages::propertyUnknown(response->res, type); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1012 | return CreatePIDRet::fail; |
| 1013 | } |
| 1014 | return CreatePIDRet::patch; |
| 1015 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1016 | struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> |
| 1017 | { |
| 1018 | |
| 1019 | GetPIDValues(const std::shared_ptr<AsyncResp>& asyncResp) : |
| 1020 | asyncResp(asyncResp) |
| 1021 | |
| 1022 | { |
| 1023 | } |
| 1024 | |
| 1025 | void run() |
| 1026 | { |
| 1027 | std::shared_ptr<GetPIDValues> self = shared_from_this(); |
| 1028 | |
| 1029 | // get all configurations |
| 1030 | crow::connections::systemBus->async_method_call( |
| 1031 | [self](const boost::system::error_code ec, |
| 1032 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
| 1033 | if (ec) |
| 1034 | { |
| 1035 | BMCWEB_LOG_ERROR << ec; |
| 1036 | messages::internalError(self->asyncResp->res); |
| 1037 | return; |
| 1038 | } |
| 1039 | self->subtree = subtree; |
| 1040 | }, |
| 1041 | "xyz.openbmc_project.ObjectMapper", |
| 1042 | "/xyz/openbmc_project/object_mapper", |
| 1043 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, |
| 1044 | std::array<const char*, 4>{ |
| 1045 | pidConfigurationIface, pidZoneConfigurationIface, |
| 1046 | objectManagerIface, stepwiseConfigurationIface}); |
| 1047 | |
| 1048 | // at the same time get the selected profile |
| 1049 | crow::connections::systemBus->async_method_call( |
| 1050 | [self](const boost::system::error_code ec, |
| 1051 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
| 1052 | if (ec || subtree.empty()) |
| 1053 | { |
| 1054 | return; |
| 1055 | } |
| 1056 | if (subtree[0].second.size() != 1) |
| 1057 | { |
| 1058 | // invalid mapper response, should never happen |
| 1059 | BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; |
| 1060 | messages::internalError(self->asyncResp->res); |
| 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | const std::string& path = subtree[0].first; |
| 1065 | const std::string& owner = subtree[0].second[0].first; |
| 1066 | crow::connections::systemBus->async_method_call( |
| 1067 | [path, owner, self]( |
| 1068 | const boost::system::error_code ec, |
| 1069 | const boost::container::flat_map< |
| 1070 | std::string, std::variant<std::vector<std::string>, |
| 1071 | std::string>>& resp) { |
| 1072 | if (ec) |
| 1073 | { |
| 1074 | BMCWEB_LOG_ERROR << "GetPIDValues: Can't get " |
| 1075 | "thermalModeIface " |
| 1076 | << path; |
| 1077 | messages::internalError(self->asyncResp->res); |
| 1078 | return; |
| 1079 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1080 | const std::string* current = nullptr; |
| 1081 | const std::vector<std::string>* supported = nullptr; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1082 | for (auto& [key, value] : resp) |
| 1083 | { |
| 1084 | if (key == "Current") |
| 1085 | { |
| 1086 | current = std::get_if<std::string>(&value); |
| 1087 | if (current == nullptr) |
| 1088 | { |
| 1089 | BMCWEB_LOG_ERROR |
| 1090 | << "GetPIDValues: thermal mode " |
| 1091 | "iface invalid " |
| 1092 | << path; |
| 1093 | messages::internalError( |
| 1094 | self->asyncResp->res); |
| 1095 | return; |
| 1096 | } |
| 1097 | } |
| 1098 | if (key == "Supported") |
| 1099 | { |
| 1100 | supported = |
| 1101 | std::get_if<std::vector<std::string>>( |
| 1102 | &value); |
| 1103 | if (supported == nullptr) |
| 1104 | { |
| 1105 | BMCWEB_LOG_ERROR |
| 1106 | << "GetPIDValues: thermal mode " |
| 1107 | "iface invalid" |
| 1108 | << path; |
| 1109 | messages::internalError( |
| 1110 | self->asyncResp->res); |
| 1111 | return; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | if (current == nullptr || supported == nullptr) |
| 1116 | { |
| 1117 | BMCWEB_LOG_ERROR << "GetPIDValues: thermal mode " |
| 1118 | "iface invalid " |
| 1119 | << path; |
| 1120 | messages::internalError(self->asyncResp->res); |
| 1121 | return; |
| 1122 | } |
| 1123 | self->currentProfile = *current; |
| 1124 | self->supportedProfiles = *supported; |
| 1125 | }, |
| 1126 | owner, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 1127 | thermalModeIface); |
| 1128 | }, |
| 1129 | "xyz.openbmc_project.ObjectMapper", |
| 1130 | "/xyz/openbmc_project/object_mapper", |
| 1131 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, |
| 1132 | std::array<const char*, 1>{thermalModeIface}); |
| 1133 | } |
| 1134 | |
| 1135 | ~GetPIDValues() |
| 1136 | { |
| 1137 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1138 | { |
| 1139 | return; |
| 1140 | } |
| 1141 | // create map of <connection, path to objMgr>> |
| 1142 | boost::container::flat_map<std::string, std::string> objectMgrPaths; |
| 1143 | boost::container::flat_set<std::string> calledConnections; |
| 1144 | for (const auto& pathGroup : subtree) |
| 1145 | { |
| 1146 | for (const auto& connectionGroup : pathGroup.second) |
| 1147 | { |
| 1148 | auto findConnection = |
| 1149 | calledConnections.find(connectionGroup.first); |
| 1150 | if (findConnection != calledConnections.end()) |
| 1151 | { |
| 1152 | break; |
| 1153 | } |
| 1154 | for (const std::string& interface : connectionGroup.second) |
| 1155 | { |
| 1156 | if (interface == objectManagerIface) |
| 1157 | { |
| 1158 | objectMgrPaths[connectionGroup.first] = pathGroup.first; |
| 1159 | } |
| 1160 | // this list is alphabetical, so we |
| 1161 | // should have found the objMgr by now |
| 1162 | if (interface == pidConfigurationIface || |
| 1163 | interface == pidZoneConfigurationIface || |
| 1164 | interface == stepwiseConfigurationIface) |
| 1165 | { |
| 1166 | auto findObjMgr = |
| 1167 | objectMgrPaths.find(connectionGroup.first); |
| 1168 | if (findObjMgr == objectMgrPaths.end()) |
| 1169 | { |
| 1170 | BMCWEB_LOG_DEBUG << connectionGroup.first |
| 1171 | << "Has no Object Manager"; |
| 1172 | continue; |
| 1173 | } |
| 1174 | |
| 1175 | calledConnections.insert(connectionGroup.first); |
| 1176 | |
| 1177 | asyncPopulatePid(findObjMgr->first, findObjMgr->second, |
| 1178 | currentProfile, supportedProfiles, |
| 1179 | asyncResp); |
| 1180 | break; |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | std::vector<std::string> supportedProfiles; |
| 1188 | std::string currentProfile; |
| 1189 | crow::openbmc_mapper::GetSubTreeType subtree; |
| 1190 | std::shared_ptr<AsyncResp> asyncResp; |
| 1191 | }; |
| 1192 | |
| 1193 | struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> |
| 1194 | { |
| 1195 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1196 | SetPIDValues(const std::shared_ptr<AsyncResp>& asyncRespIn, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1197 | nlohmann::json& data) : |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1198 | asyncResp(asyncRespIn) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1199 | { |
| 1200 | |
| 1201 | std::optional<nlohmann::json> pidControllers; |
| 1202 | std::optional<nlohmann::json> fanControllers; |
| 1203 | std::optional<nlohmann::json> fanZones; |
| 1204 | std::optional<nlohmann::json> stepwiseControllers; |
| 1205 | |
| 1206 | if (!redfish::json_util::readJson( |
| 1207 | data, asyncResp->res, "PidControllers", pidControllers, |
| 1208 | "FanControllers", fanControllers, "FanZones", fanZones, |
| 1209 | "StepwiseControllers", stepwiseControllers, "Profile", profile)) |
| 1210 | { |
| 1211 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
| 1212 | << data.dump(); |
| 1213 | return; |
| 1214 | } |
| 1215 | configuration.emplace_back("PidControllers", std::move(pidControllers)); |
| 1216 | configuration.emplace_back("FanControllers", std::move(fanControllers)); |
| 1217 | configuration.emplace_back("FanZones", std::move(fanZones)); |
| 1218 | configuration.emplace_back("StepwiseControllers", |
| 1219 | std::move(stepwiseControllers)); |
| 1220 | } |
| 1221 | void run() |
| 1222 | { |
| 1223 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1224 | { |
| 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | std::shared_ptr<SetPIDValues> self = shared_from_this(); |
| 1229 | |
| 1230 | // todo(james): might make sense to do a mapper call here if this |
| 1231 | // interface gets more traction |
| 1232 | crow::connections::systemBus->async_method_call( |
| 1233 | [self](const boost::system::error_code ec, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1234 | dbus::utility::ManagedObjectType& mObj) { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1235 | if (ec) |
| 1236 | { |
| 1237 | BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; |
| 1238 | messages::internalError(self->asyncResp->res); |
| 1239 | return; |
| 1240 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1241 | self->managedObj = std::move(mObj); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1242 | }, |
| 1243 | "xyz.openbmc_project.EntityManager", "/", objectManagerIface, |
| 1244 | "GetManagedObjects"); |
| 1245 | |
| 1246 | // at the same time get the profile information |
| 1247 | crow::connections::systemBus->async_method_call( |
| 1248 | [self](const boost::system::error_code ec, |
| 1249 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
| 1250 | if (ec || subtree.empty()) |
| 1251 | { |
| 1252 | return; |
| 1253 | } |
| 1254 | if (subtree[0].second.empty()) |
| 1255 | { |
| 1256 | // invalid mapper response, should never happen |
| 1257 | BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; |
| 1258 | messages::internalError(self->asyncResp->res); |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | const std::string& path = subtree[0].first; |
| 1263 | const std::string& owner = subtree[0].second[0].first; |
| 1264 | crow::connections::systemBus->async_method_call( |
| 1265 | [self, path, owner]( |
| 1266 | const boost::system::error_code ec, |
| 1267 | const boost::container::flat_map< |
| 1268 | std::string, std::variant<std::vector<std::string>, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1269 | std::string>>& r) { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1270 | if (ec) |
| 1271 | { |
| 1272 | BMCWEB_LOG_ERROR << "SetPIDValues: Can't get " |
| 1273 | "thermalModeIface " |
| 1274 | << path; |
| 1275 | messages::internalError(self->asyncResp->res); |
| 1276 | return; |
| 1277 | } |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1278 | const std::string* current = nullptr; |
| 1279 | const std::vector<std::string>* supported = nullptr; |
| 1280 | for (auto& [key, value] : r) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1281 | { |
| 1282 | if (key == "Current") |
| 1283 | { |
| 1284 | current = std::get_if<std::string>(&value); |
| 1285 | if (current == nullptr) |
| 1286 | { |
| 1287 | BMCWEB_LOG_ERROR |
| 1288 | << "SetPIDValues: thermal mode " |
| 1289 | "iface invalid " |
| 1290 | << path; |
| 1291 | messages::internalError( |
| 1292 | self->asyncResp->res); |
| 1293 | return; |
| 1294 | } |
| 1295 | } |
| 1296 | if (key == "Supported") |
| 1297 | { |
| 1298 | supported = |
| 1299 | std::get_if<std::vector<std::string>>( |
| 1300 | &value); |
| 1301 | if (supported == nullptr) |
| 1302 | { |
| 1303 | BMCWEB_LOG_ERROR |
| 1304 | << "SetPIDValues: thermal mode " |
| 1305 | "iface invalid" |
| 1306 | << path; |
| 1307 | messages::internalError( |
| 1308 | self->asyncResp->res); |
| 1309 | return; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | if (current == nullptr || supported == nullptr) |
| 1314 | { |
| 1315 | BMCWEB_LOG_ERROR << "SetPIDValues: thermal mode " |
| 1316 | "iface invalid " |
| 1317 | << path; |
| 1318 | messages::internalError(self->asyncResp->res); |
| 1319 | return; |
| 1320 | } |
| 1321 | self->currentProfile = *current; |
| 1322 | self->supportedProfiles = *supported; |
| 1323 | self->profileConnection = owner; |
| 1324 | self->profilePath = path; |
| 1325 | }, |
| 1326 | owner, path, "org.freedesktop.DBus.Properties", "GetAll", |
| 1327 | thermalModeIface); |
| 1328 | }, |
| 1329 | "xyz.openbmc_project.ObjectMapper", |
| 1330 | "/xyz/openbmc_project/object_mapper", |
| 1331 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, |
| 1332 | std::array<const char*, 1>{thermalModeIface}); |
| 1333 | } |
| 1334 | ~SetPIDValues() |
| 1335 | { |
| 1336 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1337 | { |
| 1338 | return; |
| 1339 | } |
| 1340 | |
| 1341 | std::shared_ptr<AsyncResp> response = asyncResp; |
| 1342 | |
| 1343 | if (profile) |
| 1344 | { |
| 1345 | if (std::find(supportedProfiles.begin(), supportedProfiles.end(), |
| 1346 | *profile) == supportedProfiles.end()) |
| 1347 | { |
| 1348 | messages::actionParameterUnknown(response->res, "Profile", |
| 1349 | *profile); |
| 1350 | return; |
| 1351 | } |
| 1352 | currentProfile = *profile; |
| 1353 | crow::connections::systemBus->async_method_call( |
| 1354 | [response](const boost::system::error_code ec) { |
| 1355 | if (ec) |
| 1356 | { |
| 1357 | BMCWEB_LOG_ERROR << "Error patching profile" << ec; |
| 1358 | messages::internalError(response->res); |
| 1359 | } |
| 1360 | }, |
| 1361 | profileConnection, profilePath, |
| 1362 | "org.freedesktop.DBus.Properties", "Set", thermalModeIface, |
| 1363 | "Current", std::variant<std::string>(*profile)); |
| 1364 | } |
| 1365 | |
| 1366 | for (auto& containerPair : configuration) |
| 1367 | { |
| 1368 | auto& container = containerPair.second; |
| 1369 | if (!container) |
| 1370 | { |
| 1371 | continue; |
| 1372 | } |
| 1373 | std::string& type = containerPair.first; |
| 1374 | |
| 1375 | for (nlohmann::json::iterator it = container->begin(); |
| 1376 | it != container->end(); it++) |
| 1377 | { |
| 1378 | const auto& name = it.key(); |
| 1379 | auto pathItr = |
| 1380 | std::find_if(managedObj.begin(), managedObj.end(), |
| 1381 | [&name](const auto& obj) { |
| 1382 | return boost::algorithm::ends_with( |
| 1383 | obj.first.str, "/" + name); |
| 1384 | }); |
| 1385 | boost::container::flat_map<std::string, |
| 1386 | dbus::utility::DbusVariantType> |
| 1387 | output; |
| 1388 | |
| 1389 | output.reserve(16); // The pid interface length |
| 1390 | |
| 1391 | // determines if we're patching entity-manager or |
| 1392 | // creating a new object |
| 1393 | bool createNewObject = (pathItr == managedObj.end()); |
| 1394 | std::string iface; |
| 1395 | if (type == "PidControllers" || type == "FanControllers") |
| 1396 | { |
| 1397 | iface = pidConfigurationIface; |
| 1398 | if (!createNewObject && |
| 1399 | pathItr->second.find(pidConfigurationIface) == |
| 1400 | pathItr->second.end()) |
| 1401 | { |
| 1402 | createNewObject = true; |
| 1403 | } |
| 1404 | } |
| 1405 | else if (type == "FanZones") |
| 1406 | { |
| 1407 | iface = pidZoneConfigurationIface; |
| 1408 | if (!createNewObject && |
| 1409 | pathItr->second.find(pidZoneConfigurationIface) == |
| 1410 | pathItr->second.end()) |
| 1411 | { |
| 1412 | |
| 1413 | createNewObject = true; |
| 1414 | } |
| 1415 | } |
| 1416 | else if (type == "StepwiseControllers") |
| 1417 | { |
| 1418 | iface = stepwiseConfigurationIface; |
| 1419 | if (!createNewObject && |
| 1420 | pathItr->second.find(stepwiseConfigurationIface) == |
| 1421 | pathItr->second.end()) |
| 1422 | { |
| 1423 | createNewObject = true; |
| 1424 | } |
| 1425 | } |
| 1426 | BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; |
| 1427 | output["Name"] = boost::replace_all_copy(name, "_", " "); |
| 1428 | |
| 1429 | std::string chassis; |
| 1430 | CreatePIDRet ret = createPidInterface( |
| 1431 | response, type, it, pathItr->first.str, managedObj, |
| 1432 | createNewObject, output, chassis, currentProfile); |
| 1433 | if (ret == CreatePIDRet::fail) |
| 1434 | { |
| 1435 | return; |
| 1436 | } |
| 1437 | else if (ret == CreatePIDRet::del) |
| 1438 | { |
| 1439 | continue; |
| 1440 | } |
| 1441 | |
| 1442 | if (!createNewObject) |
| 1443 | { |
| 1444 | for (const auto& property : output) |
| 1445 | { |
| 1446 | crow::connections::systemBus->async_method_call( |
| 1447 | [response, |
| 1448 | propertyName{std::string(property.first)}]( |
| 1449 | const boost::system::error_code ec) { |
| 1450 | if (ec) |
| 1451 | { |
| 1452 | BMCWEB_LOG_ERROR << "Error patching " |
| 1453 | << propertyName << ": " |
| 1454 | << ec; |
| 1455 | messages::internalError(response->res); |
| 1456 | return; |
| 1457 | } |
| 1458 | messages::success(response->res); |
| 1459 | }, |
| 1460 | "xyz.openbmc_project.EntityManager", |
| 1461 | pathItr->first.str, |
| 1462 | "org.freedesktop.DBus.Properties", "Set", iface, |
| 1463 | property.first, property.second); |
| 1464 | } |
| 1465 | } |
| 1466 | else |
| 1467 | { |
| 1468 | if (chassis.empty()) |
| 1469 | { |
| 1470 | BMCWEB_LOG_ERROR << "Failed to get chassis from config"; |
| 1471 | messages::invalidObject(response->res, name); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
| 1475 | bool foundChassis = false; |
| 1476 | for (const auto& obj : managedObj) |
| 1477 | { |
| 1478 | if (boost::algorithm::ends_with(obj.first.str, chassis)) |
| 1479 | { |
| 1480 | chassis = obj.first.str; |
| 1481 | foundChassis = true; |
| 1482 | break; |
| 1483 | } |
| 1484 | } |
| 1485 | if (!foundChassis) |
| 1486 | { |
| 1487 | BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; |
| 1488 | messages::resourceMissingAtURI( |
| 1489 | response->res, "/redfish/v1/Chassis/" + chassis); |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | crow::connections::systemBus->async_method_call( |
| 1494 | [response](const boost::system::error_code ec) { |
| 1495 | if (ec) |
| 1496 | { |
| 1497 | BMCWEB_LOG_ERROR << "Error Adding Pid Object " |
| 1498 | << ec; |
| 1499 | messages::internalError(response->res); |
| 1500 | return; |
| 1501 | } |
| 1502 | messages::success(response->res); |
| 1503 | }, |
| 1504 | "xyz.openbmc_project.EntityManager", chassis, |
| 1505 | "xyz.openbmc_project.AddObject", "AddObject", output); |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | std::shared_ptr<AsyncResp> asyncResp; |
| 1511 | std::vector<std::pair<std::string, std::optional<nlohmann::json>>> |
| 1512 | configuration; |
| 1513 | std::optional<std::string> profile; |
| 1514 | dbus::utility::ManagedObjectType managedObj; |
| 1515 | std::vector<std::string> supportedProfiles; |
| 1516 | std::string currentProfile; |
| 1517 | std::string profileConnection; |
| 1518 | std::string profilePath; |
| 1519 | }; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1520 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1521 | class Manager : public Node |
| 1522 | { |
| 1523 | public: |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1524 | Manager(CrowApp& app) : Node(app, "/redfish/v1/Managers/bmc/") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1525 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1526 | uuid = app.template getMiddleware<crow::persistent_data::Middleware>() |
| 1527 | .systemUuid; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1528 | entityPrivileges = { |
| 1529 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1530 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1531 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 1532 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 1533 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 1534 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1537 | private: |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1538 | void doGet(crow::Response& res, const crow::Request& req, |
| 1539 | const std::vector<std::string>& params) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1540 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1541 | res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; |
| 1542 | res.jsonValue["@odata.type"] = "#Manager.v1_3_0.Manager"; |
| 1543 | res.jsonValue["@odata.context"] = |
| 1544 | "/redfish/v1/$metadata#Manager.Manager"; |
| 1545 | res.jsonValue["Id"] = "bmc"; |
| 1546 | res.jsonValue["Name"] = "OpenBmc Manager"; |
| 1547 | res.jsonValue["Description"] = "Baseboard Management Controller"; |
| 1548 | res.jsonValue["PowerState"] = "On"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1549 | res.jsonValue["Status"] = {{"State", "Enabled"}, {"Health", "OK"}}; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1550 | res.jsonValue["ManagerType"] = "BMC"; |
Ed Tanous | 3602e23 | 2019-05-13 11:11:44 -0700 | [diff] [blame] | 1551 | res.jsonValue["UUID"] = systemd_utils::getUuid(); |
| 1552 | res.jsonValue["ServiceEntryPointUUID"] = uuid; |
Ed Tanous | 7517658 | 2018-12-14 08:14:34 -0800 | [diff] [blame] | 1553 | res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1554 | |
| 1555 | res.jsonValue["LogServices"] = { |
| 1556 | {"@odata.id", "/redfish/v1/Managers/bmc/LogServices"}}; |
| 1557 | |
| 1558 | res.jsonValue["NetworkProtocol"] = { |
| 1559 | {"@odata.id", "/redfish/v1/Managers/bmc/NetworkProtocol"}}; |
| 1560 | |
| 1561 | res.jsonValue["EthernetInterfaces"] = { |
| 1562 | {"@odata.id", "/redfish/v1/Managers/bmc/EthernetInterfaces"}}; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1563 | |
| 1564 | #ifdef BMCWEB_ENABLE_VM_NBDPROXY |
| 1565 | res.jsonValue["VirtualMedia"] = { |
| 1566 | {"@odata.id", "/redfish/v1/Managers/bmc/VirtualMedia"}}; |
| 1567 | #endif // BMCWEB_ENABLE_VM_NBDPROXY |
| 1568 | |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1569 | // default oem data |
| 1570 | nlohmann::json& oem = res.jsonValue["Oem"]; |
| 1571 | nlohmann::json& oemOpenbmc = oem["OpenBmc"]; |
| 1572 | oem["@odata.type"] = "#OemManager.Oem"; |
| 1573 | oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; |
| 1574 | oem["@odata.context"] = "/redfish/v1/$metadata#OemManager.Oem"; |
| 1575 | oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; |
| 1576 | oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; |
| 1577 | oemOpenbmc["@odata.context"] = |
| 1578 | "/redfish/v1/$metadata#OemManager.OpenBmc"; |
Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1579 | oemOpenbmc["Certificates"] = { |
| 1580 | {"@odata.id", "/redfish/v1/Managers/bmc/Truststore/Certificates"}}; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1581 | |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 1582 | // Update Actions object. |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1583 | nlohmann::json& manager_reset = |
| 1584 | res.jsonValue["Actions"]["#Manager.Reset"]; |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 1585 | manager_reset["target"] = |
| 1586 | "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; |
| 1587 | manager_reset["ResetType@Redfish.AllowableValues"] = { |
| 1588 | "GracefulRestart"}; |
Jennifer Lee | ca53792 | 2018-08-10 10:07:30 -0700 | [diff] [blame] | 1589 | |
Andrew Geissler | cb92c03 | 2018-08-17 07:56:14 -0700 | [diff] [blame] | 1590 | res.jsonValue["DateTime"] = crow::utility::dateTimeNow(); |
Santosh Puranik | 474bfad | 2019-04-02 16:00:09 +0530 | [diff] [blame] | 1591 | |
Kuiying Wang | f8c3e6f | 2019-08-22 13:35:56 +0800 | [diff] [blame] | 1592 | // Fill in SerialConsole info |
Santosh Puranik | 474bfad | 2019-04-02 16:00:09 +0530 | [diff] [blame] | 1593 | res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; |
Kuiying Wang | f8c3e6f | 2019-08-22 13:35:56 +0800 | [diff] [blame] | 1594 | res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; |
Santosh Puranik | 474bfad | 2019-04-02 16:00:09 +0530 | [diff] [blame] | 1595 | res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = {"IPMI", |
| 1596 | "SSH"}; |
Santosh Puranik | ef47bb1 | 2019-04-30 10:28:52 +0530 | [diff] [blame] | 1597 | #ifdef BMCWEB_ENABLE_KVM |
Kuiying Wang | f8c3e6f | 2019-08-22 13:35:56 +0800 | [diff] [blame] | 1598 | // Fill in GraphicalConsole info |
Santosh Puranik | ef47bb1 | 2019-04-30 10:28:52 +0530 | [diff] [blame] | 1599 | res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; |
Jae Hyun Yoo | 704fae6 | 2019-10-02 13:01:27 -0700 | [diff] [blame] | 1600 | res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; |
Santosh Puranik | ef47bb1 | 2019-04-30 10:28:52 +0530 | [diff] [blame] | 1601 | res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"}; |
| 1602 | #endif // BMCWEB_ENABLE_KVM |
Santosh Puranik | 474bfad | 2019-04-02 16:00:09 +0530 | [diff] [blame] | 1603 | |
Gunnar Mills | 603a664 | 2019-01-21 17:03:51 -0600 | [diff] [blame] | 1604 | res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; |
| 1605 | res.jsonValue["Links"]["ManagerForServers"] = { |
| 1606 | {{"@odata.id", "/redfish/v1/Systems/system"}}}; |
Shawn McCarney | 26f0389 | 2019-05-03 13:20:24 -0500 | [diff] [blame] | 1607 | |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 1608 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1609 | |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 1610 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 1611 | health->isManagersHealth = true; |
| 1612 | health->populate(); |
| 1613 | |
Andrew Geissler | e90c505 | 2019-06-28 13:52:27 -0500 | [diff] [blame] | 1614 | fw_util::getActiveFwVersion(asyncResp, fw_util::bmcPurpose, |
| 1615 | "FirmwareVersion"); |
James Feist | 0f6b00b | 2019-06-10 14:15:53 -0700 | [diff] [blame] | 1616 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1617 | auto pids = std::make_shared<GetPIDValues>(asyncResp); |
| 1618 | pids->run(); |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1619 | |
| 1620 | getMainChassisId(asyncResp, [](const std::string& chassisId, |
| 1621 | const std::shared_ptr<AsyncResp> aRsp) { |
| 1622 | aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; |
| 1623 | aRsp->res.jsonValue["Links"]["ManagerForChassis"] = { |
| 1624 | {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; |
Jason M. Bills | 2c0feb0 | 2019-07-26 16:35:20 -0700 | [diff] [blame] | 1625 | aRsp->res.jsonValue["Links"]["ManagerInChassis"] = { |
| 1626 | {"@odata.id", "/redfish/v1/Chassis/" + chassisId}}; |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1627 | }); |
James Feist | 0f6b00b | 2019-06-10 14:15:53 -0700 | [diff] [blame] | 1628 | |
| 1629 | static bool started = false; |
| 1630 | |
| 1631 | if (!started) |
| 1632 | { |
| 1633 | crow::connections::systemBus->async_method_call( |
| 1634 | [asyncResp](const boost::system::error_code ec, |
| 1635 | const std::variant<double>& resp) { |
| 1636 | if (ec) |
| 1637 | { |
| 1638 | BMCWEB_LOG_ERROR << "Error while getting progress"; |
| 1639 | messages::internalError(asyncResp->res); |
| 1640 | return; |
| 1641 | } |
| 1642 | const double* val = std::get_if<double>(&resp); |
| 1643 | if (val == nullptr) |
| 1644 | { |
| 1645 | BMCWEB_LOG_ERROR |
| 1646 | << "Invalid response while getting progress"; |
| 1647 | messages::internalError(asyncResp->res); |
| 1648 | return; |
| 1649 | } |
| 1650 | if (*val < 1.0) |
| 1651 | { |
| 1652 | asyncResp->res.jsonValue["Status"]["State"] = |
| 1653 | "Starting"; |
| 1654 | started = true; |
| 1655 | } |
| 1656 | }, |
| 1657 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 1658 | "org.freedesktop.DBus.Properties", "Get", |
| 1659 | "org.freedesktop.systemd1.Manager", "Progress"); |
| 1660 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1661 | } |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1662 | |
| 1663 | void doPatch(crow::Response& res, const crow::Request& req, |
| 1664 | const std::vector<std::string>& params) override |
| 1665 | { |
Ed Tanous | 0627a2c | 2018-11-29 17:09:23 -0800 | [diff] [blame] | 1666 | std::optional<nlohmann::json> oem; |
Santosh Puranik | af5d6058 | 2019-03-20 18:16:36 +0530 | [diff] [blame] | 1667 | std::optional<std::string> datetime; |
Santosh Puranik | 41352c2 | 2019-07-03 05:35:49 -0500 | [diff] [blame] | 1668 | std::shared_ptr<AsyncResp> response = std::make_shared<AsyncResp>(res); |
Ed Tanous | 0627a2c | 2018-11-29 17:09:23 -0800 | [diff] [blame] | 1669 | |
Santosh Puranik | 41352c2 | 2019-07-03 05:35:49 -0500 | [diff] [blame] | 1670 | if (!json_util::readJson(req, response->res, "Oem", oem, "DateTime", |
| 1671 | datetime)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1672 | { |
| 1673 | return; |
| 1674 | } |
Ed Tanous | 0627a2c | 2018-11-29 17:09:23 -0800 | [diff] [blame] | 1675 | |
Ed Tanous | 0627a2c | 2018-11-29 17:09:23 -0800 | [diff] [blame] | 1676 | if (oem) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1677 | { |
Ed Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 1678 | std::optional<nlohmann::json> openbmc; |
| 1679 | if (!redfish::json_util::readJson(*oem, res, "OpenBmc", openbmc)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1680 | { |
Ed Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 1681 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " |
| 1682 | << oem->dump(); |
| 1683 | return; |
| 1684 | } |
| 1685 | if (openbmc) |
| 1686 | { |
| 1687 | std::optional<nlohmann::json> fan; |
| 1688 | if (!redfish::json_util::readJson(*openbmc, res, "Fan", fan)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1689 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1690 | BMCWEB_LOG_ERROR << "Line:" << __LINE__ |
Ed Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 1691 | << ", Illegal Property " |
| 1692 | << openbmc->dump(); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1693 | return; |
| 1694 | } |
Ed Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 1695 | if (fan) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1696 | { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1697 | auto pid = std::make_shared<SetPIDValues>(response, *fan); |
| 1698 | pid->run(); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1699 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1700 | } |
| 1701 | } |
Santosh Puranik | af5d6058 | 2019-03-20 18:16:36 +0530 | [diff] [blame] | 1702 | if (datetime) |
| 1703 | { |
| 1704 | setDateTime(response, std::move(*datetime)); |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | void setDateTime(std::shared_ptr<AsyncResp> aResp, |
| 1709 | std::string datetime) const |
| 1710 | { |
| 1711 | BMCWEB_LOG_DEBUG << "Set date time: " << datetime; |
| 1712 | |
| 1713 | std::stringstream stream(datetime); |
| 1714 | // Convert from ISO 8601 to boost local_time |
| 1715 | // (BMC only has time in UTC) |
| 1716 | boost::posix_time::ptime posixTime; |
| 1717 | boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); |
| 1718 | // Facet gets deleted with the stringsteam |
| 1719 | auto ifc = std::make_unique<boost::local_time::local_time_input_facet>( |
| 1720 | "%Y-%m-%d %H:%M:%S%F %ZP"); |
| 1721 | stream.imbue(std::locale(stream.getloc(), ifc.release())); |
| 1722 | |
| 1723 | boost::local_time::local_date_time ldt( |
| 1724 | boost::local_time::not_a_date_time); |
| 1725 | |
| 1726 | if (stream >> ldt) |
| 1727 | { |
| 1728 | posixTime = ldt.utc_time(); |
| 1729 | boost::posix_time::time_duration dur = posixTime - epoch; |
| 1730 | uint64_t durMicroSecs = |
| 1731 | static_cast<uint64_t>(dur.total_microseconds()); |
| 1732 | crow::connections::systemBus->async_method_call( |
| 1733 | [aResp{std::move(aResp)}, datetime{std::move(datetime)}]( |
| 1734 | const boost::system::error_code ec) { |
| 1735 | if (ec) |
| 1736 | { |
| 1737 | BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " |
| 1738 | "DBUS response error " |
| 1739 | << ec; |
| 1740 | messages::internalError(aResp->res); |
| 1741 | return; |
| 1742 | } |
| 1743 | aResp->res.jsonValue["DateTime"] = datetime; |
| 1744 | }, |
| 1745 | "xyz.openbmc_project.Time.Manager", |
| 1746 | "/xyz/openbmc_project/time/bmc", |
| 1747 | "org.freedesktop.DBus.Properties", "Set", |
| 1748 | "xyz.openbmc_project.Time.EpochTime", "Elapsed", |
| 1749 | std::variant<uint64_t>(durMicroSecs)); |
| 1750 | } |
| 1751 | else |
| 1752 | { |
| 1753 | messages::propertyValueFormatError(aResp->res, datetime, |
| 1754 | "DateTime"); |
| 1755 | return; |
| 1756 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1759 | std::string uuid; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1760 | }; |
| 1761 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1762 | class ManagerCollection : public Node |
| 1763 | { |
| 1764 | public: |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1765 | ManagerCollection(CrowApp& app) : Node(app, "/redfish/v1/Managers/") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1766 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1767 | entityPrivileges = { |
| 1768 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1769 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1770 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 1771 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 1772 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 1773 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 1774 | } |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1775 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1776 | private: |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1777 | void doGet(crow::Response& res, const crow::Request& req, |
| 1778 | const std::vector<std::string>& params) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1779 | { |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1780 | // Collections don't include the static data added by SubRoute |
| 1781 | // because it has a duplicate entry for members |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1782 | res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; |
| 1783 | res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection"; |
| 1784 | res.jsonValue["@odata.context"] = |
| 1785 | "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; |
| 1786 | res.jsonValue["Name"] = "Manager Collection"; |
| 1787 | res.jsonValue["Members@odata.count"] = 1; |
| 1788 | res.jsonValue["Members"] = { |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 1789 | {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1790 | res.end(); |
| 1791 | } |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1792 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1793 | } // namespace redfish |