19c310685SBorawski.Lukasz /* 29c310685SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation 39c310685SBorawski.Lukasz // 49c310685SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License"); 59c310685SBorawski.Lukasz // you may not use this file except in compliance with the License. 69c310685SBorawski.Lukasz // You may obtain a copy of the License at 79c310685SBorawski.Lukasz // 89c310685SBorawski.Lukasz // http://www.apache.org/licenses/LICENSE-2.0 99c310685SBorawski.Lukasz // 109c310685SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software 119c310685SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS, 129c310685SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139c310685SBorawski.Lukasz // See the License for the specific language governing permissions and 149c310685SBorawski.Lukasz // limitations under the License. 159c310685SBorawski.Lukasz */ 169c310685SBorawski.Lukasz #pragma once 179c310685SBorawski.Lukasz 18b49ac873SJames Feist #include "health.hpp" 199c310685SBorawski.Lukasz #include "node.hpp" 20c5d03ff4SJennifer Lee #include "redfish_util.hpp" 219c310685SBorawski.Lukasz 225b4aa86bSJames Feist #include <boost/algorithm/string/replace.hpp> 23af5d6058SSantosh Puranik #include <boost/date_time.hpp> 245b4aa86bSJames Feist #include <dbus_utility.hpp> 2573df0db0SJames Feist #include <memory> 26af5d6058SSantosh Puranik #include <sstream> 27e90c5052SAndrew Geissler #include <utils/fw_utils.hpp> 287bffdb7eSBernard Wong #include <utils/systemd_utils.hpp> 29abf2add6SEd Tanous #include <variant> 305b4aa86bSJames Feist 311abe55efSEd Tanous namespace redfish 321abe55efSEd Tanous { 33ed5befbdSJennifer Lee 34ed5befbdSJennifer Lee /** 35ed5befbdSJennifer Lee * ManagerActionsReset class supports handle POST method for Reset action. 36ed5befbdSJennifer Lee * The class retrieves and sends data directly to dbus. 37ed5befbdSJennifer Lee */ 38ed5befbdSJennifer Lee class ManagerActionsReset : public Node 39ed5befbdSJennifer Lee { 40ed5befbdSJennifer Lee public: 41ed5befbdSJennifer Lee ManagerActionsReset(CrowApp& app) : 42ed5befbdSJennifer Lee Node(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 43ed5befbdSJennifer Lee { 44ed5befbdSJennifer Lee entityPrivileges = { 45ed5befbdSJennifer Lee {boost::beast::http::verb::get, {{"Login"}}}, 46ed5befbdSJennifer Lee {boost::beast::http::verb::head, {{"Login"}}}, 47ed5befbdSJennifer Lee {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 48ed5befbdSJennifer Lee {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 49ed5befbdSJennifer Lee {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 50ed5befbdSJennifer Lee {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 51ed5befbdSJennifer Lee } 52ed5befbdSJennifer Lee 53ed5befbdSJennifer Lee private: 54ed5befbdSJennifer Lee /** 55ed5befbdSJennifer Lee * Function handles POST method request. 56ed5befbdSJennifer Lee * Analyzes POST body message before sends Reset request data to dbus. 57ed5befbdSJennifer Lee * OpenBMC allows for ResetType is GracefulRestart only. 58ed5befbdSJennifer Lee */ 59ed5befbdSJennifer Lee void doPost(crow::Response& res, const crow::Request& req, 60ed5befbdSJennifer Lee const std::vector<std::string>& params) override 61ed5befbdSJennifer Lee { 62ed5befbdSJennifer Lee std::string resetType; 63ed5befbdSJennifer Lee 64ed5befbdSJennifer Lee if (!json_util::readJson(req, res, "ResetType", resetType)) 65ed5befbdSJennifer Lee { 66ed5befbdSJennifer Lee return; 67ed5befbdSJennifer Lee } 68ed5befbdSJennifer Lee 69ed5befbdSJennifer Lee if (resetType != "GracefulRestart") 70ed5befbdSJennifer Lee { 71ed5befbdSJennifer Lee res.result(boost::beast::http::status::bad_request); 72ed5befbdSJennifer Lee messages::actionParameterNotSupported(res, resetType, "ResetType"); 73ed5befbdSJennifer Lee BMCWEB_LOG_ERROR << "Request incorrect action parameter: " 74ed5befbdSJennifer Lee << resetType; 75ed5befbdSJennifer Lee res.end(); 76ed5befbdSJennifer Lee return; 77ed5befbdSJennifer Lee } 78ed5befbdSJennifer Lee doBMCGracefulRestart(res, req, params); 79ed5befbdSJennifer Lee } 80ed5befbdSJennifer Lee 81ed5befbdSJennifer Lee /** 82ed5befbdSJennifer Lee * Function transceives data with dbus directly. 83ed5befbdSJennifer Lee * All BMC state properties will be retrieved before sending reset request. 84ed5befbdSJennifer Lee */ 85ed5befbdSJennifer Lee void doBMCGracefulRestart(crow::Response& res, const crow::Request& req, 86ed5befbdSJennifer Lee const std::vector<std::string>& params) 87ed5befbdSJennifer Lee { 88ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 89ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 90ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 91ed5befbdSJennifer Lee const std::string& propertyValue = 92ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 93ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 94ed5befbdSJennifer Lee 95ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 96ed5befbdSJennifer Lee VariantType dbusPropertyValue(propertyValue); 97ed5befbdSJennifer Lee 98ed5befbdSJennifer Lee std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 99ed5befbdSJennifer Lee 100ed5befbdSJennifer Lee crow::connections::systemBus->async_method_call( 101ed5befbdSJennifer Lee [asyncResp](const boost::system::error_code ec) { 102ed5befbdSJennifer Lee // Use "Set" method to set the property value. 103ed5befbdSJennifer Lee if (ec) 104ed5befbdSJennifer Lee { 105ed5befbdSJennifer Lee BMCWEB_LOG_ERROR << "[Set] Bad D-Bus request error: " << ec; 106ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 107ed5befbdSJennifer Lee return; 108ed5befbdSJennifer Lee } 109ed5befbdSJennifer Lee 110ed5befbdSJennifer Lee messages::success(asyncResp->res); 111ed5befbdSJennifer Lee }, 112ed5befbdSJennifer Lee processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 113ed5befbdSJennifer Lee interfaceName, destProperty, dbusPropertyValue); 114ed5befbdSJennifer Lee } 115ed5befbdSJennifer Lee }; 116ed5befbdSJennifer Lee 1175b4aa86bSJames Feist static constexpr const char* objectManagerIface = 1185b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 1195b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 1205b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 1215b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 1225b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 123b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 124b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 12573df0db0SJames Feist static constexpr const char* thermalModeIface = 12673df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 1279c310685SBorawski.Lukasz 1285b4aa86bSJames Feist static void asyncPopulatePid(const std::string& connection, 1295b4aa86bSJames Feist const std::string& path, 13073df0db0SJames Feist const std::string& currentProfile, 13173df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 1325b4aa86bSJames Feist std::shared_ptr<AsyncResp> asyncResp) 1335b4aa86bSJames Feist { 1345b4aa86bSJames Feist 1355b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 13673df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 13773df0db0SJames Feist const boost::system::error_code ec, 1385b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 1395b4aa86bSJames Feist if (ec) 1405b4aa86bSJames Feist { 1415b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 1425b4aa86bSJames Feist asyncResp->res.jsonValue.clear(); 143f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1445b4aa86bSJames Feist return; 1455b4aa86bSJames Feist } 1465b4aa86bSJames Feist nlohmann::json& configRoot = 1475b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 1485b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 1495b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 1505b4aa86bSJames Feist fans["@odata.context"] = 1515b4aa86bSJames Feist "/redfish/v1/$metadata#OemManager.FanControllers"; 1525b4aa86bSJames Feist fans["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/" 1535b4aa86bSJames Feist "Fan/FanControllers"; 1545b4aa86bSJames Feist 1555b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 1565b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 1575b4aa86bSJames Feist pids["@odata.context"] = 1585b4aa86bSJames Feist "/redfish/v1/$metadata#OemManager.PidControllers"; 1595b4aa86bSJames Feist pids["@odata.id"] = 1605b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 1615b4aa86bSJames Feist 162b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 163b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 164b7a08d04SJames Feist stepwise["@odata.context"] = 165b7a08d04SJames Feist "/redfish/v1/$metadata#OemManager.StepwiseControllers"; 166b7a08d04SJames Feist stepwise["@odata.id"] = 167b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 168b7a08d04SJames Feist 1695b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 1705b4aa86bSJames Feist zones["@odata.id"] = 1715b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 1725b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 1735b4aa86bSJames Feist zones["@odata.context"] = 1745b4aa86bSJames Feist "/redfish/v1/$metadata#OemManager.FanZones"; 1755b4aa86bSJames Feist configRoot["@odata.id"] = 1765b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 1775b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 1785b4aa86bSJames Feist configRoot["@odata.context"] = 1795b4aa86bSJames Feist "/redfish/v1/$metadata#OemManager.Fan"; 18073df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 18173df0db0SJames Feist 18273df0db0SJames Feist if (!currentProfile.empty()) 18373df0db0SJames Feist { 18473df0db0SJames Feist configRoot["Profile"] = currentProfile; 18573df0db0SJames Feist } 18673df0db0SJames Feist BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; 1875b4aa86bSJames Feist 1885b4aa86bSJames Feist for (const auto& pathPair : managedObj) 1895b4aa86bSJames Feist { 1905b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 1915b4aa86bSJames Feist { 1925b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 193b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 194b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 1955b4aa86bSJames Feist { 1965b4aa86bSJames Feist continue; 1975b4aa86bSJames Feist } 1985b4aa86bSJames Feist auto findName = intfPair.second.find("Name"); 1995b4aa86bSJames Feist if (findName == intfPair.second.end()) 2005b4aa86bSJames Feist { 2015b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Field missing Name"; 202a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 2035b4aa86bSJames Feist return; 2045b4aa86bSJames Feist } 20573df0db0SJames Feist 2065b4aa86bSJames Feist const std::string* namePtr = 207abf2add6SEd Tanous std::get_if<std::string>(&findName->second); 2085b4aa86bSJames Feist if (namePtr == nullptr) 2095b4aa86bSJames Feist { 2105b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Name Field illegal"; 211b7a08d04SJames Feist messages::internalError(asyncResp->res); 2125b4aa86bSJames Feist return; 2135b4aa86bSJames Feist } 2145b4aa86bSJames Feist std::string name = *namePtr; 2155b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 21673df0db0SJames Feist 21773df0db0SJames Feist auto findProfiles = intfPair.second.find("Profiles"); 21873df0db0SJames Feist if (findProfiles != intfPair.second.end()) 21973df0db0SJames Feist { 22073df0db0SJames Feist const std::vector<std::string>* profiles = 22173df0db0SJames Feist std::get_if<std::vector<std::string>>( 22273df0db0SJames Feist &findProfiles->second); 22373df0db0SJames Feist if (profiles == nullptr) 22473df0db0SJames Feist { 22573df0db0SJames Feist BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; 22673df0db0SJames Feist messages::internalError(asyncResp->res); 22773df0db0SJames Feist return; 22873df0db0SJames Feist } 22973df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 23073df0db0SJames Feist currentProfile) == profiles->end()) 23173df0db0SJames Feist { 23273df0db0SJames Feist BMCWEB_LOG_INFO 23373df0db0SJames Feist << name << " not supported in current profile"; 23473df0db0SJames Feist continue; 23573df0db0SJames Feist } 23673df0db0SJames Feist } 237b7a08d04SJames Feist nlohmann::json* config = nullptr; 238c33a90ecSJames Feist 239c33a90ecSJames Feist const std::string* classPtr = nullptr; 240c33a90ecSJames Feist auto findClass = intfPair.second.find("Class"); 241c33a90ecSJames Feist if (findClass != intfPair.second.end()) 242c33a90ecSJames Feist { 243c33a90ecSJames Feist classPtr = std::get_if<std::string>(&findClass->second); 244c33a90ecSJames Feist } 245c33a90ecSJames Feist 2465b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 2475b4aa86bSJames Feist { 2485b4aa86bSJames Feist std::string chassis; 2495b4aa86bSJames Feist if (!dbus::utility::getNthStringFromPath( 2505b4aa86bSJames Feist pathPair.first.str, 5, chassis)) 2515b4aa86bSJames Feist { 2525b4aa86bSJames Feist chassis = "#IllegalValue"; 2535b4aa86bSJames Feist } 2545b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 2555b4aa86bSJames Feist zone["Chassis"] = { 2565b4aa86bSJames Feist {"@odata.id", "/redfish/v1/Chassis/" + chassis}}; 2575b4aa86bSJames Feist zone["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/" 2585b4aa86bSJames Feist "OpenBmc/Fan/FanZones/" + 2595b4aa86bSJames Feist name; 2605b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 2615b4aa86bSJames Feist zone["@odata.context"] = 2625b4aa86bSJames Feist "/redfish/v1/$metadata#OemManager.FanZone"; 263b7a08d04SJames Feist config = &zone; 2645b4aa86bSJames Feist } 2655b4aa86bSJames Feist 266b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 2675b4aa86bSJames Feist { 268c33a90ecSJames Feist if (classPtr == nullptr) 269c33a90ecSJames Feist { 270c33a90ecSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 271c33a90ecSJames Feist messages::internalError(asyncResp->res); 272c33a90ecSJames Feist return; 273c33a90ecSJames Feist } 274c33a90ecSJames Feist 275b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 276b7a08d04SJames Feist config = &controller; 2775b4aa86bSJames Feist 278b7a08d04SJames Feist controller["@odata.id"] = 279b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/" 280b7a08d04SJames Feist "OpenBmc/Fan/StepwiseControllers/" + 281b7a08d04SJames Feist std::string(name); 282b7a08d04SJames Feist controller["@odata.type"] = 283b7a08d04SJames Feist "#OemManager.StepwiseController"; 284b7a08d04SJames Feist 285b7a08d04SJames Feist controller["@odata.context"] = 286b7a08d04SJames Feist "/redfish/v1/" 287b7a08d04SJames Feist "$metadata#OemManager.StepwiseController"; 288c33a90ecSJames Feist controller["Direction"] = *classPtr; 2895b4aa86bSJames Feist } 2905b4aa86bSJames Feist 2915b4aa86bSJames Feist // pid and fans are off the same configuration 292b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 2935b4aa86bSJames Feist { 294c33a90ecSJames Feist 2955b4aa86bSJames Feist if (classPtr == nullptr) 2965b4aa86bSJames Feist { 2975b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 298a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 2995b4aa86bSJames Feist return; 3005b4aa86bSJames Feist } 3015b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 3025b4aa86bSJames Feist nlohmann::json& element = 3035b4aa86bSJames Feist isFan ? fans[name] : pids[name]; 304b7a08d04SJames Feist config = &element; 3055b4aa86bSJames Feist if (isFan) 3065b4aa86bSJames Feist { 3075b4aa86bSJames Feist element["@odata.id"] = 3085b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 3095b4aa86bSJames Feist "OpenBmc/Fan/FanControllers/" + 3105b4aa86bSJames Feist std::string(name); 3115b4aa86bSJames Feist element["@odata.type"] = 3125b4aa86bSJames Feist "#OemManager.FanController"; 3135b4aa86bSJames Feist 3145b4aa86bSJames Feist element["@odata.context"] = 3155b4aa86bSJames Feist "/redfish/v1/" 3165b4aa86bSJames Feist "$metadata#OemManager.FanController"; 3175b4aa86bSJames Feist } 3185b4aa86bSJames Feist else 3195b4aa86bSJames Feist { 3205b4aa86bSJames Feist element["@odata.id"] = 3215b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 3225b4aa86bSJames Feist "OpenBmc/Fan/PidControllers/" + 3235b4aa86bSJames Feist std::string(name); 3245b4aa86bSJames Feist element["@odata.type"] = 3255b4aa86bSJames Feist "#OemManager.PidController"; 3265b4aa86bSJames Feist element["@odata.context"] = 3275b4aa86bSJames Feist "/redfish/v1/$metadata" 3285b4aa86bSJames Feist "#OemManager.PidController"; 3295b4aa86bSJames Feist } 330b7a08d04SJames Feist } 331b7a08d04SJames Feist else 332b7a08d04SJames Feist { 333b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Unexpected configuration"; 334b7a08d04SJames Feist messages::internalError(asyncResp->res); 335b7a08d04SJames Feist return; 336b7a08d04SJames Feist } 337b7a08d04SJames Feist 338b7a08d04SJames Feist // used for making maps out of 2 vectors 339b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 340b7a08d04SJames Feist const std::vector<double>* values = nullptr; 341b7a08d04SJames Feist 342b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 343b7a08d04SJames Feist { 344b7a08d04SJames Feist if (propertyPair.first == "Type" || 345b7a08d04SJames Feist propertyPair.first == "Class" || 346b7a08d04SJames Feist propertyPair.first == "Name") 347b7a08d04SJames Feist { 348b7a08d04SJames Feist continue; 349b7a08d04SJames Feist } 350b7a08d04SJames Feist 351b7a08d04SJames Feist // zones 352b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 353b7a08d04SJames Feist { 354b7a08d04SJames Feist const double* ptr = 355abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 356b7a08d04SJames Feist if (ptr == nullptr) 357b7a08d04SJames Feist { 358b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 359b7a08d04SJames Feist << propertyPair.first; 360b7a08d04SJames Feist messages::internalError(asyncResp->res); 361b7a08d04SJames Feist return; 362b7a08d04SJames Feist } 363b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 364b7a08d04SJames Feist } 365b7a08d04SJames Feist 366b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 367b7a08d04SJames Feist { 368b7a08d04SJames Feist if (propertyPair.first == "Reading" || 369b7a08d04SJames Feist propertyPair.first == "Output") 370b7a08d04SJames Feist { 371b7a08d04SJames Feist const std::vector<double>* ptr = 372abf2add6SEd Tanous std::get_if<std::vector<double>>( 373b7a08d04SJames Feist &propertyPair.second); 374b7a08d04SJames Feist 375b7a08d04SJames Feist if (ptr == nullptr) 376b7a08d04SJames Feist { 377b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 378b7a08d04SJames Feist << propertyPair.first; 379b7a08d04SJames Feist messages::internalError(asyncResp->res); 380b7a08d04SJames Feist return; 381b7a08d04SJames Feist } 382b7a08d04SJames Feist 383b7a08d04SJames Feist if (propertyPair.first == "Reading") 384b7a08d04SJames Feist { 385b7a08d04SJames Feist keys = ptr; 386b7a08d04SJames Feist } 387b7a08d04SJames Feist else 388b7a08d04SJames Feist { 389b7a08d04SJames Feist values = ptr; 390b7a08d04SJames Feist } 391b7a08d04SJames Feist if (keys && values) 392b7a08d04SJames Feist { 393b7a08d04SJames Feist if (keys->size() != values->size()) 394b7a08d04SJames Feist { 395b7a08d04SJames Feist BMCWEB_LOG_ERROR 396b7a08d04SJames Feist << "Reading and Output size don't " 397b7a08d04SJames Feist "match "; 398b7a08d04SJames Feist messages::internalError(asyncResp->res); 399b7a08d04SJames Feist return; 400b7a08d04SJames Feist } 401b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 402b7a08d04SJames Feist steps = nlohmann::json::array(); 403b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 404b7a08d04SJames Feist { 405b7a08d04SJames Feist steps.push_back( 406b7a08d04SJames Feist {{"Target", (*keys)[ii]}, 407b7a08d04SJames Feist {"Output", (*values)[ii]}}); 408b7a08d04SJames Feist } 409b7a08d04SJames Feist } 410b7a08d04SJames Feist } 411b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 412b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 413b7a08d04SJames Feist { 414b7a08d04SJames Feist const double* ptr = 415abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 416b7a08d04SJames Feist if (ptr == nullptr) 417b7a08d04SJames Feist { 418b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 419b7a08d04SJames Feist << propertyPair.first; 420b7a08d04SJames Feist messages::internalError(asyncResp->res); 421b7a08d04SJames Feist return; 422b7a08d04SJames Feist } 423b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 424b7a08d04SJames Feist } 425b7a08d04SJames Feist } 426b7a08d04SJames Feist 427b7a08d04SJames Feist // pid and fans are off the same configuration 428b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 429b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 430b7a08d04SJames Feist { 4315b4aa86bSJames Feist 4325b4aa86bSJames Feist if (propertyPair.first == "Zones") 4335b4aa86bSJames Feist { 4345b4aa86bSJames Feist const std::vector<std::string>* inputs = 435abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 4361b6b96c5SEd Tanous &propertyPair.second); 4375b4aa86bSJames Feist 4385b4aa86bSJames Feist if (inputs == nullptr) 4395b4aa86bSJames Feist { 4405b4aa86bSJames Feist BMCWEB_LOG_ERROR 4415b4aa86bSJames Feist << "Zones Pid Field Illegal"; 442a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4435b4aa86bSJames Feist return; 4445b4aa86bSJames Feist } 445b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 4465b4aa86bSJames Feist data = nlohmann::json::array(); 4475b4aa86bSJames Feist for (std::string itemCopy : *inputs) 4485b4aa86bSJames Feist { 4495b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 4505b4aa86bSJames Feist data.push_back( 4515b4aa86bSJames Feist {{"@odata.id", 4525b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 4535b4aa86bSJames Feist "OpenBmc/Fan/FanZones/" + 4545b4aa86bSJames Feist itemCopy}}); 4555b4aa86bSJames Feist } 4565b4aa86bSJames Feist } 4575b4aa86bSJames Feist // todo(james): may never happen, but this 4585b4aa86bSJames Feist // assumes configuration data referenced in the 4595b4aa86bSJames Feist // PID config is provided by the same daemon, we 4605b4aa86bSJames Feist // could add another loop to cover all cases, 4615b4aa86bSJames Feist // but I'm okay kicking this can down the road a 4625b4aa86bSJames Feist // bit 4635b4aa86bSJames Feist 4645b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 4655b4aa86bSJames Feist propertyPair.first == "Outputs") 4665b4aa86bSJames Feist { 467b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 4685b4aa86bSJames Feist const std::vector<std::string>* inputs = 469abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 4701b6b96c5SEd Tanous &propertyPair.second); 4715b4aa86bSJames Feist 4725b4aa86bSJames Feist if (inputs == nullptr) 4735b4aa86bSJames Feist { 4745b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 4755b4aa86bSJames Feist << propertyPair.first; 476f12894f8SJason M. Bills messages::internalError(asyncResp->res); 4775b4aa86bSJames Feist return; 4785b4aa86bSJames Feist } 4795b4aa86bSJames Feist data = *inputs; 4805b4aa86bSJames Feist } // doubles 4815b4aa86bSJames Feist else if (propertyPair.first == 4825b4aa86bSJames Feist "FFGainCoefficient" || 4835b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 4845b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 4855b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 4865b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 487aad1a257SJames Feist propertyPair.first == 488aad1a257SJames Feist "PositiveHysteresis" || 489aad1a257SJames Feist propertyPair.first == 490aad1a257SJames Feist "NegativeHysteresis" || 4915b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 4925b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 4935b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 4947625cb81SJames Feist propertyPair.first == "SetPoint" || 4955b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 4965b4aa86bSJames Feist propertyPair.first == "SlewPos") 4975b4aa86bSJames Feist { 4985b4aa86bSJames Feist const double* ptr = 499abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 5005b4aa86bSJames Feist if (ptr == nullptr) 5015b4aa86bSJames Feist { 5025b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 5035b4aa86bSJames Feist << propertyPair.first; 504f12894f8SJason M. Bills messages::internalError(asyncResp->res); 5055b4aa86bSJames Feist return; 5065b4aa86bSJames Feist } 507b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 5085b4aa86bSJames Feist } 5095b4aa86bSJames Feist } 5105b4aa86bSJames Feist } 5115b4aa86bSJames Feist } 5125b4aa86bSJames Feist } 5135b4aa86bSJames Feist }, 5145b4aa86bSJames Feist connection, path, objectManagerIface, "GetManagedObjects"); 5155b4aa86bSJames Feist } 516ca537928SJennifer Lee 51783ff9ab6SJames Feist enum class CreatePIDRet 51883ff9ab6SJames Feist { 51983ff9ab6SJames Feist fail, 52083ff9ab6SJames Feist del, 52183ff9ab6SJames Feist patch 52283ff9ab6SJames Feist }; 52383ff9ab6SJames Feist 5245f2caaefSJames Feist static bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response, 5255f2caaefSJames Feist std::vector<nlohmann::json>& config, 5265f2caaefSJames Feist std::vector<std::string>& zones) 5275f2caaefSJames Feist { 528b6baeaa4SJames Feist if (config.empty()) 529b6baeaa4SJames Feist { 530b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Empty Zones"; 531b6baeaa4SJames Feist messages::propertyValueFormatError(response->res, 532b6baeaa4SJames Feist nlohmann::json::array(), "Zones"); 533b6baeaa4SJames Feist return false; 534b6baeaa4SJames Feist } 5355f2caaefSJames Feist for (auto& odata : config) 5365f2caaefSJames Feist { 5375f2caaefSJames Feist std::string path; 5385f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 5395f2caaefSJames Feist path)) 5405f2caaefSJames Feist { 5415f2caaefSJames Feist return false; 5425f2caaefSJames Feist } 5435f2caaefSJames Feist std::string input; 54461adbda3SJames Feist 54561adbda3SJames Feist // 8 below comes from 54661adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 54761adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 54861adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 5495f2caaefSJames Feist { 5505f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << path; 5515f2caaefSJames Feist BMCWEB_LOG_ERROR << "Illegal Type Zones"; 5525f2caaefSJames Feist messages::propertyValueFormatError(response->res, odata.dump(), 5535f2caaefSJames Feist "Zones"); 5545f2caaefSJames Feist return false; 5555f2caaefSJames Feist } 5565f2caaefSJames Feist boost::replace_all(input, "_", " "); 5575f2caaefSJames Feist zones.emplace_back(std::move(input)); 5585f2caaefSJames Feist } 5595f2caaefSJames Feist return true; 5605f2caaefSJames Feist } 5615f2caaefSJames Feist 56273df0db0SJames Feist static const dbus::utility::ManagedItem* 56373df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 564b6baeaa4SJames Feist const std::string& value, std::string& chassis) 565b6baeaa4SJames Feist { 566b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; 567b6baeaa4SJames Feist 568b6baeaa4SJames Feist std::string escaped = boost::replace_all_copy(value, " ", "_"); 569b6baeaa4SJames Feist escaped = "/" + escaped; 570b6baeaa4SJames Feist auto it = std::find_if( 571b6baeaa4SJames Feist managedObj.begin(), managedObj.end(), [&escaped](const auto& obj) { 572b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 573b6baeaa4SJames Feist { 574b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; 575b6baeaa4SJames Feist return true; 576b6baeaa4SJames Feist } 577b6baeaa4SJames Feist return false; 578b6baeaa4SJames Feist }); 579b6baeaa4SJames Feist 580b6baeaa4SJames Feist if (it == managedObj.end()) 581b6baeaa4SJames Feist { 58273df0db0SJames Feist return nullptr; 583b6baeaa4SJames Feist } 584b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 585b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 58673df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 58773df0db0SJames Feist { 58873df0db0SJames Feist return &(*it); 58973df0db0SJames Feist } 59073df0db0SJames Feist 59173df0db0SJames Feist return nullptr; 592b6baeaa4SJames Feist } 593b6baeaa4SJames Feist 59483ff9ab6SJames Feist static CreatePIDRet createPidInterface( 59583ff9ab6SJames Feist const std::shared_ptr<AsyncResp>& response, const std::string& type, 596b6baeaa4SJames Feist nlohmann::json::iterator it, const std::string& path, 59783ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 59883ff9ab6SJames Feist boost::container::flat_map<std::string, dbus::utility::DbusVariantType>& 59983ff9ab6SJames Feist output, 60073df0db0SJames Feist std::string& chassis, const std::string& profile) 60183ff9ab6SJames Feist { 60283ff9ab6SJames Feist 6035f2caaefSJames Feist // common deleter 604b6baeaa4SJames Feist if (it.value() == nullptr) 6055f2caaefSJames Feist { 6065f2caaefSJames Feist std::string iface; 6075f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 6085f2caaefSJames Feist { 6095f2caaefSJames Feist iface = pidConfigurationIface; 6105f2caaefSJames Feist } 6115f2caaefSJames Feist else if (type == "FanZones") 6125f2caaefSJames Feist { 6135f2caaefSJames Feist iface = pidZoneConfigurationIface; 6145f2caaefSJames Feist } 6155f2caaefSJames Feist else if (type == "StepwiseControllers") 6165f2caaefSJames Feist { 6175f2caaefSJames Feist iface = stepwiseConfigurationIface; 6185f2caaefSJames Feist } 6195f2caaefSJames Feist else 6205f2caaefSJames Feist { 6215f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type " 6225f2caaefSJames Feist << type; 6235f2caaefSJames Feist messages::propertyUnknown(response->res, type); 6245f2caaefSJames Feist return CreatePIDRet::fail; 6255f2caaefSJames Feist } 6265f2caaefSJames Feist // delete interface 6275f2caaefSJames Feist crow::connections::systemBus->async_method_call( 6285f2caaefSJames Feist [response, path](const boost::system::error_code ec) { 6295f2caaefSJames Feist if (ec) 6305f2caaefSJames Feist { 6315f2caaefSJames Feist BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; 6325f2caaefSJames Feist messages::internalError(response->res); 633b6baeaa4SJames Feist return; 6345f2caaefSJames Feist } 635b6baeaa4SJames Feist messages::success(response->res); 6365f2caaefSJames Feist }, 6375f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 6385f2caaefSJames Feist return CreatePIDRet::del; 6395f2caaefSJames Feist } 6405f2caaefSJames Feist 64173df0db0SJames Feist const dbus::utility::ManagedItem* managedItem = nullptr; 642b6baeaa4SJames Feist if (!createNewObject) 643b6baeaa4SJames Feist { 644b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 645b6baeaa4SJames Feist // d-bus 64673df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 64773df0db0SJames Feist if (managedItem == nullptr) 648b6baeaa4SJames Feist { 649b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 650b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 651b6baeaa4SJames Feist return CreatePIDRet::fail; 652b6baeaa4SJames Feist } 653b6baeaa4SJames Feist } 654b6baeaa4SJames Feist 65573df0db0SJames Feist if (profile.size() && 65673df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 65773df0db0SJames Feist type == "StepwiseControllers")) 65873df0db0SJames Feist { 65973df0db0SJames Feist if (managedItem == nullptr) 66073df0db0SJames Feist { 66173df0db0SJames Feist output["Profiles"] = std::vector<std::string>{profile}; 66273df0db0SJames Feist } 66373df0db0SJames Feist else 66473df0db0SJames Feist { 66573df0db0SJames Feist std::string interface; 66673df0db0SJames Feist if (type == "StepwiseControllers") 66773df0db0SJames Feist { 66873df0db0SJames Feist interface = stepwiseConfigurationIface; 66973df0db0SJames Feist } 67073df0db0SJames Feist else 67173df0db0SJames Feist { 67273df0db0SJames Feist interface = pidConfigurationIface; 67373df0db0SJames Feist } 67473df0db0SJames Feist auto findConfig = managedItem->second.find(interface); 67573df0db0SJames Feist if (findConfig == managedItem->second.end()) 67673df0db0SJames Feist { 67773df0db0SJames Feist BMCWEB_LOG_ERROR 67873df0db0SJames Feist << "Failed to find interface in managed object"; 67973df0db0SJames Feist messages::internalError(response->res); 68073df0db0SJames Feist return CreatePIDRet::fail; 68173df0db0SJames Feist } 68273df0db0SJames Feist auto findProfiles = findConfig->second.find("Profiles"); 68373df0db0SJames Feist if (findProfiles != findConfig->second.end()) 68473df0db0SJames Feist { 68573df0db0SJames Feist const std::vector<std::string>* curProfiles = 68673df0db0SJames Feist std::get_if<std::vector<std::string>>( 68773df0db0SJames Feist &(findProfiles->second)); 68873df0db0SJames Feist if (curProfiles == nullptr) 68973df0db0SJames Feist { 69073df0db0SJames Feist BMCWEB_LOG_ERROR << "Illegal profiles in managed object"; 69173df0db0SJames Feist messages::internalError(response->res); 69273df0db0SJames Feist return CreatePIDRet::fail; 69373df0db0SJames Feist } 69473df0db0SJames Feist if (std::find(curProfiles->begin(), curProfiles->end(), 69573df0db0SJames Feist profile) == curProfiles->end()) 69673df0db0SJames Feist { 69773df0db0SJames Feist std::vector<std::string> newProfiles = *curProfiles; 69873df0db0SJames Feist newProfiles.push_back(profile); 69973df0db0SJames Feist output["Profiles"] = newProfiles; 70073df0db0SJames Feist } 70173df0db0SJames Feist } 70273df0db0SJames Feist } 70373df0db0SJames Feist } 70473df0db0SJames Feist 70583ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 70683ff9ab6SJames Feist { 70783ff9ab6SJames Feist if (createNewObject) 70883ff9ab6SJames Feist { 70983ff9ab6SJames Feist output["Class"] = type == "PidControllers" ? std::string("temp") 71083ff9ab6SJames Feist : std::string("fan"); 71183ff9ab6SJames Feist output["Type"] = std::string("Pid"); 71283ff9ab6SJames Feist } 7135f2caaefSJames Feist 7145f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 7155f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 7165f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 7175f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 7185f2caaefSJames Feist if (!redfish::json_util::readJson( 719b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 7205f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 7215f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 7225f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 7235f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 7245f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 7255f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 7265f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 7275f2caaefSJames Feist doubles["SetPoint"], "SlewNeg", doubles["SlewNeg"], "SlewPos", 728aad1a257SJames Feist doubles["SlewPos"], "PositiveHysteresis", 729aad1a257SJames Feist doubles["PositiveHysteresis"], "NegativeHysteresis", 730aad1a257SJames Feist doubles["NegativeHysteresis"])) 73183ff9ab6SJames Feist { 7325f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 733b6baeaa4SJames Feist << it.value().dump(); 7345f2caaefSJames Feist return CreatePIDRet::fail; 73583ff9ab6SJames Feist } 7365f2caaefSJames Feist if (zones) 7375f2caaefSJames Feist { 7385f2caaefSJames Feist std::vector<std::string> zonesStr; 7395f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 7405f2caaefSJames Feist { 7415f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones"; 7425f2caaefSJames Feist return CreatePIDRet::fail; 7435f2caaefSJames Feist } 744b6baeaa4SJames Feist if (chassis.empty() && 745b6baeaa4SJames Feist !findChassis(managedObj, zonesStr[0], chassis)) 746b6baeaa4SJames Feist { 747b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 748b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 749b6baeaa4SJames Feist return CreatePIDRet::fail; 750b6baeaa4SJames Feist } 751b6baeaa4SJames Feist 7525f2caaefSJames Feist output["Zones"] = std::move(zonesStr); 7535f2caaefSJames Feist } 7545f2caaefSJames Feist if (inputs || outputs) 7555f2caaefSJames Feist { 7565f2caaefSJames Feist std::array<std::optional<std::vector<std::string>>*, 2> containers = 7575f2caaefSJames Feist {&inputs, &outputs}; 7585f2caaefSJames Feist size_t index = 0; 7595f2caaefSJames Feist for (const auto& containerPtr : containers) 7605f2caaefSJames Feist { 7615f2caaefSJames Feist std::optional<std::vector<std::string>>& container = 7625f2caaefSJames Feist *containerPtr; 7635f2caaefSJames Feist if (!container) 7645f2caaefSJames Feist { 7655f2caaefSJames Feist index++; 7665f2caaefSJames Feist continue; 76783ff9ab6SJames Feist } 76883ff9ab6SJames Feist 7695f2caaefSJames Feist for (std::string& value : *container) 77083ff9ab6SJames Feist { 7715f2caaefSJames Feist boost::replace_all(value, "_", " "); 77283ff9ab6SJames Feist } 7735f2caaefSJames Feist std::string key; 7745f2caaefSJames Feist if (index == 0) 7755f2caaefSJames Feist { 7765f2caaefSJames Feist key = "Inputs"; 7775f2caaefSJames Feist } 7785f2caaefSJames Feist else 7795f2caaefSJames Feist { 7805f2caaefSJames Feist key = "Outputs"; 7815f2caaefSJames Feist } 7825f2caaefSJames Feist output[key] = *container; 7835f2caaefSJames Feist index++; 7845f2caaefSJames Feist } 78583ff9ab6SJames Feist } 78683ff9ab6SJames Feist 78783ff9ab6SJames Feist // doubles 7885f2caaefSJames Feist for (const auto& pairs : doubles) 78983ff9ab6SJames Feist { 7905f2caaefSJames Feist if (!pairs.second) 79183ff9ab6SJames Feist { 7925f2caaefSJames Feist continue; 79383ff9ab6SJames Feist } 7945f2caaefSJames Feist BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; 7955f2caaefSJames Feist output[pairs.first] = *(pairs.second); 7965f2caaefSJames Feist } 79783ff9ab6SJames Feist } 79883ff9ab6SJames Feist 79983ff9ab6SJames Feist else if (type == "FanZones") 80083ff9ab6SJames Feist { 80183ff9ab6SJames Feist output["Type"] = std::string("Pid.Zone"); 80283ff9ab6SJames Feist 8035f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 8045f2caaefSJames Feist std::optional<double> failSafePercent; 805d3ec07f8SJames Feist std::optional<double> minThermalOutput; 806b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 8075f2caaefSJames Feist chassisContainer, "FailSafePercent", 808d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 809d3ec07f8SJames Feist minThermalOutput)) 81083ff9ab6SJames Feist { 8115f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 812b6baeaa4SJames Feist << it.value().dump(); 81383ff9ab6SJames Feist return CreatePIDRet::fail; 81483ff9ab6SJames Feist } 8155f2caaefSJames Feist 8165f2caaefSJames Feist if (chassisContainer) 81783ff9ab6SJames Feist { 8185f2caaefSJames Feist 8195f2caaefSJames Feist std::string chassisId; 8205f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 8215f2caaefSJames Feist "@odata.id", chassisId)) 8225f2caaefSJames Feist { 8235f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 8245f2caaefSJames Feist << chassisContainer->dump(); 82583ff9ab6SJames Feist return CreatePIDRet::fail; 82683ff9ab6SJames Feist } 82783ff9ab6SJames Feist 82883ff9ab6SJames Feist // /refish/v1/chassis/chassis_name/ 8295f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 83083ff9ab6SJames Feist { 8315f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; 8325f2caaefSJames Feist messages::invalidObject(response->res, chassisId); 83383ff9ab6SJames Feist return CreatePIDRet::fail; 83483ff9ab6SJames Feist } 83583ff9ab6SJames Feist } 836d3ec07f8SJames Feist if (minThermalOutput) 83783ff9ab6SJames Feist { 838d3ec07f8SJames Feist output["MinThermalOutput"] = *minThermalOutput; 8395f2caaefSJames Feist } 8405f2caaefSJames Feist if (failSafePercent) 84183ff9ab6SJames Feist { 8425f2caaefSJames Feist output["FailSafePercent"] = *failSafePercent; 8435f2caaefSJames Feist } 8445f2caaefSJames Feist } 8455f2caaefSJames Feist else if (type == "StepwiseControllers") 8465f2caaefSJames Feist { 8475f2caaefSJames Feist output["Type"] = std::string("Stepwise"); 8485f2caaefSJames Feist 8495f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 8505f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 8515f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 8525f2caaefSJames Feist std::optional<double> positiveHysteresis; 8535f2caaefSJames Feist std::optional<double> negativeHysteresis; 854c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 8555f2caaefSJames Feist if (!redfish::json_util::readJson( 856b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 857b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 858c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 859c33a90ecSJames Feist direction)) 8605f2caaefSJames Feist { 8615f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 862b6baeaa4SJames Feist << it.value().dump(); 86383ff9ab6SJames Feist return CreatePIDRet::fail; 86483ff9ab6SJames Feist } 8655f2caaefSJames Feist 8665f2caaefSJames Feist if (zones) 86783ff9ab6SJames Feist { 868b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 869b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 8705f2caaefSJames Feist { 8715f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones"; 87283ff9ab6SJames Feist return CreatePIDRet::fail; 87383ff9ab6SJames Feist } 874b6baeaa4SJames Feist if (chassis.empty() && 875b6baeaa4SJames Feist !findChassis(managedObj, zonesStrs[0], chassis)) 876b6baeaa4SJames Feist { 877b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 878b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 879b6baeaa4SJames Feist return CreatePIDRet::fail; 880b6baeaa4SJames Feist } 881b6baeaa4SJames Feist output["Zones"] = std::move(zonesStrs); 8825f2caaefSJames Feist } 8835f2caaefSJames Feist if (steps) 8845f2caaefSJames Feist { 8855f2caaefSJames Feist std::vector<double> readings; 8865f2caaefSJames Feist std::vector<double> outputs; 8875f2caaefSJames Feist for (auto& step : *steps) 8885f2caaefSJames Feist { 8895f2caaefSJames Feist double target; 890b01bf299SEd Tanous double output; 8915f2caaefSJames Feist 8925f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 893b01bf299SEd Tanous target, "Output", output)) 8945f2caaefSJames Feist { 8955f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ 896b6baeaa4SJames Feist << ", Illegal Property " 897b6baeaa4SJames Feist << it.value().dump(); 8985f2caaefSJames Feist return CreatePIDRet::fail; 8995f2caaefSJames Feist } 9005f2caaefSJames Feist readings.emplace_back(target); 901b01bf299SEd Tanous outputs.emplace_back(output); 9025f2caaefSJames Feist } 9035f2caaefSJames Feist output["Reading"] = std::move(readings); 9045f2caaefSJames Feist output["Output"] = std::move(outputs); 9055f2caaefSJames Feist } 9065f2caaefSJames Feist if (inputs) 9075f2caaefSJames Feist { 9085f2caaefSJames Feist for (std::string& value : *inputs) 9095f2caaefSJames Feist { 9105f2caaefSJames Feist boost::replace_all(value, "_", " "); 9115f2caaefSJames Feist } 9125f2caaefSJames Feist output["Inputs"] = std::move(*inputs); 9135f2caaefSJames Feist } 9145f2caaefSJames Feist if (negativeHysteresis) 9155f2caaefSJames Feist { 9165f2caaefSJames Feist output["NegativeHysteresis"] = *negativeHysteresis; 9175f2caaefSJames Feist } 9185f2caaefSJames Feist if (positiveHysteresis) 9195f2caaefSJames Feist { 9205f2caaefSJames Feist output["PositiveHysteresis"] = *positiveHysteresis; 92183ff9ab6SJames Feist } 922c33a90ecSJames Feist if (direction) 923c33a90ecSJames Feist { 924c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 925c33a90ecSJames Feist "Ceiling", "Floor"}; 926c33a90ecSJames Feist if (std::find(allowedDirections.begin(), allowedDirections.end(), 927c33a90ecSJames Feist *direction) == allowedDirections.end()) 928c33a90ecSJames Feist { 929c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 930c33a90ecSJames Feist *direction); 931c33a90ecSJames Feist return CreatePIDRet::fail; 932c33a90ecSJames Feist } 933c33a90ecSJames Feist output["Class"] = *direction; 934c33a90ecSJames Feist } 93583ff9ab6SJames Feist } 93683ff9ab6SJames Feist else 93783ff9ab6SJames Feist { 9385f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type " << type; 93935a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 94083ff9ab6SJames Feist return CreatePIDRet::fail; 94183ff9ab6SJames Feist } 94283ff9ab6SJames Feist return CreatePIDRet::patch; 94383ff9ab6SJames Feist } 94473df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 94573df0db0SJames Feist { 94683ff9ab6SJames Feist 94773df0db0SJames Feist GetPIDValues(const std::shared_ptr<AsyncResp>& asyncResp) : 94873df0db0SJames Feist asyncResp(asyncResp) 94973df0db0SJames Feist 9501abe55efSEd Tanous { 9519c310685SBorawski.Lukasz } 9529c310685SBorawski.Lukasz 95373df0db0SJames Feist void run() 9545b4aa86bSJames Feist { 95573df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 95673df0db0SJames Feist 95773df0db0SJames Feist // get all configurations 9585b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 95973df0db0SJames Feist [self](const boost::system::error_code ec, 9605b4aa86bSJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 9615b4aa86bSJames Feist if (ec) 9625b4aa86bSJames Feist { 9635b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 96473df0db0SJames Feist messages::internalError(self->asyncResp->res); 96573df0db0SJames Feist return; 96673df0db0SJames Feist } 96773df0db0SJames Feist self->subtree = subtree; 96873df0db0SJames Feist }, 96973df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 97073df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 97173df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 97273df0db0SJames Feist std::array<const char*, 4>{ 97373df0db0SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 97473df0db0SJames Feist objectManagerIface, stepwiseConfigurationIface}); 97573df0db0SJames Feist 97673df0db0SJames Feist // at the same time get the selected profile 97773df0db0SJames Feist crow::connections::systemBus->async_method_call( 97873df0db0SJames Feist [self](const boost::system::error_code ec, 97973df0db0SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 98073df0db0SJames Feist if (ec || subtree.empty()) 98173df0db0SJames Feist { 98273df0db0SJames Feist return; 98373df0db0SJames Feist } 98473df0db0SJames Feist if (subtree[0].second.size() != 1) 98573df0db0SJames Feist { 98673df0db0SJames Feist // invalid mapper response, should never happen 98773df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; 98873df0db0SJames Feist messages::internalError(self->asyncResp->res); 9895b4aa86bSJames Feist return; 9905b4aa86bSJames Feist } 9915b4aa86bSJames Feist 99273df0db0SJames Feist const std::string& path = subtree[0].first; 99373df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 99473df0db0SJames Feist crow::connections::systemBus->async_method_call( 99573df0db0SJames Feist [path, owner, self]( 99673df0db0SJames Feist const boost::system::error_code ec, 99773df0db0SJames Feist const boost::container::flat_map< 99873df0db0SJames Feist std::string, std::variant<std::vector<std::string>, 99973df0db0SJames Feist std::string>>& resp) { 100073df0db0SJames Feist if (ec) 100173df0db0SJames Feist { 100273df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Can't get " 100373df0db0SJames Feist "thermalModeIface " 100473df0db0SJames Feist << path; 100573df0db0SJames Feist messages::internalError(self->asyncResp->res); 100673df0db0SJames Feist return; 100773df0db0SJames Feist } 100873df0db0SJames Feist const std::string* current; 100973df0db0SJames Feist const std::vector<std::string>* supported; 101073df0db0SJames Feist for (auto& [key, value] : resp) 101173df0db0SJames Feist { 101273df0db0SJames Feist if (key == "Current") 101373df0db0SJames Feist { 101473df0db0SJames Feist current = std::get_if<std::string>(&value); 101573df0db0SJames Feist if (current == nullptr) 101673df0db0SJames Feist { 101773df0db0SJames Feist BMCWEB_LOG_ERROR 101873df0db0SJames Feist << "GetPIDValues: thermal mode " 101973df0db0SJames Feist "iface invalid " 102073df0db0SJames Feist << path; 102173df0db0SJames Feist messages::internalError( 102273df0db0SJames Feist self->asyncResp->res); 102373df0db0SJames Feist return; 102473df0db0SJames Feist } 102573df0db0SJames Feist } 102673df0db0SJames Feist if (key == "Supported") 102773df0db0SJames Feist { 102873df0db0SJames Feist supported = 102973df0db0SJames Feist std::get_if<std::vector<std::string>>( 103073df0db0SJames Feist &value); 103173df0db0SJames Feist if (supported == nullptr) 103273df0db0SJames Feist { 103373df0db0SJames Feist BMCWEB_LOG_ERROR 103473df0db0SJames Feist << "GetPIDValues: thermal mode " 103573df0db0SJames Feist "iface invalid" 103673df0db0SJames Feist << path; 103773df0db0SJames Feist messages::internalError( 103873df0db0SJames Feist self->asyncResp->res); 103973df0db0SJames Feist return; 104073df0db0SJames Feist } 104173df0db0SJames Feist } 104273df0db0SJames Feist } 104373df0db0SJames Feist if (current == nullptr || supported == nullptr) 104473df0db0SJames Feist { 104573df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: thermal mode " 104673df0db0SJames Feist "iface invalid " 104773df0db0SJames Feist << path; 104873df0db0SJames Feist messages::internalError(self->asyncResp->res); 104973df0db0SJames Feist return; 105073df0db0SJames Feist } 105173df0db0SJames Feist self->currentProfile = *current; 105273df0db0SJames Feist self->supportedProfiles = *supported; 105373df0db0SJames Feist }, 105473df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 105573df0db0SJames Feist thermalModeIface); 105673df0db0SJames Feist }, 105773df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 105873df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 105973df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 106073df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 106173df0db0SJames Feist } 106273df0db0SJames Feist 106373df0db0SJames Feist ~GetPIDValues() 106473df0db0SJames Feist { 106573df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 106673df0db0SJames Feist { 106773df0db0SJames Feist return; 106873df0db0SJames Feist } 10695b4aa86bSJames Feist // create map of <connection, path to objMgr>> 107073df0db0SJames Feist boost::container::flat_map<std::string, std::string> objectMgrPaths; 10716bce33bcSJames Feist boost::container::flat_set<std::string> calledConnections; 10725b4aa86bSJames Feist for (const auto& pathGroup : subtree) 10735b4aa86bSJames Feist { 10745b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 10755b4aa86bSJames Feist { 10766bce33bcSJames Feist auto findConnection = 10776bce33bcSJames Feist calledConnections.find(connectionGroup.first); 10786bce33bcSJames Feist if (findConnection != calledConnections.end()) 10796bce33bcSJames Feist { 10806bce33bcSJames Feist break; 10816bce33bcSJames Feist } 108273df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 10835b4aa86bSJames Feist { 10845b4aa86bSJames Feist if (interface == objectManagerIface) 10855b4aa86bSJames Feist { 108673df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 10875b4aa86bSJames Feist } 10885b4aa86bSJames Feist // this list is alphabetical, so we 10895b4aa86bSJames Feist // should have found the objMgr by now 10905b4aa86bSJames Feist if (interface == pidConfigurationIface || 1091b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1092b7a08d04SJames Feist interface == stepwiseConfigurationIface) 10935b4aa86bSJames Feist { 10945b4aa86bSJames Feist auto findObjMgr = 10955b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 10965b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 10975b4aa86bSJames Feist { 10985b4aa86bSJames Feist BMCWEB_LOG_DEBUG << connectionGroup.first 10995b4aa86bSJames Feist << "Has no Object Manager"; 11005b4aa86bSJames Feist continue; 11015b4aa86bSJames Feist } 11026bce33bcSJames Feist 11036bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 11046bce33bcSJames Feist 110573df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 110673df0db0SJames Feist currentProfile, supportedProfiles, 110773df0db0SJames Feist asyncResp); 11085b4aa86bSJames Feist break; 11095b4aa86bSJames Feist } 11105b4aa86bSJames Feist } 11115b4aa86bSJames Feist } 11125b4aa86bSJames Feist } 111373df0db0SJames Feist } 111473df0db0SJames Feist 111573df0db0SJames Feist std::vector<std::string> supportedProfiles; 111673df0db0SJames Feist std::string currentProfile; 111773df0db0SJames Feist crow::openbmc_mapper::GetSubTreeType subtree; 111873df0db0SJames Feist std::shared_ptr<AsyncResp> asyncResp; 111973df0db0SJames Feist }; 112073df0db0SJames Feist 112173df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 112273df0db0SJames Feist { 112373df0db0SJames Feist 112473df0db0SJames Feist SetPIDValues(const std::shared_ptr<AsyncResp>& asyncResp, 112573df0db0SJames Feist nlohmann::json& data) : 112673df0db0SJames Feist asyncResp(asyncResp) 112773df0db0SJames Feist { 112873df0db0SJames Feist 112973df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 113073df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 113173df0db0SJames Feist std::optional<nlohmann::json> fanZones; 113273df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 113373df0db0SJames Feist 113473df0db0SJames Feist if (!redfish::json_util::readJson( 113573df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 113673df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 113773df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 113873df0db0SJames Feist { 113973df0db0SJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 114073df0db0SJames Feist << data.dump(); 114173df0db0SJames Feist return; 114273df0db0SJames Feist } 114373df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 114473df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 114573df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 114673df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 114773df0db0SJames Feist std::move(stepwiseControllers)); 114873df0db0SJames Feist } 114973df0db0SJames Feist void run() 115073df0db0SJames Feist { 115173df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 115273df0db0SJames Feist { 115373df0db0SJames Feist return; 115473df0db0SJames Feist } 115573df0db0SJames Feist 115673df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 115773df0db0SJames Feist 115873df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 115973df0db0SJames Feist // interface gets more traction 116073df0db0SJames Feist crow::connections::systemBus->async_method_call( 116173df0db0SJames Feist [self](const boost::system::error_code ec, 116273df0db0SJames Feist dbus::utility::ManagedObjectType& managedObj) { 116373df0db0SJames Feist if (ec) 116473df0db0SJames Feist { 116573df0db0SJames Feist BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; 116673df0db0SJames Feist messages::internalError(self->asyncResp->res); 116773df0db0SJames Feist return; 116873df0db0SJames Feist } 116973df0db0SJames Feist self->managedObj = std::move(managedObj); 117073df0db0SJames Feist }, 117173df0db0SJames Feist "xyz.openbmc_project.EntityManager", "/", objectManagerIface, 117273df0db0SJames Feist "GetManagedObjects"); 117373df0db0SJames Feist 117473df0db0SJames Feist // at the same time get the profile information 117573df0db0SJames Feist crow::connections::systemBus->async_method_call( 117673df0db0SJames Feist [self](const boost::system::error_code ec, 117773df0db0SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 117873df0db0SJames Feist if (ec || subtree.empty()) 117973df0db0SJames Feist { 118073df0db0SJames Feist return; 118173df0db0SJames Feist } 118273df0db0SJames Feist if (subtree[0].second.empty()) 118373df0db0SJames Feist { 118473df0db0SJames Feist // invalid mapper response, should never happen 118573df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; 118673df0db0SJames Feist messages::internalError(self->asyncResp->res); 118773df0db0SJames Feist return; 118873df0db0SJames Feist } 118973df0db0SJames Feist 119073df0db0SJames Feist const std::string& path = subtree[0].first; 119173df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 119273df0db0SJames Feist crow::connections::systemBus->async_method_call( 119373df0db0SJames Feist [self, path, owner]( 119473df0db0SJames Feist const boost::system::error_code ec, 119573df0db0SJames Feist const boost::container::flat_map< 119673df0db0SJames Feist std::string, std::variant<std::vector<std::string>, 119773df0db0SJames Feist std::string>>& resp) { 119873df0db0SJames Feist if (ec) 119973df0db0SJames Feist { 120073df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Can't get " 120173df0db0SJames Feist "thermalModeIface " 120273df0db0SJames Feist << path; 120373df0db0SJames Feist messages::internalError(self->asyncResp->res); 120473df0db0SJames Feist return; 120573df0db0SJames Feist } 120673df0db0SJames Feist const std::string* current; 120773df0db0SJames Feist const std::vector<std::string>* supported; 120873df0db0SJames Feist for (auto& [key, value] : resp) 120973df0db0SJames Feist { 121073df0db0SJames Feist if (key == "Current") 121173df0db0SJames Feist { 121273df0db0SJames Feist current = std::get_if<std::string>(&value); 121373df0db0SJames Feist if (current == nullptr) 121473df0db0SJames Feist { 121573df0db0SJames Feist BMCWEB_LOG_ERROR 121673df0db0SJames Feist << "SetPIDValues: thermal mode " 121773df0db0SJames Feist "iface invalid " 121873df0db0SJames Feist << path; 121973df0db0SJames Feist messages::internalError( 122073df0db0SJames Feist self->asyncResp->res); 122173df0db0SJames Feist return; 122273df0db0SJames Feist } 122373df0db0SJames Feist } 122473df0db0SJames Feist if (key == "Supported") 122573df0db0SJames Feist { 122673df0db0SJames Feist supported = 122773df0db0SJames Feist std::get_if<std::vector<std::string>>( 122873df0db0SJames Feist &value); 122973df0db0SJames Feist if (supported == nullptr) 123073df0db0SJames Feist { 123173df0db0SJames Feist BMCWEB_LOG_ERROR 123273df0db0SJames Feist << "SetPIDValues: thermal mode " 123373df0db0SJames Feist "iface invalid" 123473df0db0SJames Feist << path; 123573df0db0SJames Feist messages::internalError( 123673df0db0SJames Feist self->asyncResp->res); 123773df0db0SJames Feist return; 123873df0db0SJames Feist } 123973df0db0SJames Feist } 124073df0db0SJames Feist } 124173df0db0SJames Feist if (current == nullptr || supported == nullptr) 124273df0db0SJames Feist { 124373df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: thermal mode " 124473df0db0SJames Feist "iface invalid " 124573df0db0SJames Feist << path; 124673df0db0SJames Feist messages::internalError(self->asyncResp->res); 124773df0db0SJames Feist return; 124873df0db0SJames Feist } 124973df0db0SJames Feist self->currentProfile = *current; 125073df0db0SJames Feist self->supportedProfiles = *supported; 125173df0db0SJames Feist self->profileConnection = owner; 125273df0db0SJames Feist self->profilePath = path; 125373df0db0SJames Feist }, 125473df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 125573df0db0SJames Feist thermalModeIface); 12565b4aa86bSJames Feist }, 12575b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", 12585b4aa86bSJames Feist "/xyz/openbmc_project/object_mapper", 12595b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 126073df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 126173df0db0SJames Feist } 126273df0db0SJames Feist ~SetPIDValues() 126373df0db0SJames Feist { 126473df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 126573df0db0SJames Feist { 126673df0db0SJames Feist return; 12675b4aa86bSJames Feist } 12685b4aa86bSJames Feist 126973df0db0SJames Feist std::shared_ptr<AsyncResp> response = asyncResp; 127073df0db0SJames Feist 127173df0db0SJames Feist if (profile) 127273df0db0SJames Feist { 127373df0db0SJames Feist if (std::find(supportedProfiles.begin(), supportedProfiles.end(), 127473df0db0SJames Feist *profile) == supportedProfiles.end()) 127573df0db0SJames Feist { 127673df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 127773df0db0SJames Feist *profile); 127873df0db0SJames Feist return; 127973df0db0SJames Feist } 128073df0db0SJames Feist currentProfile = *profile; 128173df0db0SJames Feist crow::connections::systemBus->async_method_call( 128273df0db0SJames Feist [response](const boost::system::error_code ec) { 128373df0db0SJames Feist if (ec) 128473df0db0SJames Feist { 128573df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching profile" << ec; 128673df0db0SJames Feist messages::internalError(response->res); 128773df0db0SJames Feist } 128873df0db0SJames Feist }, 128973df0db0SJames Feist profileConnection, profilePath, 129073df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", thermalModeIface, 129173df0db0SJames Feist "Current", std::variant<std::string>(*profile)); 129273df0db0SJames Feist } 129373df0db0SJames Feist 129473df0db0SJames Feist for (auto& containerPair : configuration) 129573df0db0SJames Feist { 129673df0db0SJames Feist auto& container = containerPair.second; 129773df0db0SJames Feist if (!container) 129873df0db0SJames Feist { 129973df0db0SJames Feist continue; 130073df0db0SJames Feist } 130173df0db0SJames Feist std::string& type = containerPair.first; 130273df0db0SJames Feist 130373df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 130473df0db0SJames Feist it != container->end(); it++) 130573df0db0SJames Feist { 130673df0db0SJames Feist const auto& name = it.key(); 130773df0db0SJames Feist auto pathItr = 130873df0db0SJames Feist std::find_if(managedObj.begin(), managedObj.end(), 130973df0db0SJames Feist [&name](const auto& obj) { 131073df0db0SJames Feist return boost::algorithm::ends_with( 131173df0db0SJames Feist obj.first.str, "/" + name); 131273df0db0SJames Feist }); 131373df0db0SJames Feist boost::container::flat_map<std::string, 131473df0db0SJames Feist dbus::utility::DbusVariantType> 131573df0db0SJames Feist output; 131673df0db0SJames Feist 131773df0db0SJames Feist output.reserve(16); // The pid interface length 131873df0db0SJames Feist 131973df0db0SJames Feist // determines if we're patching entity-manager or 132073df0db0SJames Feist // creating a new object 132173df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 132273df0db0SJames Feist std::string iface; 132373df0db0SJames Feist if (type == "PidControllers" || type == "FanControllers") 132473df0db0SJames Feist { 132573df0db0SJames Feist iface = pidConfigurationIface; 132673df0db0SJames Feist if (!createNewObject && 132773df0db0SJames Feist pathItr->second.find(pidConfigurationIface) == 132873df0db0SJames Feist pathItr->second.end()) 132973df0db0SJames Feist { 133073df0db0SJames Feist createNewObject = true; 133173df0db0SJames Feist } 133273df0db0SJames Feist } 133373df0db0SJames Feist else if (type == "FanZones") 133473df0db0SJames Feist { 133573df0db0SJames Feist iface = pidZoneConfigurationIface; 133673df0db0SJames Feist if (!createNewObject && 133773df0db0SJames Feist pathItr->second.find(pidZoneConfigurationIface) == 133873df0db0SJames Feist pathItr->second.end()) 133973df0db0SJames Feist { 134073df0db0SJames Feist 134173df0db0SJames Feist createNewObject = true; 134273df0db0SJames Feist } 134373df0db0SJames Feist } 134473df0db0SJames Feist else if (type == "StepwiseControllers") 134573df0db0SJames Feist { 134673df0db0SJames Feist iface = stepwiseConfigurationIface; 134773df0db0SJames Feist if (!createNewObject && 134873df0db0SJames Feist pathItr->second.find(stepwiseConfigurationIface) == 134973df0db0SJames Feist pathItr->second.end()) 135073df0db0SJames Feist { 135173df0db0SJames Feist createNewObject = true; 135273df0db0SJames Feist } 135373df0db0SJames Feist } 135473df0db0SJames Feist BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; 135573df0db0SJames Feist output["Name"] = boost::replace_all_copy(name, "_", " "); 135673df0db0SJames Feist 135773df0db0SJames Feist std::string chassis; 135873df0db0SJames Feist CreatePIDRet ret = createPidInterface( 135973df0db0SJames Feist response, type, it, pathItr->first.str, managedObj, 136073df0db0SJames Feist createNewObject, output, chassis, currentProfile); 136173df0db0SJames Feist if (ret == CreatePIDRet::fail) 136273df0db0SJames Feist { 136373df0db0SJames Feist return; 136473df0db0SJames Feist } 136573df0db0SJames Feist else if (ret == CreatePIDRet::del) 136673df0db0SJames Feist { 136773df0db0SJames Feist continue; 136873df0db0SJames Feist } 136973df0db0SJames Feist 137073df0db0SJames Feist if (!createNewObject) 137173df0db0SJames Feist { 137273df0db0SJames Feist for (const auto& property : output) 137373df0db0SJames Feist { 137473df0db0SJames Feist crow::connections::systemBus->async_method_call( 137573df0db0SJames Feist [response, 137673df0db0SJames Feist propertyName{std::string(property.first)}]( 137773df0db0SJames Feist const boost::system::error_code ec) { 137873df0db0SJames Feist if (ec) 137973df0db0SJames Feist { 138073df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching " 138173df0db0SJames Feist << propertyName << ": " 138273df0db0SJames Feist << ec; 138373df0db0SJames Feist messages::internalError(response->res); 138473df0db0SJames Feist return; 138573df0db0SJames Feist } 138673df0db0SJames Feist messages::success(response->res); 138773df0db0SJames Feist }, 138873df0db0SJames Feist "xyz.openbmc_project.EntityManager", 138973df0db0SJames Feist pathItr->first.str, 139073df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", iface, 139173df0db0SJames Feist property.first, property.second); 139273df0db0SJames Feist } 139373df0db0SJames Feist } 139473df0db0SJames Feist else 139573df0db0SJames Feist { 139673df0db0SJames Feist if (chassis.empty()) 139773df0db0SJames Feist { 139873df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config"; 139973df0db0SJames Feist messages::invalidObject(response->res, name); 140073df0db0SJames Feist return; 140173df0db0SJames Feist } 140273df0db0SJames Feist 140373df0db0SJames Feist bool foundChassis = false; 140473df0db0SJames Feist for (const auto& obj : managedObj) 140573df0db0SJames Feist { 140673df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 140773df0db0SJames Feist { 140873df0db0SJames Feist chassis = obj.first.str; 140973df0db0SJames Feist foundChassis = true; 141073df0db0SJames Feist break; 141173df0db0SJames Feist } 141273df0db0SJames Feist } 141373df0db0SJames Feist if (!foundChassis) 141473df0db0SJames Feist { 141573df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; 141673df0db0SJames Feist messages::resourceMissingAtURI( 141773df0db0SJames Feist response->res, "/redfish/v1/Chassis/" + chassis); 141873df0db0SJames Feist return; 141973df0db0SJames Feist } 142073df0db0SJames Feist 142173df0db0SJames Feist crow::connections::systemBus->async_method_call( 142273df0db0SJames Feist [response](const boost::system::error_code ec) { 142373df0db0SJames Feist if (ec) 142473df0db0SJames Feist { 142573df0db0SJames Feist BMCWEB_LOG_ERROR << "Error Adding Pid Object " 142673df0db0SJames Feist << ec; 142773df0db0SJames Feist messages::internalError(response->res); 142873df0db0SJames Feist return; 142973df0db0SJames Feist } 143073df0db0SJames Feist messages::success(response->res); 143173df0db0SJames Feist }, 143273df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 143373df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 143473df0db0SJames Feist } 143573df0db0SJames Feist } 143673df0db0SJames Feist } 143773df0db0SJames Feist } 143873df0db0SJames Feist std::shared_ptr<AsyncResp> asyncResp; 143973df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 144073df0db0SJames Feist configuration; 144173df0db0SJames Feist std::optional<std::string> profile; 144273df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 144373df0db0SJames Feist std::vector<std::string> supportedProfiles; 144473df0db0SJames Feist std::string currentProfile; 144573df0db0SJames Feist std::string profileConnection; 144673df0db0SJames Feist std::string profilePath; 144773df0db0SJames Feist }; 144873df0db0SJames Feist 144973df0db0SJames Feist class Manager : public Node 145073df0db0SJames Feist { 145173df0db0SJames Feist public: 145273df0db0SJames Feist Manager(CrowApp& app) : Node(app, "/redfish/v1/Managers/bmc/") 145373df0db0SJames Feist { 145473df0db0SJames Feist uuid = app.template getMiddleware<crow::persistent_data::Middleware>() 145573df0db0SJames Feist .systemUuid; 145673df0db0SJames Feist entityPrivileges = { 145773df0db0SJames Feist {boost::beast::http::verb::get, {{"Login"}}}, 145873df0db0SJames Feist {boost::beast::http::verb::head, {{"Login"}}}, 145973df0db0SJames Feist {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 146073df0db0SJames Feist {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 146173df0db0SJames Feist {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 146273df0db0SJames Feist {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 146373df0db0SJames Feist } 146473df0db0SJames Feist 146573df0db0SJames Feist private: 146655c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 14671abe55efSEd Tanous const std::vector<std::string>& params) override 14681abe55efSEd Tanous { 14690f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 14700f74e643SEd Tanous res.jsonValue["@odata.type"] = "#Manager.v1_3_0.Manager"; 14710f74e643SEd Tanous res.jsonValue["@odata.context"] = 14720f74e643SEd Tanous "/redfish/v1/$metadata#Manager.Manager"; 14730f74e643SEd Tanous res.jsonValue["Id"] = "bmc"; 14740f74e643SEd Tanous res.jsonValue["Name"] = "OpenBmc Manager"; 14750f74e643SEd Tanous res.jsonValue["Description"] = "Baseboard Management Controller"; 14760f74e643SEd Tanous res.jsonValue["PowerState"] = "On"; 1477029573d4SEd Tanous res.jsonValue["Status"] = {{"State", "Enabled"}, {"Health", "OK"}}; 14780f74e643SEd Tanous res.jsonValue["ManagerType"] = "BMC"; 14793602e232SEd Tanous res.jsonValue["UUID"] = systemd_utils::getUuid(); 14803602e232SEd Tanous res.jsonValue["ServiceEntryPointUUID"] = uuid; 14810f74e643SEd Tanous res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 14820f74e643SEd Tanous 14830f74e643SEd Tanous res.jsonValue["LogServices"] = { 14840f74e643SEd Tanous {"@odata.id", "/redfish/v1/Managers/bmc/LogServices"}}; 14850f74e643SEd Tanous 14860f74e643SEd Tanous res.jsonValue["NetworkProtocol"] = { 14870f74e643SEd Tanous {"@odata.id", "/redfish/v1/Managers/bmc/NetworkProtocol"}}; 14880f74e643SEd Tanous 14890f74e643SEd Tanous res.jsonValue["EthernetInterfaces"] = { 14900f74e643SEd Tanous {"@odata.id", "/redfish/v1/Managers/bmc/EthernetInterfaces"}}; 14910f74e643SEd Tanous // default oem data 14920f74e643SEd Tanous nlohmann::json& oem = res.jsonValue["Oem"]; 14930f74e643SEd Tanous nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 14940f74e643SEd Tanous oem["@odata.type"] = "#OemManager.Oem"; 14950f74e643SEd Tanous oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 14960f74e643SEd Tanous oem["@odata.context"] = "/redfish/v1/$metadata#OemManager.Oem"; 14970f74e643SEd Tanous oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 14980f74e643SEd Tanous oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 14990f74e643SEd Tanous oemOpenbmc["@odata.context"] = 15000f74e643SEd Tanous "/redfish/v1/$metadata#OemManager.OpenBmc"; 15010f74e643SEd Tanous 1502ed5befbdSJennifer Lee // Update Actions object. 15030f74e643SEd Tanous nlohmann::json& manager_reset = 15040f74e643SEd Tanous res.jsonValue["Actions"]["#Manager.Reset"]; 1505ed5befbdSJennifer Lee manager_reset["target"] = 1506ed5befbdSJennifer Lee "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 1507ed5befbdSJennifer Lee manager_reset["ResetType@Redfish.AllowableValues"] = { 1508ed5befbdSJennifer Lee "GracefulRestart"}; 1509ca537928SJennifer Lee 1510cb92c03bSAndrew Geissler res.jsonValue["DateTime"] = crow::utility::dateTimeNow(); 1511474bfad5SSantosh Puranik 1512474bfad5SSantosh Puranik // Fill in GraphicalConsole and SerialConsole info 1513474bfad5SSantosh Puranik res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 1514474bfad5SSantosh Puranik res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = {"IPMI", 1515474bfad5SSantosh Puranik "SSH"}; 1516ef47bb18SSantosh Puranik #ifdef BMCWEB_ENABLE_KVM 1517ef47bb18SSantosh Puranik res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 1518ef47bb18SSantosh Puranik res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"}; 1519ef47bb18SSantosh Puranik #endif // BMCWEB_ENABLE_KVM 1520474bfad5SSantosh Puranik 1521603a6640SGunnar Mills res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 1522603a6640SGunnar Mills res.jsonValue["Links"]["ManagerForServers"] = { 1523603a6640SGunnar Mills {{"@odata.id", "/redfish/v1/Systems/system"}}}; 152426f03899SShawn McCarney 1525ed5befbdSJennifer Lee std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 15265b4aa86bSJames Feist 1527b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1528b49ac873SJames Feist health->isManagersHealth = true; 1529b49ac873SJames Feist health->populate(); 1530b49ac873SJames Feist 1531e90c5052SAndrew Geissler fw_util::getActiveFwVersion(asyncResp, fw_util::bmcPurpose, 1532e90c5052SAndrew Geissler "FirmwareVersion"); 15330f6b00bdSJames Feist 153473df0db0SJames Feist auto pids = std::make_shared<GetPIDValues>(asyncResp); 153573df0db0SJames Feist pids->run(); 1536c5d03ff4SJennifer Lee 1537c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string& chassisId, 1538c5d03ff4SJennifer Lee const std::shared_ptr<AsyncResp> aRsp) { 1539c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 1540c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["ManagerForChassis"] = { 1541c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1542*2c0feb00SJason M. Bills aRsp->res.jsonValue["Links"]["ManagerInChassis"] = { 1543*2c0feb00SJason M. Bills {"@odata.id", "/redfish/v1/Chassis/" + chassisId}}; 1544c5d03ff4SJennifer Lee }); 15450f6b00bdSJames Feist 15460f6b00bdSJames Feist static bool started = false; 15470f6b00bdSJames Feist 15480f6b00bdSJames Feist if (!started) 15490f6b00bdSJames Feist { 15500f6b00bdSJames Feist crow::connections::systemBus->async_method_call( 15510f6b00bdSJames Feist [asyncResp](const boost::system::error_code ec, 15520f6b00bdSJames Feist const std::variant<double>& resp) { 15530f6b00bdSJames Feist if (ec) 15540f6b00bdSJames Feist { 15550f6b00bdSJames Feist BMCWEB_LOG_ERROR << "Error while getting progress"; 15560f6b00bdSJames Feist messages::internalError(asyncResp->res); 15570f6b00bdSJames Feist return; 15580f6b00bdSJames Feist } 15590f6b00bdSJames Feist const double* val = std::get_if<double>(&resp); 15600f6b00bdSJames Feist if (val == nullptr) 15610f6b00bdSJames Feist { 15620f6b00bdSJames Feist BMCWEB_LOG_ERROR 15630f6b00bdSJames Feist << "Invalid response while getting progress"; 15640f6b00bdSJames Feist messages::internalError(asyncResp->res); 15650f6b00bdSJames Feist return; 15660f6b00bdSJames Feist } 15670f6b00bdSJames Feist if (*val < 1.0) 15680f6b00bdSJames Feist { 15690f6b00bdSJames Feist asyncResp->res.jsonValue["Status"]["State"] = 15700f6b00bdSJames Feist "Starting"; 15710f6b00bdSJames Feist started = true; 15720f6b00bdSJames Feist } 15730f6b00bdSJames Feist }, 15740f6b00bdSJames Feist "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 15750f6b00bdSJames Feist "org.freedesktop.DBus.Properties", "Get", 15760f6b00bdSJames Feist "org.freedesktop.systemd1.Manager", "Progress"); 15770f6b00bdSJames Feist } 157883ff9ab6SJames Feist } 15795b4aa86bSJames Feist 15805b4aa86bSJames Feist void doPatch(crow::Response& res, const crow::Request& req, 15815b4aa86bSJames Feist const std::vector<std::string>& params) override 15825b4aa86bSJames Feist { 15830627a2c7SEd Tanous std::optional<nlohmann::json> oem; 1584af5d6058SSantosh Puranik std::optional<std::string> datetime; 15850627a2c7SEd Tanous 1586af5d6058SSantosh Puranik if (!json_util::readJson(req, res, "Oem", oem, "DateTime", datetime)) 158783ff9ab6SJames Feist { 158883ff9ab6SJames Feist return; 158983ff9ab6SJames Feist } 15900627a2c7SEd Tanous 159183ff9ab6SJames Feist std::shared_ptr<AsyncResp> response = std::make_shared<AsyncResp>(res); 15920627a2c7SEd Tanous 15930627a2c7SEd Tanous if (oem) 159483ff9ab6SJames Feist { 15955f2caaefSJames Feist std::optional<nlohmann::json> openbmc; 159643b761d0SEd Tanous if (!redfish::json_util::readJson(*oem, res, "OpenBmc", openbmc)) 159783ff9ab6SJames Feist { 159843b761d0SEd Tanous BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property " 159943b761d0SEd Tanous << oem->dump(); 160083ff9ab6SJames Feist return; 160183ff9ab6SJames Feist } 16025f2caaefSJames Feist if (openbmc) 160383ff9ab6SJames Feist { 16045f2caaefSJames Feist std::optional<nlohmann::json> fan; 160543b761d0SEd Tanous if (!redfish::json_util::readJson(*openbmc, res, "Fan", fan)) 160683ff9ab6SJames Feist { 16075f2caaefSJames Feist BMCWEB_LOG_ERROR << "Line:" << __LINE__ 16085f2caaefSJames Feist << ", Illegal Property " 16095f2caaefSJames Feist << openbmc->dump(); 161083ff9ab6SJames Feist return; 161183ff9ab6SJames Feist } 16125f2caaefSJames Feist if (fan) 161383ff9ab6SJames Feist { 161473df0db0SJames Feist auto pid = std::make_shared<SetPIDValues>(response, *fan); 161573df0db0SJames Feist pid->run(); 161683ff9ab6SJames Feist } 161783ff9ab6SJames Feist } 161883ff9ab6SJames Feist } 1619af5d6058SSantosh Puranik if (datetime) 1620af5d6058SSantosh Puranik { 1621af5d6058SSantosh Puranik setDateTime(response, std::move(*datetime)); 1622af5d6058SSantosh Puranik } 1623af5d6058SSantosh Puranik } 1624af5d6058SSantosh Puranik 1625af5d6058SSantosh Puranik void setDateTime(std::shared_ptr<AsyncResp> aResp, 1626af5d6058SSantosh Puranik std::string datetime) const 1627af5d6058SSantosh Puranik { 1628af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Set date time: " << datetime; 1629af5d6058SSantosh Puranik 1630af5d6058SSantosh Puranik std::stringstream stream(datetime); 1631af5d6058SSantosh Puranik // Convert from ISO 8601 to boost local_time 1632af5d6058SSantosh Puranik // (BMC only has time in UTC) 1633af5d6058SSantosh Puranik boost::posix_time::ptime posixTime; 1634af5d6058SSantosh Puranik boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); 1635af5d6058SSantosh Puranik // Facet gets deleted with the stringsteam 1636af5d6058SSantosh Puranik auto ifc = std::make_unique<boost::local_time::local_time_input_facet>( 1637af5d6058SSantosh Puranik "%Y-%m-%d %H:%M:%S%F %ZP"); 1638af5d6058SSantosh Puranik stream.imbue(std::locale(stream.getloc(), ifc.release())); 1639af5d6058SSantosh Puranik 1640af5d6058SSantosh Puranik boost::local_time::local_date_time ldt( 1641af5d6058SSantosh Puranik boost::local_time::not_a_date_time); 1642af5d6058SSantosh Puranik 1643af5d6058SSantosh Puranik if (stream >> ldt) 1644af5d6058SSantosh Puranik { 1645af5d6058SSantosh Puranik posixTime = ldt.utc_time(); 1646af5d6058SSantosh Puranik boost::posix_time::time_duration dur = posixTime - epoch; 1647af5d6058SSantosh Puranik uint64_t durMicroSecs = 1648af5d6058SSantosh Puranik static_cast<uint64_t>(dur.total_microseconds()); 1649af5d6058SSantosh Puranik crow::connections::systemBus->async_method_call( 1650af5d6058SSantosh Puranik [aResp{std::move(aResp)}, datetime{std::move(datetime)}]( 1651af5d6058SSantosh Puranik const boost::system::error_code ec) { 1652af5d6058SSantosh Puranik if (ec) 1653af5d6058SSantosh Puranik { 1654af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " 1655af5d6058SSantosh Puranik "DBUS response error " 1656af5d6058SSantosh Puranik << ec; 1657af5d6058SSantosh Puranik messages::internalError(aResp->res); 1658af5d6058SSantosh Puranik return; 1659af5d6058SSantosh Puranik } 1660af5d6058SSantosh Puranik aResp->res.jsonValue["DateTime"] = datetime; 1661af5d6058SSantosh Puranik }, 1662af5d6058SSantosh Puranik "xyz.openbmc_project.Time.Manager", 1663af5d6058SSantosh Puranik "/xyz/openbmc_project/time/bmc", 1664af5d6058SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1665af5d6058SSantosh Puranik "xyz.openbmc_project.Time.EpochTime", "Elapsed", 1666af5d6058SSantosh Puranik std::variant<uint64_t>(durMicroSecs)); 1667af5d6058SSantosh Puranik } 1668af5d6058SSantosh Puranik else 1669af5d6058SSantosh Puranik { 1670af5d6058SSantosh Puranik messages::propertyValueFormatError(aResp->res, datetime, 1671af5d6058SSantosh Puranik "DateTime"); 1672af5d6058SSantosh Puranik return; 1673af5d6058SSantosh Puranik } 167483ff9ab6SJames Feist } 16759c310685SBorawski.Lukasz 16760f74e643SEd Tanous std::string uuid; 16779c310685SBorawski.Lukasz }; 16789c310685SBorawski.Lukasz 16791abe55efSEd Tanous class ManagerCollection : public Node 16801abe55efSEd Tanous { 16819c310685SBorawski.Lukasz public: 16821abe55efSEd Tanous ManagerCollection(CrowApp& app) : Node(app, "/redfish/v1/Managers/") 16831abe55efSEd Tanous { 1684a434f2bdSEd Tanous entityPrivileges = { 1685a434f2bdSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 1686e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 1687e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1688e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1689e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1690e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16919c310685SBorawski.Lukasz } 16929c310685SBorawski.Lukasz 16939c310685SBorawski.Lukasz private: 169455c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 16951abe55efSEd Tanous const std::vector<std::string>& params) override 16961abe55efSEd Tanous { 169783ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 169883ff9ab6SJames Feist // because it has a duplicate entry for members 169955c7b7a2SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 170055c7b7a2SEd Tanous res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection"; 170155c7b7a2SEd Tanous res.jsonValue["@odata.context"] = 170255c7b7a2SEd Tanous "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; 170355c7b7a2SEd Tanous res.jsonValue["Name"] = "Manager Collection"; 170455c7b7a2SEd Tanous res.jsonValue["Members@odata.count"] = 1; 170555c7b7a2SEd Tanous res.jsonValue["Members"] = { 17065b4aa86bSJames Feist {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 17079c310685SBorawski.Lukasz res.end(); 17089c310685SBorawski.Lukasz } 17099c310685SBorawski.Lukasz }; 17109c310685SBorawski.Lukasz } // namespace redfish 1711