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 1813451e39SWilly Tu #include "bmcweb_config.h" 1913451e39SWilly Tu 20a51fc2d2SSui Chen #include "app.hpp" 21a51fc2d2SSui Chen #include "dbus_utility.hpp" 22b49ac873SJames Feist #include "health.hpp" 23a51fc2d2SSui Chen #include "query.hpp" 24c5d03ff4SJennifer Lee #include "redfish_util.hpp" 25a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 26fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp" 273ccb3adbSEd Tanous #include "utils/json_utils.hpp" 28a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 29a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 302b82937eSEd Tanous #include "utils/time_utils.hpp" 319c310685SBorawski.Lukasz 32e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 33ef4c65b7SEd Tanous #include <boost/url/format.hpp> 34fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 35fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 361214b7e7SGunnar Mills 37a170f275SEd Tanous #include <algorithm> 38e99073f5SGeorge Liu #include <array> 394bfefa74SGunnar Mills #include <cstdint> 401214b7e7SGunnar Mills #include <memory> 419970e93fSKonstantin Aladyshev #include <optional> 423544d2a7SEd Tanous #include <ranges> 431214b7e7SGunnar Mills #include <sstream> 449970e93fSKonstantin Aladyshev #include <string> 45e99073f5SGeorge Liu #include <string_view> 46abf2add6SEd Tanous #include <variant> 475b4aa86bSJames Feist 481abe55efSEd Tanous namespace redfish 491abe55efSEd Tanous { 50ed5befbdSJennifer Lee 51ed5befbdSJennifer Lee /** 522a5c4407SGunnar Mills * Function reboots the BMC. 532a5c4407SGunnar Mills * 542a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 55ed5befbdSJennifer Lee */ 568d1b46d7Szhanghch05 inline void 578d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 58ed5befbdSJennifer Lee { 59ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 60ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 61ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 62ed5befbdSJennifer Lee const std::string& propertyValue = 63ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 64ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 65ed5befbdSJennifer Lee 66ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 679ae226faSGeorge Liu sdbusplus::asio::setProperty( 689ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 699ae226faSGeorge Liu destProperty, propertyValue, 705e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 71ed5befbdSJennifer Lee // Use "Set" method to set the property value. 72ed5befbdSJennifer Lee if (ec) 73ed5befbdSJennifer Lee { 7462598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 75ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 76ed5befbdSJennifer Lee return; 77ed5befbdSJennifer Lee } 78ed5befbdSJennifer Lee 79ed5befbdSJennifer Lee messages::success(asyncResp->res); 809ae226faSGeorge Liu }); 81ed5befbdSJennifer Lee } 822a5c4407SGunnar Mills 838d1b46d7Szhanghch05 inline void 848d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 85f92af389SJayaprakash Mutyala { 86f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 87f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 88f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 89f92af389SJayaprakash Mutyala const std::string& propertyValue = 90f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 91f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 92f92af389SJayaprakash Mutyala 93f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 949ae226faSGeorge Liu sdbusplus::asio::setProperty( 959ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 969ae226faSGeorge Liu destProperty, propertyValue, 975e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 98f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 99f92af389SJayaprakash Mutyala if (ec) 100f92af389SJayaprakash Mutyala { 10162598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 102f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 103f92af389SJayaprakash Mutyala return; 104f92af389SJayaprakash Mutyala } 105f92af389SJayaprakash Mutyala 106f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 1079ae226faSGeorge Liu }); 108f92af389SJayaprakash Mutyala } 109f92af389SJayaprakash Mutyala 1102a5c4407SGunnar Mills /** 1112a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1122a5c4407SGunnar Mills * action. 1132a5c4407SGunnar Mills */ 1147e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1152a5c4407SGunnar Mills { 1162a5c4407SGunnar Mills /** 1172a5c4407SGunnar Mills * Function handles POST method request. 1182a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 119f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1202a5c4407SGunnar Mills */ 1217e860f15SJohn Edward Broadbent 1227e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 123ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 12545ca1b86SEd Tanous [&app](const crow::Request& req, 1267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 12845ca1b86SEd Tanous { 12945ca1b86SEd Tanous return; 13045ca1b86SEd Tanous } 13162598e31SEd Tanous BMCWEB_LOG_DEBUG("Post Manager Reset."); 1322a5c4407SGunnar Mills 1332a5c4407SGunnar Mills std::string resetType; 1342a5c4407SGunnar Mills 13515ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1367e860f15SJohn Edward Broadbent resetType)) 1372a5c4407SGunnar Mills { 1382a5c4407SGunnar Mills return; 1392a5c4407SGunnar Mills } 1402a5c4407SGunnar Mills 141f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 142f92af389SJayaprakash Mutyala { 14362598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 144f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 145f92af389SJayaprakash Mutyala return; 146f92af389SJayaprakash Mutyala } 1473174e4dfSEd Tanous if (resetType == "ForceRestart") 148f92af389SJayaprakash Mutyala { 14962598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 150f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 151f92af389SJayaprakash Mutyala return; 152f92af389SJayaprakash Mutyala } 15362598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType); 1542a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1552a5c4407SGunnar Mills "ResetType"); 1562a5c4407SGunnar Mills 1572a5c4407SGunnar Mills return; 1587e860f15SJohn Edward Broadbent }); 1592a5c4407SGunnar Mills } 160ed5befbdSJennifer Lee 1613e40fc74SGunnar Mills /** 1623e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1633e40fc74SGunnar Mills * action. 1643e40fc74SGunnar Mills */ 1657e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1663e40fc74SGunnar Mills { 1673e40fc74SGunnar Mills /** 1683e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1693e40fc74SGunnar Mills * 1703e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1713e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1723e40fc74SGunnar Mills * 1733e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1743e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1753e40fc74SGunnar Mills * 1763e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1773e40fc74SGunnar Mills */ 1787e860f15SJohn Edward Broadbent 1797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1807e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 181ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 18345ca1b86SEd Tanous [&app](const crow::Request& req, 1847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1853ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18645ca1b86SEd Tanous { 18745ca1b86SEd Tanous return; 18845ca1b86SEd Tanous } 18962598e31SEd Tanous BMCWEB_LOG_DEBUG("Post ResetToDefaults."); 1903e40fc74SGunnar Mills 1919970e93fSKonstantin Aladyshev std::optional<std::string> resetType; 1929970e93fSKonstantin Aladyshev std::optional<std::string> resetToDefaultsType; 1933e40fc74SGunnar Mills 1949970e93fSKonstantin Aladyshev if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1959970e93fSKonstantin Aladyshev resetType, "ResetToDefaultsType", 1969970e93fSKonstantin Aladyshev resetToDefaultsType)) 1973e40fc74SGunnar Mills { 1989970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Missing property ResetType."); 1993e40fc74SGunnar Mills 200002d39b4SEd Tanous messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", 2019970e93fSKonstantin Aladyshev "ResetType"); 2023e40fc74SGunnar Mills return; 2033e40fc74SGunnar Mills } 2043e40fc74SGunnar Mills 2059970e93fSKonstantin Aladyshev if (resetToDefaultsType && !resetType) 2069970e93fSKonstantin Aladyshev { 2079970e93fSKonstantin Aladyshev BMCWEB_LOG_WARNING( 2089970e93fSKonstantin Aladyshev "Using deprecated ResetToDefaultsType, should be ResetType." 2099970e93fSKonstantin Aladyshev "Support for the ResetToDefaultsType will be dropped in 2Q24"); 2109970e93fSKonstantin Aladyshev resetType = resetToDefaultsType; 2119970e93fSKonstantin Aladyshev } 2129970e93fSKonstantin Aladyshev 2133e40fc74SGunnar Mills if (resetType != "ResetAll") 2143e40fc74SGunnar Mills { 2159970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 2169970e93fSKonstantin Aladyshev *resetType); 2179970e93fSKonstantin Aladyshev messages::actionParameterNotSupported(asyncResp->res, *resetType, 2189970e93fSKonstantin Aladyshev "ResetType"); 2193e40fc74SGunnar Mills return; 2203e40fc74SGunnar Mills } 2213e40fc74SGunnar Mills 2223e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2235e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2243e40fc74SGunnar Mills if (ec) 2253e40fc74SGunnar Mills { 22662598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec); 2273e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2283e40fc74SGunnar Mills return; 2293e40fc74SGunnar Mills } 2303e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2313e40fc74SGunnar Mills // Can't erase what the BMC is running on 2323e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2333e40fc74SGunnar Mills }, 2343e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2353e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2363e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2377e860f15SJohn Edward Broadbent }); 2383e40fc74SGunnar Mills } 2393e40fc74SGunnar Mills 2401cb1a9e6SAppaRao Puli /** 2411cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2421cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2431cb1a9e6SAppaRao Puli */ 2447e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2451cb1a9e6SAppaRao Puli { 2461cb1a9e6SAppaRao Puli /** 2471cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2481cb1a9e6SAppaRao Puli */ 2497e860f15SJohn Edward Broadbent 2507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 251ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 25345ca1b86SEd Tanous [&app](const crow::Request& req, 2547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2553ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 25645ca1b86SEd Tanous { 25745ca1b86SEd Tanous return; 25845ca1b86SEd Tanous } 2591476687dSEd Tanous 2601476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2611476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 2621476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2631476687dSEd Tanous "/redfish/v1/Managers/bmc/ResetActionInfo"; 2641476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 2651476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 2661476687dSEd Tanous nlohmann::json::object_t parameter; 2671476687dSEd Tanous parameter["Name"] = "ResetType"; 2681476687dSEd Tanous parameter["Required"] = true; 2691476687dSEd Tanous parameter["DataType"] = "String"; 2701476687dSEd Tanous 2711476687dSEd Tanous nlohmann::json::array_t allowableValues; 272ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 273ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 2741476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 2751476687dSEd Tanous 2761476687dSEd Tanous nlohmann::json::array_t parameters; 277ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 2781476687dSEd Tanous 2791476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 2807e860f15SJohn Edward Broadbent }); 2811cb1a9e6SAppaRao Puli } 2821cb1a9e6SAppaRao Puli 2835b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2845b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2855b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2865b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2875b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2885b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 289b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 290b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 29173df0db0SJames Feist static constexpr const char* thermalModeIface = 29273df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2939c310685SBorawski.Lukasz 2948d1b46d7Szhanghch05 inline void 2958d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 29673df0db0SJames Feist const std::string& currentProfile, 29773df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2988d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2995b4aa86bSJames Feist { 3005eb468daSGeorge Liu sdbusplus::message::object_path objPath(path); 3015eb468daSGeorge Liu dbus::utility::getManagedObjects( 3025eb468daSGeorge Liu connection, objPath, 30373df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 3045e7e2dc5SEd Tanous const boost::system::error_code& ec, 3055b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 3065b4aa86bSJames Feist if (ec) 3075b4aa86bSJames Feist { 30862598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 309f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3105b4aa86bSJames Feist return; 3115b4aa86bSJames Feist } 3125b4aa86bSJames Feist nlohmann::json& configRoot = 3135b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 3145b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 3155b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 3160fda0f12SGeorge Liu fans["@odata.id"] = 3170fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers"; 3185b4aa86bSJames Feist 3195b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 3205b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 3215b4aa86bSJames Feist pids["@odata.id"] = 3225b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 3235b4aa86bSJames Feist 324b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 325b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 326b7a08d04SJames Feist stepwise["@odata.id"] = 327b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 328b7a08d04SJames Feist 3295b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 3305b4aa86bSJames Feist zones["@odata.id"] = 3315b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 3325b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 333002d39b4SEd Tanous configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 3345b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 33573df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 33673df0db0SJames Feist 33773df0db0SJames Feist if (!currentProfile.empty()) 33873df0db0SJames Feist { 33973df0db0SJames Feist configRoot["Profile"] = currentProfile; 34073df0db0SJames Feist } 341bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("profile = {} !", currentProfile); 3425b4aa86bSJames Feist 3435b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3445b4aa86bSJames Feist { 3455b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3465b4aa86bSJames Feist { 3475b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 348b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 349b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3505b4aa86bSJames Feist { 3515b4aa86bSJames Feist continue; 3525b4aa86bSJames Feist } 35373df0db0SJames Feist 354711ac7a9SEd Tanous std::string name; 355711ac7a9SEd Tanous 356711ac7a9SEd Tanous for (const std::pair<std::string, 357002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 358002d39b4SEd Tanous intfPair.second) 359711ac7a9SEd Tanous { 360711ac7a9SEd Tanous if (propPair.first == "Name") 361711ac7a9SEd Tanous { 3625b4aa86bSJames Feist const std::string* namePtr = 363711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 3645b4aa86bSJames Feist if (namePtr == nullptr) 3655b4aa86bSJames Feist { 36662598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Name Field illegal"); 367b7a08d04SJames Feist messages::internalError(asyncResp->res); 3685b4aa86bSJames Feist return; 3695b4aa86bSJames Feist } 370db697703SWilly Tu name = *namePtr; 3715b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 372711ac7a9SEd Tanous } 373711ac7a9SEd Tanous else if (propPair.first == "Profiles") 37473df0db0SJames Feist { 37573df0db0SJames Feist const std::vector<std::string>* profiles = 37673df0db0SJames Feist std::get_if<std::vector<std::string>>( 377711ac7a9SEd Tanous &propPair.second); 37873df0db0SJames Feist if (profiles == nullptr) 37973df0db0SJames Feist { 38062598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Profiles Field illegal"); 38173df0db0SJames Feist messages::internalError(asyncResp->res); 38273df0db0SJames Feist return; 38373df0db0SJames Feist } 38473df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 38573df0db0SJames Feist currentProfile) == profiles->end()) 38673df0db0SJames Feist { 38762598e31SEd Tanous BMCWEB_LOG_INFO( 38862598e31SEd Tanous "{} not supported in current profile", name); 38973df0db0SJames Feist continue; 39073df0db0SJames Feist } 39173df0db0SJames Feist } 392711ac7a9SEd Tanous } 393b7a08d04SJames Feist nlohmann::json* config = nullptr; 394c33a90ecSJames Feist const std::string* classPtr = nullptr; 395711ac7a9SEd Tanous 396711ac7a9SEd Tanous for (const std::pair<std::string, 397002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 398002d39b4SEd Tanous intfPair.second) 399c33a90ecSJames Feist { 400727dc83fSLei YU if (propPair.first == "Class") 401711ac7a9SEd Tanous { 402002d39b4SEd Tanous classPtr = std::get_if<std::string>(&propPair.second); 403711ac7a9SEd Tanous } 404c33a90ecSJames Feist } 405c33a90ecSJames Feist 406ef4c65b7SEd Tanous boost::urls::url url("/redfish/v1/Managers/bmc"); 4075b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 4085b4aa86bSJames Feist { 4095b4aa86bSJames Feist std::string chassis; 410002d39b4SEd Tanous if (!dbus::utility::getNthStringFromPath(pathPair.first.str, 411002d39b4SEd Tanous 5, chassis)) 4125b4aa86bSJames Feist { 4135b4aa86bSJames Feist chassis = "#IllegalValue"; 4145b4aa86bSJames Feist } 4155b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 416ef4c65b7SEd Tanous zone["Chassis"]["@odata.id"] = 417ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis); 418eddfc437SWilly Tu url.set_fragment( 419eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) 420eddfc437SWilly Tu .to_string()); 421eddfc437SWilly Tu zone["@odata.id"] = std::move(url); 4225b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 423b7a08d04SJames Feist config = &zone; 4245b4aa86bSJames Feist } 4255b4aa86bSJames Feist 426b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 4275b4aa86bSJames Feist { 428c33a90ecSJames Feist if (classPtr == nullptr) 429c33a90ecSJames Feist { 43062598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 431c33a90ecSJames Feist messages::internalError(asyncResp->res); 432c33a90ecSJames Feist return; 433c33a90ecSJames Feist } 434c33a90ecSJames Feist 435b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 436b7a08d04SJames Feist config = &controller; 437eddfc437SWilly Tu url.set_fragment( 438eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / 439eddfc437SWilly Tu name) 440eddfc437SWilly Tu .to_string()); 441eddfc437SWilly Tu controller["@odata.id"] = std::move(url); 442b7a08d04SJames Feist controller["@odata.type"] = 443b7a08d04SJames Feist "#OemManager.StepwiseController"; 444b7a08d04SJames Feist 445c33a90ecSJames Feist controller["Direction"] = *classPtr; 4465b4aa86bSJames Feist } 4475b4aa86bSJames Feist 4485b4aa86bSJames Feist // pid and fans are off the same configuration 449b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4505b4aa86bSJames Feist { 4515b4aa86bSJames Feist if (classPtr == nullptr) 4525b4aa86bSJames Feist { 45362598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 454a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4555b4aa86bSJames Feist return; 4565b4aa86bSJames Feist } 4575b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 458002d39b4SEd Tanous nlohmann::json& element = isFan ? fans[name] : pids[name]; 459b7a08d04SJames Feist config = &element; 4605b4aa86bSJames Feist if (isFan) 4615b4aa86bSJames Feist { 462eddfc437SWilly Tu url.set_fragment( 463eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / 464eddfc437SWilly Tu name) 465eddfc437SWilly Tu .to_string()); 466eddfc437SWilly Tu element["@odata.id"] = std::move(url); 467002d39b4SEd Tanous element["@odata.type"] = "#OemManager.FanController"; 4685b4aa86bSJames Feist } 4695b4aa86bSJames Feist else 4705b4aa86bSJames Feist { 471eddfc437SWilly Tu url.set_fragment( 472eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / 473eddfc437SWilly Tu name) 474eddfc437SWilly Tu .to_string()); 475eddfc437SWilly Tu element["@odata.id"] = std::move(url); 476002d39b4SEd Tanous element["@odata.type"] = "#OemManager.PidController"; 4775b4aa86bSJames Feist } 478b7a08d04SJames Feist } 479b7a08d04SJames Feist else 480b7a08d04SJames Feist { 48162598e31SEd Tanous BMCWEB_LOG_ERROR("Unexpected configuration"); 482b7a08d04SJames Feist messages::internalError(asyncResp->res); 483b7a08d04SJames Feist return; 484b7a08d04SJames Feist } 485b7a08d04SJames Feist 486b7a08d04SJames Feist // used for making maps out of 2 vectors 487b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 488b7a08d04SJames Feist const std::vector<double>* values = nullptr; 489b7a08d04SJames Feist 490b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 491b7a08d04SJames Feist { 492b7a08d04SJames Feist if (propertyPair.first == "Type" || 493b7a08d04SJames Feist propertyPair.first == "Class" || 494b7a08d04SJames Feist propertyPair.first == "Name") 495b7a08d04SJames Feist { 496b7a08d04SJames Feist continue; 497b7a08d04SJames Feist } 498b7a08d04SJames Feist 499b7a08d04SJames Feist // zones 500b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 501b7a08d04SJames Feist { 502b7a08d04SJames Feist const double* ptr = 503abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 504b7a08d04SJames Feist if (ptr == nullptr) 505b7a08d04SJames Feist { 50662598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 50762598e31SEd Tanous propertyPair.first); 508b7a08d04SJames Feist messages::internalError(asyncResp->res); 509b7a08d04SJames Feist return; 510b7a08d04SJames Feist } 511b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 512b7a08d04SJames Feist } 513b7a08d04SJames Feist 514b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 515b7a08d04SJames Feist { 516b7a08d04SJames Feist if (propertyPair.first == "Reading" || 517b7a08d04SJames Feist propertyPair.first == "Output") 518b7a08d04SJames Feist { 519b7a08d04SJames Feist const std::vector<double>* ptr = 520abf2add6SEd Tanous std::get_if<std::vector<double>>( 521b7a08d04SJames Feist &propertyPair.second); 522b7a08d04SJames Feist 523b7a08d04SJames Feist if (ptr == nullptr) 524b7a08d04SJames Feist { 52562598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 52662598e31SEd Tanous propertyPair.first); 527b7a08d04SJames Feist messages::internalError(asyncResp->res); 528b7a08d04SJames Feist return; 529b7a08d04SJames Feist } 530b7a08d04SJames Feist 531b7a08d04SJames Feist if (propertyPair.first == "Reading") 532b7a08d04SJames Feist { 533b7a08d04SJames Feist keys = ptr; 534b7a08d04SJames Feist } 535b7a08d04SJames Feist else 536b7a08d04SJames Feist { 537b7a08d04SJames Feist values = ptr; 538b7a08d04SJames Feist } 539e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 540b7a08d04SJames Feist { 541b7a08d04SJames Feist if (keys->size() != values->size()) 542b7a08d04SJames Feist { 54362598e31SEd Tanous BMCWEB_LOG_ERROR( 54462598e31SEd Tanous "Reading and Output size don't match "); 545b7a08d04SJames Feist messages::internalError(asyncResp->res); 546b7a08d04SJames Feist return; 547b7a08d04SJames Feist } 548b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 549b7a08d04SJames Feist steps = nlohmann::json::array(); 550b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 551b7a08d04SJames Feist { 5521476687dSEd Tanous nlohmann::json::object_t step; 5531476687dSEd Tanous step["Target"] = (*keys)[ii]; 5541476687dSEd Tanous step["Output"] = (*values)[ii]; 555b2ba3072SPatrick Williams steps.emplace_back(std::move(step)); 556b7a08d04SJames Feist } 557b7a08d04SJames Feist } 558b7a08d04SJames Feist } 559b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 560b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 561b7a08d04SJames Feist { 562b7a08d04SJames Feist const double* ptr = 563abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 564b7a08d04SJames Feist if (ptr == nullptr) 565b7a08d04SJames Feist { 56662598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 56762598e31SEd Tanous propertyPair.first); 568b7a08d04SJames Feist messages::internalError(asyncResp->res); 569b7a08d04SJames Feist return; 570b7a08d04SJames Feist } 571b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 572b7a08d04SJames Feist } 573b7a08d04SJames Feist } 574b7a08d04SJames Feist 575b7a08d04SJames Feist // pid and fans are off the same configuration 576b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 577b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 578b7a08d04SJames Feist { 5795b4aa86bSJames Feist if (propertyPair.first == "Zones") 5805b4aa86bSJames Feist { 5815b4aa86bSJames Feist const std::vector<std::string>* inputs = 582abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5831b6b96c5SEd Tanous &propertyPair.second); 5845b4aa86bSJames Feist 5855b4aa86bSJames Feist if (inputs == nullptr) 5865b4aa86bSJames Feist { 58762598e31SEd Tanous BMCWEB_LOG_ERROR("Zones Pid Field Illegal"); 588a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5895b4aa86bSJames Feist return; 5905b4aa86bSJames Feist } 591b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5925b4aa86bSJames Feist data = nlohmann::json::array(); 5935b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5945b4aa86bSJames Feist { 5955b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5961476687dSEd Tanous nlohmann::json::object_t input; 597ef4c65b7SEd Tanous boost::urls::url managerUrl = boost::urls::format( 598ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc#{}", 599eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / 600eddfc437SWilly Tu itemCopy) 601eddfc437SWilly Tu .to_string()); 602eddfc437SWilly Tu input["@odata.id"] = std::move(managerUrl); 603b2ba3072SPatrick Williams data.emplace_back(std::move(input)); 6045b4aa86bSJames Feist } 6055b4aa86bSJames Feist } 6065b4aa86bSJames Feist // todo(james): may never happen, but this 6075b4aa86bSJames Feist // assumes configuration data referenced in the 6085b4aa86bSJames Feist // PID config is provided by the same daemon, we 6095b4aa86bSJames Feist // could add another loop to cover all cases, 6105b4aa86bSJames Feist // but I'm okay kicking this can down the road a 6115b4aa86bSJames Feist // bit 6125b4aa86bSJames Feist 6135b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 6145b4aa86bSJames Feist propertyPair.first == "Outputs") 6155b4aa86bSJames Feist { 616b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6175b4aa86bSJames Feist const std::vector<std::string>* inputs = 618abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6191b6b96c5SEd Tanous &propertyPair.second); 6205b4aa86bSJames Feist 6215b4aa86bSJames Feist if (inputs == nullptr) 6225b4aa86bSJames Feist { 62362598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 62462598e31SEd Tanous propertyPair.first); 625f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6265b4aa86bSJames Feist return; 6275b4aa86bSJames Feist } 6285b4aa86bSJames Feist data = *inputs; 629b943aaefSJames Feist } 630b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 631b943aaefSJames Feist { 632b943aaefSJames Feist const std::string* ptr = 633002d39b4SEd Tanous std::get_if<std::string>(&propertyPair.second); 634b943aaefSJames Feist 635b943aaefSJames Feist if (ptr == nullptr) 636b943aaefSJames Feist { 63762598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 63862598e31SEd Tanous propertyPair.first); 639b943aaefSJames Feist messages::internalError(asyncResp->res); 640b943aaefSJames Feist return; 641b943aaefSJames Feist } 642b943aaefSJames Feist // translate from dbus to redfish 643b943aaefSJames Feist if (*ptr == "WarningHigh") 644b943aaefSJames Feist { 645b943aaefSJames Feist (*config)["SetPointOffset"] = 646b943aaefSJames Feist "UpperThresholdNonCritical"; 647b943aaefSJames Feist } 648b943aaefSJames Feist else if (*ptr == "WarningLow") 649b943aaefSJames Feist { 650b943aaefSJames Feist (*config)["SetPointOffset"] = 651b943aaefSJames Feist "LowerThresholdNonCritical"; 652b943aaefSJames Feist } 653b943aaefSJames Feist else if (*ptr == "CriticalHigh") 654b943aaefSJames Feist { 655b943aaefSJames Feist (*config)["SetPointOffset"] = 656b943aaefSJames Feist "UpperThresholdCritical"; 657b943aaefSJames Feist } 658b943aaefSJames Feist else if (*ptr == "CriticalLow") 659b943aaefSJames Feist { 660b943aaefSJames Feist (*config)["SetPointOffset"] = 661b943aaefSJames Feist "LowerThresholdCritical"; 662b943aaefSJames Feist } 663b943aaefSJames Feist else 664b943aaefSJames Feist { 66562598e31SEd Tanous BMCWEB_LOG_ERROR("Value Illegal {}", *ptr); 666b943aaefSJames Feist messages::internalError(asyncResp->res); 667b943aaefSJames Feist return; 668b943aaefSJames Feist } 669b943aaefSJames Feist } 670b943aaefSJames Feist // doubles 671002d39b4SEd Tanous else if (propertyPair.first == "FFGainCoefficient" || 6725b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6735b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6745b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6755b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 676002d39b4SEd Tanous propertyPair.first == "PositiveHysteresis" || 677002d39b4SEd Tanous propertyPair.first == "NegativeHysteresis" || 6785b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6795b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6805b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6817625cb81SJames Feist propertyPair.first == "SetPoint" || 6825b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6835b4aa86bSJames Feist propertyPair.first == "SlewPos") 6845b4aa86bSJames Feist { 6855b4aa86bSJames Feist const double* ptr = 686abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6875b4aa86bSJames Feist if (ptr == nullptr) 6885b4aa86bSJames Feist { 68962598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 69062598e31SEd Tanous propertyPair.first); 691f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6925b4aa86bSJames Feist return; 6935b4aa86bSJames Feist } 694b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6955b4aa86bSJames Feist } 6965b4aa86bSJames Feist } 6975b4aa86bSJames Feist } 6985b4aa86bSJames Feist } 6995b4aa86bSJames Feist } 7005eb468daSGeorge Liu }); 7015b4aa86bSJames Feist } 702ca537928SJennifer Lee 70383ff9ab6SJames Feist enum class CreatePIDRet 70483ff9ab6SJames Feist { 70583ff9ab6SJames Feist fail, 70683ff9ab6SJames Feist del, 70783ff9ab6SJames Feist patch 70883ff9ab6SJames Feist }; 70983ff9ab6SJames Feist 7108d1b46d7Szhanghch05 inline bool 7118d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 7125f2caaefSJames Feist std::vector<nlohmann::json>& config, 7135f2caaefSJames Feist std::vector<std::string>& zones) 7145f2caaefSJames Feist { 715b6baeaa4SJames Feist if (config.empty()) 716b6baeaa4SJames Feist { 71762598e31SEd Tanous BMCWEB_LOG_ERROR("Empty Zones"); 718f818b04dSEd Tanous messages::propertyValueFormatError(response->res, config, "Zones"); 719b6baeaa4SJames Feist return false; 720b6baeaa4SJames Feist } 7215f2caaefSJames Feist for (auto& odata : config) 7225f2caaefSJames Feist { 7235f2caaefSJames Feist std::string path; 7245f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 7255f2caaefSJames Feist path)) 7265f2caaefSJames Feist { 7275f2caaefSJames Feist return false; 7285f2caaefSJames Feist } 7295f2caaefSJames Feist std::string input; 73061adbda3SJames Feist 73161adbda3SJames Feist // 8 below comes from 73261adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 73361adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 73461adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 7355f2caaefSJames Feist { 73662598e31SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", path); 73762598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type Zones"); 738f818b04dSEd Tanous messages::propertyValueFormatError(response->res, odata, "Zones"); 7395f2caaefSJames Feist return false; 7405f2caaefSJames Feist } 741a170f275SEd Tanous std::replace(input.begin(), input.end(), '_', ' '); 7425f2caaefSJames Feist zones.emplace_back(std::move(input)); 7435f2caaefSJames Feist } 7445f2caaefSJames Feist return true; 7455f2caaefSJames Feist } 7465f2caaefSJames Feist 747711ac7a9SEd Tanous inline const dbus::utility::ManagedObjectType::value_type* 74873df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 749b6baeaa4SJames Feist const std::string& value, std::string& chassis) 750b6baeaa4SJames Feist { 75162598e31SEd Tanous BMCWEB_LOG_DEBUG("Find Chassis: {}", value); 752b6baeaa4SJames Feist 753a170f275SEd Tanous std::string escaped = value; 7546ce82fabSYaswanth Reddy M std::replace(escaped.begin(), escaped.end(), ' ', '_'); 755b6baeaa4SJames Feist escaped = "/" + escaped; 7563544d2a7SEd Tanous auto it = std::ranges::find_if(managedObj, [&escaped](const auto& obj) { 75718f8f608SEd Tanous if (obj.first.str.ends_with(escaped)) 758b6baeaa4SJames Feist { 75962598e31SEd Tanous BMCWEB_LOG_DEBUG("Matched {}", obj.first.str); 760b6baeaa4SJames Feist return true; 761b6baeaa4SJames Feist } 762b6baeaa4SJames Feist return false; 763b6baeaa4SJames Feist }); 764b6baeaa4SJames Feist 765b6baeaa4SJames Feist if (it == managedObj.end()) 766b6baeaa4SJames Feist { 76773df0db0SJames Feist return nullptr; 768b6baeaa4SJames Feist } 769b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 770b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 77173df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 77273df0db0SJames Feist { 77373df0db0SJames Feist return &(*it); 77473df0db0SJames Feist } 77573df0db0SJames Feist 77673df0db0SJames Feist return nullptr; 777b6baeaa4SJames Feist } 778b6baeaa4SJames Feist 77923a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7808d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 781b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 78283ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 783b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 784b9d36b47SEd Tanous const std::string& profile) 78583ff9ab6SJames Feist { 7865f2caaefSJames Feist // common deleter 787b6baeaa4SJames Feist if (it.value() == nullptr) 7885f2caaefSJames Feist { 7895f2caaefSJames Feist std::string iface; 7905f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7915f2caaefSJames Feist { 7925f2caaefSJames Feist iface = pidConfigurationIface; 7935f2caaefSJames Feist } 7945f2caaefSJames Feist else if (type == "FanZones") 7955f2caaefSJames Feist { 7965f2caaefSJames Feist iface = pidZoneConfigurationIface; 7975f2caaefSJames Feist } 7985f2caaefSJames Feist else if (type == "StepwiseControllers") 7995f2caaefSJames Feist { 8005f2caaefSJames Feist iface = stepwiseConfigurationIface; 8015f2caaefSJames Feist } 8025f2caaefSJames Feist else 8035f2caaefSJames Feist { 80462598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 8055f2caaefSJames Feist messages::propertyUnknown(response->res, type); 8065f2caaefSJames Feist return CreatePIDRet::fail; 8075f2caaefSJames Feist } 8086ee7f774SJames Feist 80962598e31SEd Tanous BMCWEB_LOG_DEBUG("del {} {}", path, iface); 8105f2caaefSJames Feist // delete interface 8115f2caaefSJames Feist crow::connections::systemBus->async_method_call( 8125e7e2dc5SEd Tanous [response, path](const boost::system::error_code& ec) { 8135f2caaefSJames Feist if (ec) 8145f2caaefSJames Feist { 81562598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", path, ec); 8165f2caaefSJames Feist messages::internalError(response->res); 817b6baeaa4SJames Feist return; 8185f2caaefSJames Feist } 819b6baeaa4SJames Feist messages::success(response->res); 8205f2caaefSJames Feist }, 8215f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 8225f2caaefSJames Feist return CreatePIDRet::del; 8235f2caaefSJames Feist } 8245f2caaefSJames Feist 825711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 826b6baeaa4SJames Feist if (!createNewObject) 827b6baeaa4SJames Feist { 828b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 829b6baeaa4SJames Feist // d-bus 83073df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 83173df0db0SJames Feist if (managedItem == nullptr) 832b6baeaa4SJames Feist { 83362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 834ef4c65b7SEd Tanous messages::invalidObject( 835ef4c65b7SEd Tanous response->res, 836ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 837b6baeaa4SJames Feist return CreatePIDRet::fail; 838b6baeaa4SJames Feist } 839b6baeaa4SJames Feist } 840b6baeaa4SJames Feist 84126f6976fSEd Tanous if (!profile.empty() && 84273df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 84373df0db0SJames Feist type == "StepwiseControllers")) 84473df0db0SJames Feist { 84573df0db0SJames Feist if (managedItem == nullptr) 84673df0db0SJames Feist { 847b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 84873df0db0SJames Feist } 84973df0db0SJames Feist else 85073df0db0SJames Feist { 85173df0db0SJames Feist std::string interface; 85273df0db0SJames Feist if (type == "StepwiseControllers") 85373df0db0SJames Feist { 85473df0db0SJames Feist interface = stepwiseConfigurationIface; 85573df0db0SJames Feist } 85673df0db0SJames Feist else 85773df0db0SJames Feist { 85873df0db0SJames Feist interface = pidConfigurationIface; 85973df0db0SJames Feist } 860711ac7a9SEd Tanous bool ifaceFound = false; 861711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 862711ac7a9SEd Tanous { 863711ac7a9SEd Tanous if (iface.first == interface) 864711ac7a9SEd Tanous { 865711ac7a9SEd Tanous ifaceFound = true; 866711ac7a9SEd Tanous for (const auto& prop : iface.second) 867711ac7a9SEd Tanous { 868711ac7a9SEd Tanous if (prop.first == "Profiles") 869711ac7a9SEd Tanous { 870711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 871711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 872711ac7a9SEd Tanous &(prop.second)); 873711ac7a9SEd Tanous if (curProfiles == nullptr) 874711ac7a9SEd Tanous { 87562598e31SEd Tanous BMCWEB_LOG_ERROR( 87662598e31SEd Tanous "Illegal profiles in managed object"); 877711ac7a9SEd Tanous messages::internalError(response->res); 878711ac7a9SEd Tanous return CreatePIDRet::fail; 879711ac7a9SEd Tanous } 880711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 881711ac7a9SEd Tanous curProfiles->end(), 882711ac7a9SEd Tanous profile) == curProfiles->end()) 883711ac7a9SEd Tanous { 884711ac7a9SEd Tanous std::vector<std::string> newProfiles = 885711ac7a9SEd Tanous *curProfiles; 886711ac7a9SEd Tanous newProfiles.push_back(profile); 887b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 888711ac7a9SEd Tanous } 889711ac7a9SEd Tanous } 890711ac7a9SEd Tanous } 891711ac7a9SEd Tanous } 892711ac7a9SEd Tanous } 893711ac7a9SEd Tanous 894711ac7a9SEd Tanous if (!ifaceFound) 89573df0db0SJames Feist { 89662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find interface in managed object"); 89773df0db0SJames Feist messages::internalError(response->res); 89873df0db0SJames Feist return CreatePIDRet::fail; 89973df0db0SJames Feist } 90073df0db0SJames Feist } 90173df0db0SJames Feist } 90273df0db0SJames Feist 90383ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 90483ff9ab6SJames Feist { 90583ff9ab6SJames Feist if (createNewObject) 90683ff9ab6SJames Feist { 907b9d36b47SEd Tanous output.emplace_back("Class", 908b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 909b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 91083ff9ab6SJames Feist } 9115f2caaefSJames Feist 9125f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 9135f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 9145f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 9155f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 916b943aaefSJames Feist std::optional<std::string> setpointOffset; 9175f2caaefSJames Feist if (!redfish::json_util::readJson( 918b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 9195f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 9205f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 9215f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 9225f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 9235f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 9245f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 9255f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 926b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 927b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 928b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 929b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 93083ff9ab6SJames Feist { 9315f2caaefSJames Feist return CreatePIDRet::fail; 93283ff9ab6SJames Feist } 9335f2caaefSJames Feist if (zones) 9345f2caaefSJames Feist { 9355f2caaefSJames Feist std::vector<std::string> zonesStr; 9365f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 9375f2caaefSJames Feist { 93862598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 9395f2caaefSJames Feist return CreatePIDRet::fail; 9405f2caaefSJames Feist } 941b6baeaa4SJames Feist if (chassis.empty() && 942e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 943b6baeaa4SJames Feist { 94462598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 945ace85d60SEd Tanous messages::invalidObject( 946ef4c65b7SEd Tanous response->res, 947ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 948b6baeaa4SJames Feist return CreatePIDRet::fail; 949b6baeaa4SJames Feist } 950b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 9515f2caaefSJames Feist } 952afb9ee06SEd Tanous 953afb9ee06SEd Tanous if (inputs) 9545f2caaefSJames Feist { 955afb9ee06SEd Tanous for (std::string& value : *inputs) 95683ff9ab6SJames Feist { 957a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 95883ff9ab6SJames Feist } 959afb9ee06SEd Tanous output.emplace_back("Inputs", *inputs); 960afb9ee06SEd Tanous } 961afb9ee06SEd Tanous 962afb9ee06SEd Tanous if (outputs) 9635f2caaefSJames Feist { 964afb9ee06SEd Tanous for (std::string& value : *outputs) 9655f2caaefSJames Feist { 966afb9ee06SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 9675f2caaefSJames Feist } 968afb9ee06SEd Tanous output.emplace_back("Outputs", *outputs); 96983ff9ab6SJames Feist } 97083ff9ab6SJames Feist 971b943aaefSJames Feist if (setpointOffset) 972b943aaefSJames Feist { 973b943aaefSJames Feist // translate between redfish and dbus names 974b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 975b943aaefSJames Feist { 976b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 977b943aaefSJames Feist } 978b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 979b943aaefSJames Feist { 980b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 981b943aaefSJames Feist } 982b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 983b943aaefSJames Feist { 984b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 985b943aaefSJames Feist } 986b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 987b943aaefSJames Feist { 988b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 989b943aaefSJames Feist } 990b943aaefSJames Feist else 991b943aaefSJames Feist { 99262598e31SEd Tanous BMCWEB_LOG_ERROR("Invalid setpointoffset {}", *setpointOffset); 993ace85d60SEd Tanous messages::propertyValueNotInList(response->res, it.key(), 994ace85d60SEd Tanous "SetPointOffset"); 995b943aaefSJames Feist return CreatePIDRet::fail; 996b943aaefSJames Feist } 997b943aaefSJames Feist } 998b943aaefSJames Feist 99983ff9ab6SJames Feist // doubles 10005f2caaefSJames Feist for (const auto& pairs : doubles) 100183ff9ab6SJames Feist { 10025f2caaefSJames Feist if (!pairs.second) 100383ff9ab6SJames Feist { 10045f2caaefSJames Feist continue; 100583ff9ab6SJames Feist } 100662598e31SEd Tanous BMCWEB_LOG_DEBUG("{} = {}", pairs.first, *pairs.second); 1007b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 10085f2caaefSJames Feist } 100983ff9ab6SJames Feist } 101083ff9ab6SJames Feist 101183ff9ab6SJames Feist else if (type == "FanZones") 101283ff9ab6SJames Feist { 1013b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 101483ff9ab6SJames Feist 10155f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 10165f2caaefSJames Feist std::optional<double> failSafePercent; 1017d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1018b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 10195f2caaefSJames Feist chassisContainer, "FailSafePercent", 1020d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 1021d3ec07f8SJames Feist minThermalOutput)) 102283ff9ab6SJames Feist { 102383ff9ab6SJames Feist return CreatePIDRet::fail; 102483ff9ab6SJames Feist } 10255f2caaefSJames Feist 10265f2caaefSJames Feist if (chassisContainer) 102783ff9ab6SJames Feist { 10285f2caaefSJames Feist std::string chassisId; 10295f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10305f2caaefSJames Feist "@odata.id", chassisId)) 10315f2caaefSJames Feist { 103283ff9ab6SJames Feist return CreatePIDRet::fail; 103383ff9ab6SJames Feist } 103483ff9ab6SJames Feist 1035717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10365f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 103783ff9ab6SJames Feist { 103862598e31SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", chassisId); 1039ace85d60SEd Tanous messages::invalidObject( 1040ef4c65b7SEd Tanous response->res, 1041ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId)); 104283ff9ab6SJames Feist return CreatePIDRet::fail; 104383ff9ab6SJames Feist } 104483ff9ab6SJames Feist } 1045d3ec07f8SJames Feist if (minThermalOutput) 104683ff9ab6SJames Feist { 1047b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 10485f2caaefSJames Feist } 10495f2caaefSJames Feist if (failSafePercent) 105083ff9ab6SJames Feist { 1051b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 10525f2caaefSJames Feist } 10535f2caaefSJames Feist } 10545f2caaefSJames Feist else if (type == "StepwiseControllers") 10555f2caaefSJames Feist { 1056b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 10575f2caaefSJames Feist 10585f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10595f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10605f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10615f2caaefSJames Feist std::optional<double> positiveHysteresis; 10625f2caaefSJames Feist std::optional<double> negativeHysteresis; 1063c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10645f2caaefSJames Feist if (!redfish::json_util::readJson( 1065b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1066b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1067c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1068c33a90ecSJames Feist direction)) 10695f2caaefSJames Feist { 107083ff9ab6SJames Feist return CreatePIDRet::fail; 107183ff9ab6SJames Feist } 10725f2caaefSJames Feist 10735f2caaefSJames Feist if (zones) 107483ff9ab6SJames Feist { 1075b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1076b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10775f2caaefSJames Feist { 107862598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 107983ff9ab6SJames Feist return CreatePIDRet::fail; 108083ff9ab6SJames Feist } 1081b6baeaa4SJames Feist if (chassis.empty() && 1082e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1083b6baeaa4SJames Feist { 108462598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 1085ace85d60SEd Tanous messages::invalidObject( 1086ef4c65b7SEd Tanous response->res, 1087ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1088b6baeaa4SJames Feist return CreatePIDRet::fail; 1089b6baeaa4SJames Feist } 1090b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 10915f2caaefSJames Feist } 10925f2caaefSJames Feist if (steps) 10935f2caaefSJames Feist { 10945f2caaefSJames Feist std::vector<double> readings; 10955f2caaefSJames Feist std::vector<double> outputs; 10965f2caaefSJames Feist for (auto& step : *steps) 10975f2caaefSJames Feist { 1098543f4400SEd Tanous double target = 0.0; 1099543f4400SEd Tanous double out = 0.0; 11005f2caaefSJames Feist 11015f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 110223a21a1cSEd Tanous target, "Output", out)) 11035f2caaefSJames Feist { 11045f2caaefSJames Feist return CreatePIDRet::fail; 11055f2caaefSJames Feist } 11065f2caaefSJames Feist readings.emplace_back(target); 110723a21a1cSEd Tanous outputs.emplace_back(out); 11085f2caaefSJames Feist } 1109b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1110b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 11115f2caaefSJames Feist } 11125f2caaefSJames Feist if (inputs) 11135f2caaefSJames Feist { 11145f2caaefSJames Feist for (std::string& value : *inputs) 11155f2caaefSJames Feist { 1116a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 11175f2caaefSJames Feist } 1118b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 11195f2caaefSJames Feist } 11205f2caaefSJames Feist if (negativeHysteresis) 11215f2caaefSJames Feist { 1122b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 11235f2caaefSJames Feist } 11245f2caaefSJames Feist if (positiveHysteresis) 11255f2caaefSJames Feist { 1126b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 112783ff9ab6SJames Feist } 1128c33a90ecSJames Feist if (direction) 1129c33a90ecSJames Feist { 1130c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1131c33a90ecSJames Feist "Ceiling", "Floor"}; 11323544d2a7SEd Tanous if (std::ranges::find(allowedDirections, *direction) == 11333544d2a7SEd Tanous allowedDirections.end()) 1134c33a90ecSJames Feist { 1135c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1136c33a90ecSJames Feist *direction); 1137c33a90ecSJames Feist return CreatePIDRet::fail; 1138c33a90ecSJames Feist } 1139b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1140c33a90ecSJames Feist } 114183ff9ab6SJames Feist } 114283ff9ab6SJames Feist else 114383ff9ab6SJames Feist { 114462598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 114535a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 114683ff9ab6SJames Feist return CreatePIDRet::fail; 114783ff9ab6SJames Feist } 114883ff9ab6SJames Feist return CreatePIDRet::patch; 114983ff9ab6SJames Feist } 115073df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 115173df0db0SJames Feist { 11526936afe4SEd Tanous struct CompletionValues 11536936afe4SEd Tanous { 11546936afe4SEd Tanous std::vector<std::string> supportedProfiles; 11556936afe4SEd Tanous std::string currentProfile; 11566936afe4SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 11576936afe4SEd Tanous }; 115883ff9ab6SJames Feist 11594e23a444SEd Tanous explicit GetPIDValues( 11604e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 116123a21a1cSEd Tanous asyncResp(asyncRespIn) 116273df0db0SJames Feist 11631214b7e7SGunnar Mills {} 11649c310685SBorawski.Lukasz 116573df0db0SJames Feist void run() 11665b4aa86bSJames Feist { 116773df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 116873df0db0SJames Feist 116973df0db0SJames Feist // get all configurations 1170e99073f5SGeorge Liu constexpr std::array<std::string_view, 4> interfaces = { 1171e99073f5SGeorge Liu pidConfigurationIface, pidZoneConfigurationIface, 1172e99073f5SGeorge Liu objectManagerIface, stepwiseConfigurationIface}; 1173e99073f5SGeorge Liu dbus::utility::getSubTree( 1174e99073f5SGeorge Liu "/", 0, interfaces, 1175b9d36b47SEd Tanous [self]( 1176e99073f5SGeorge Liu const boost::system::error_code& ec, 1177b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 11785b4aa86bSJames Feist if (ec) 11795b4aa86bSJames Feist { 118062598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 118173df0db0SJames Feist messages::internalError(self->asyncResp->res); 118273df0db0SJames Feist return; 118373df0db0SJames Feist } 11846936afe4SEd Tanous self->complete.subtree = subtreeLocal; 1185e99073f5SGeorge Liu }); 118673df0db0SJames Feist 118773df0db0SJames Feist // at the same time get the selected profile 1188e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1189e99073f5SGeorge Liu thermalModeIface}; 1190e99073f5SGeorge Liu dbus::utility::getSubTree( 1191e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1192b9d36b47SEd Tanous [self]( 1193e99073f5SGeorge Liu const boost::system::error_code& ec, 1194b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 119523a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 119673df0db0SJames Feist { 119773df0db0SJames Feist return; 119873df0db0SJames Feist } 119923a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 120073df0db0SJames Feist { 120173df0db0SJames Feist // invalid mapper response, should never happen 120262598e31SEd Tanous BMCWEB_LOG_ERROR("GetPIDValues: Mapper Error"); 120373df0db0SJames Feist messages::internalError(self->asyncResp->res); 12045b4aa86bSJames Feist return; 12055b4aa86bSJames Feist } 12065b4aa86bSJames Feist 120723a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 120823a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 1209fac6e53bSKrzysztof Grobelny 1210fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1211fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 1212168e20c1SEd Tanous [path, owner, 12135e7e2dc5SEd Tanous self](const boost::system::error_code& ec2, 1214b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 121523a21a1cSEd Tanous if (ec2) 121673df0db0SJames Feist { 121762598e31SEd Tanous BMCWEB_LOG_ERROR( 121862598e31SEd Tanous "GetPIDValues: Can't get thermalModeIface {}", path); 121973df0db0SJames Feist messages::internalError(self->asyncResp->res); 122073df0db0SJames Feist return; 122173df0db0SJames Feist } 1222fac6e53bSKrzysztof Grobelny 1223271584abSEd Tanous const std::string* current = nullptr; 1224271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1225fac6e53bSKrzysztof Grobelny 1226fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1227fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Current", current, 1228fac6e53bSKrzysztof Grobelny "Supported", supported); 1229fac6e53bSKrzysztof Grobelny 1230fac6e53bSKrzysztof Grobelny if (!success) 123173df0db0SJames Feist { 1232002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 123373df0db0SJames Feist return; 123473df0db0SJames Feist } 1235fac6e53bSKrzysztof Grobelny 123673df0db0SJames Feist if (current == nullptr || supported == nullptr) 123773df0db0SJames Feist { 123862598e31SEd Tanous BMCWEB_LOG_ERROR( 123962598e31SEd Tanous "GetPIDValues: thermal mode iface invalid {}", path); 124073df0db0SJames Feist messages::internalError(self->asyncResp->res); 124173df0db0SJames Feist return; 124273df0db0SJames Feist } 12436936afe4SEd Tanous self->complete.currentProfile = *current; 12446936afe4SEd Tanous self->complete.supportedProfiles = *supported; 1245fac6e53bSKrzysztof Grobelny }); 1246e99073f5SGeorge Liu }); 124773df0db0SJames Feist } 124873df0db0SJames Feist 12496936afe4SEd Tanous static void 12506936afe4SEd Tanous processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12516936afe4SEd Tanous const CompletionValues& completion) 125273df0db0SJames Feist { 125373df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 125473df0db0SJames Feist { 125573df0db0SJames Feist return; 125673df0db0SJames Feist } 12575b4aa86bSJames Feist // create map of <connection, path to objMgr>> 12586936afe4SEd Tanous boost::container::flat_map< 12596936afe4SEd Tanous std::string, std::string, std::less<>, 12606936afe4SEd Tanous std::vector<std::pair<std::string, std::string>>> 12616936afe4SEd Tanous objectMgrPaths; 12626936afe4SEd Tanous boost::container::flat_set<std::string, std::less<>, 12636936afe4SEd Tanous std::vector<std::string>> 12646936afe4SEd Tanous calledConnections; 12656936afe4SEd Tanous for (const auto& pathGroup : completion.subtree) 12665b4aa86bSJames Feist { 12675b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12685b4aa86bSJames Feist { 12696bce33bcSJames Feist auto findConnection = 12706bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12716bce33bcSJames Feist if (findConnection != calledConnections.end()) 12726bce33bcSJames Feist { 12736bce33bcSJames Feist break; 12746bce33bcSJames Feist } 127573df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 12765b4aa86bSJames Feist { 12775b4aa86bSJames Feist if (interface == objectManagerIface) 12785b4aa86bSJames Feist { 127973df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 12805b4aa86bSJames Feist } 12815b4aa86bSJames Feist // this list is alphabetical, so we 12825b4aa86bSJames Feist // should have found the objMgr by now 12835b4aa86bSJames Feist if (interface == pidConfigurationIface || 1284b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1285b7a08d04SJames Feist interface == stepwiseConfigurationIface) 12865b4aa86bSJames Feist { 12875b4aa86bSJames Feist auto findObjMgr = 12885b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 12895b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 12905b4aa86bSJames Feist { 129162598e31SEd Tanous BMCWEB_LOG_DEBUG("{}Has no Object Manager", 129262598e31SEd Tanous connectionGroup.first); 12935b4aa86bSJames Feist continue; 12945b4aa86bSJames Feist } 12956bce33bcSJames Feist 12966bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 12976bce33bcSJames Feist 129873df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 12996936afe4SEd Tanous completion.currentProfile, 13006936afe4SEd Tanous completion.supportedProfiles, 130173df0db0SJames Feist asyncResp); 13025b4aa86bSJames Feist break; 13035b4aa86bSJames Feist } 13045b4aa86bSJames Feist } 13055b4aa86bSJames Feist } 13065b4aa86bSJames Feist } 130773df0db0SJames Feist } 130873df0db0SJames Feist 13096936afe4SEd Tanous ~GetPIDValues() 13106936afe4SEd Tanous { 13116936afe4SEd Tanous boost::asio::post(crow::connections::systemBus->get_io_context(), 13126936afe4SEd Tanous std::bind_front(&processingComplete, asyncResp, 13136936afe4SEd Tanous std::move(complete))); 13146936afe4SEd Tanous } 13156936afe4SEd Tanous 1316ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1317ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1318ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1319ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1320ecd6a3a2SEd Tanous 13218d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 13226936afe4SEd Tanous CompletionValues complete; 132373df0db0SJames Feist }; 132473df0db0SJames Feist 132573df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 132673df0db0SJames Feist { 13278d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 132873df0db0SJames Feist nlohmann::json& data) : 1329271584abSEd Tanous asyncResp(asyncRespIn) 133073df0db0SJames Feist { 133173df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 133273df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 133373df0db0SJames Feist std::optional<nlohmann::json> fanZones; 133473df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 133573df0db0SJames Feist 133673df0db0SJames Feist if (!redfish::json_util::readJson( 133773df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 133873df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 133973df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 134073df0db0SJames Feist { 134173df0db0SJames Feist return; 134273df0db0SJames Feist } 134373df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 134473df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 134573df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 134673df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 134773df0db0SJames Feist std::move(stepwiseControllers)); 134873df0db0SJames Feist } 1349ecd6a3a2SEd Tanous 1350ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1351ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1352ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1353ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1354ecd6a3a2SEd Tanous 135573df0db0SJames Feist void run() 135673df0db0SJames Feist { 135773df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 135873df0db0SJames Feist { 135973df0db0SJames Feist return; 136073df0db0SJames Feist } 136173df0db0SJames Feist 136273df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 136373df0db0SJames Feist 136473df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 136573df0db0SJames Feist // interface gets more traction 13665eb468daSGeorge Liu sdbusplus::message::object_path objPath( 13675eb468daSGeorge Liu "/xyz/openbmc_project/inventory"); 13685eb468daSGeorge Liu dbus::utility::getManagedObjects( 13695eb468daSGeorge Liu "xyz.openbmc_project.EntityManager", objPath, 13705e7e2dc5SEd Tanous [self](const boost::system::error_code& ec, 1371914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 137273df0db0SJames Feist if (ec) 137373df0db0SJames Feist { 137462598e31SEd Tanous BMCWEB_LOG_ERROR("Error communicating to Entity Manager"); 137573df0db0SJames Feist messages::internalError(self->asyncResp->res); 137673df0db0SJames Feist return; 137773df0db0SJames Feist } 1378e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1379e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1380e69d9de2SJames Feist stepwiseConfigurationIface}; 1381e69d9de2SJames Feist 138214b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1383e69d9de2SJames Feist { 138414b0b8d5SJames Feist for (const auto& [interface, _] : object) 1385e69d9de2SJames Feist { 13863544d2a7SEd Tanous if (std::ranges::find(configurations, interface) != 13873544d2a7SEd Tanous configurations.end()) 1388e69d9de2SJames Feist { 138914b0b8d5SJames Feist self->objectCount++; 1390e69d9de2SJames Feist break; 1391e69d9de2SJames Feist } 1392e69d9de2SJames Feist } 1393e69d9de2SJames Feist } 1394914e2d5dSEd Tanous self->managedObj = mObj; 13955eb468daSGeorge Liu }); 139673df0db0SJames Feist 139773df0db0SJames Feist // at the same time get the profile information 1398e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1399e99073f5SGeorge Liu thermalModeIface}; 1400e99073f5SGeorge Liu dbus::utility::getSubTree( 1401e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1402e99073f5SGeorge Liu [self](const boost::system::error_code& ec, 1403b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 140473df0db0SJames Feist if (ec || subtree.empty()) 140573df0db0SJames Feist { 140673df0db0SJames Feist return; 140773df0db0SJames Feist } 140873df0db0SJames Feist if (subtree[0].second.empty()) 140973df0db0SJames Feist { 141073df0db0SJames Feist // invalid mapper response, should never happen 141162598e31SEd Tanous BMCWEB_LOG_ERROR("SetPIDValues: Mapper Error"); 141273df0db0SJames Feist messages::internalError(self->asyncResp->res); 141373df0db0SJames Feist return; 141473df0db0SJames Feist } 141573df0db0SJames Feist 141673df0db0SJames Feist const std::string& path = subtree[0].first; 141773df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 1418fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1419fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 14205e7e2dc5SEd Tanous [self, path, owner](const boost::system::error_code& ec2, 1421b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1422cb13a392SEd Tanous if (ec2) 142373df0db0SJames Feist { 142462598e31SEd Tanous BMCWEB_LOG_ERROR( 142562598e31SEd Tanous "SetPIDValues: Can't get thermalModeIface {}", path); 142673df0db0SJames Feist messages::internalError(self->asyncResp->res); 142773df0db0SJames Feist return; 142873df0db0SJames Feist } 1429271584abSEd Tanous const std::string* current = nullptr; 1430271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1431fac6e53bSKrzysztof Grobelny 1432fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1433fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), r, "Current", current, 1434fac6e53bSKrzysztof Grobelny "Supported", supported); 1435fac6e53bSKrzysztof Grobelny 1436fac6e53bSKrzysztof Grobelny if (!success) 143773df0db0SJames Feist { 1438002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 143973df0db0SJames Feist return; 144073df0db0SJames Feist } 1441fac6e53bSKrzysztof Grobelny 144273df0db0SJames Feist if (current == nullptr || supported == nullptr) 144373df0db0SJames Feist { 144462598e31SEd Tanous BMCWEB_LOG_ERROR( 144562598e31SEd Tanous "SetPIDValues: thermal mode iface invalid {}", path); 144673df0db0SJames Feist messages::internalError(self->asyncResp->res); 144773df0db0SJames Feist return; 144873df0db0SJames Feist } 144973df0db0SJames Feist self->currentProfile = *current; 145073df0db0SJames Feist self->supportedProfiles = *supported; 145173df0db0SJames Feist self->profileConnection = owner; 145273df0db0SJames Feist self->profilePath = path; 1453fac6e53bSKrzysztof Grobelny }); 1454e99073f5SGeorge Liu }); 145573df0db0SJames Feist } 145624b2fe81SEd Tanous void pidSetDone() 145773df0db0SJames Feist { 145873df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 145973df0db0SJames Feist { 146073df0db0SJames Feist return; 14615b4aa86bSJames Feist } 14628d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 146373df0db0SJames Feist if (profile) 146473df0db0SJames Feist { 14653544d2a7SEd Tanous if (std::ranges::find(supportedProfiles, *profile) == 14663544d2a7SEd Tanous supportedProfiles.end()) 146773df0db0SJames Feist { 146873df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 146973df0db0SJames Feist *profile); 147073df0db0SJames Feist return; 147173df0db0SJames Feist } 147273df0db0SJames Feist currentProfile = *profile; 14739ae226faSGeorge Liu sdbusplus::asio::setProperty( 14749ae226faSGeorge Liu *crow::connections::systemBus, profileConnection, profilePath, 14759ae226faSGeorge Liu thermalModeIface, "Current", *profile, 14765e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 147773df0db0SJames Feist if (ec) 147873df0db0SJames Feist { 147962598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching profile{}", ec); 148073df0db0SJames Feist messages::internalError(response->res); 148173df0db0SJames Feist } 14829ae226faSGeorge Liu }); 148373df0db0SJames Feist } 148473df0db0SJames Feist 148573df0db0SJames Feist for (auto& containerPair : configuration) 148673df0db0SJames Feist { 148773df0db0SJames Feist auto& container = containerPair.second; 148873df0db0SJames Feist if (!container) 148973df0db0SJames Feist { 149073df0db0SJames Feist continue; 149173df0db0SJames Feist } 149262598e31SEd Tanous BMCWEB_LOG_DEBUG("{}", *container); 14936ee7f774SJames Feist 149402cad96eSEd Tanous const std::string& type = containerPair.first; 149573df0db0SJames Feist 149673df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 149717a897dfSManojkiran Eda it != container->end(); ++it) 149873df0db0SJames Feist { 149973df0db0SJames Feist const auto& name = it.key(); 1500cddbf3dfSPotin Lai std::string dbusObjName = name; 1501cddbf3dfSPotin Lai std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); 150262598e31SEd Tanous BMCWEB_LOG_DEBUG("looking for {}", name); 15036ee7f774SJames Feist 15043544d2a7SEd Tanous auto pathItr = std::ranges::find_if( 15053544d2a7SEd Tanous managedObj, [&dbusObjName](const auto& obj) { 150618f8f608SEd Tanous return obj.first.parent_path() == dbusObjName; 150773df0db0SJames Feist }); 1508b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 150973df0db0SJames Feist 151073df0db0SJames Feist output.reserve(16); // The pid interface length 151173df0db0SJames Feist 151273df0db0SJames Feist // determines if we're patching entity-manager or 151373df0db0SJames Feist // creating a new object 151473df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 151562598e31SEd Tanous BMCWEB_LOG_DEBUG("Found = {}", !createNewObject); 15166ee7f774SJames Feist 151773df0db0SJames Feist std::string iface; 1518ea2b670dSEd Tanous if (!createNewObject) 1519ea2b670dSEd Tanous { 15208be2b5b6SPotin Lai bool findInterface = false; 1521ea2b670dSEd Tanous for (const auto& interface : pathItr->second) 1522ea2b670dSEd Tanous { 1523ea2b670dSEd Tanous if (interface.first == pidConfigurationIface) 1524ea2b670dSEd Tanous { 1525ea2b670dSEd Tanous if (type == "PidControllers" || 1526ea2b670dSEd Tanous type == "FanControllers") 152773df0db0SJames Feist { 152873df0db0SJames Feist iface = pidConfigurationIface; 15298be2b5b6SPotin Lai findInterface = true; 15308be2b5b6SPotin Lai break; 153173df0db0SJames Feist } 153273df0db0SJames Feist } 1533ea2b670dSEd Tanous else if (interface.first == pidZoneConfigurationIface) 153473df0db0SJames Feist { 1535ea2b670dSEd Tanous if (type == "FanZones") 153673df0db0SJames Feist { 1537da39350aSPavanKumarIntel iface = pidZoneConfigurationIface; 15388be2b5b6SPotin Lai findInterface = true; 15398be2b5b6SPotin Lai break; 154073df0db0SJames Feist } 154173df0db0SJames Feist } 1542ea2b670dSEd Tanous else if (interface.first == stepwiseConfigurationIface) 1543ea2b670dSEd Tanous { 1544ea2b670dSEd Tanous if (type == "StepwiseControllers") 154573df0db0SJames Feist { 154673df0db0SJames Feist iface = stepwiseConfigurationIface; 15478be2b5b6SPotin Lai findInterface = true; 15488be2b5b6SPotin Lai break; 15498be2b5b6SPotin Lai } 15508be2b5b6SPotin Lai } 15518be2b5b6SPotin Lai } 15528be2b5b6SPotin Lai 15538be2b5b6SPotin Lai // create new object if interface not found 15548be2b5b6SPotin Lai if (!findInterface) 15558be2b5b6SPotin Lai { 155673df0db0SJames Feist createNewObject = true; 155773df0db0SJames Feist } 1558ea2b670dSEd Tanous } 15596ee7f774SJames Feist 15606ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15616ee7f774SJames Feist { 15624e0453b1SGunnar Mills // can't delete a non-existent object 1563e2616cc5SEd Tanous messages::propertyValueNotInList(response->res, it.value(), 1564e2616cc5SEd Tanous name); 15656ee7f774SJames Feist continue; 15666ee7f774SJames Feist } 15676ee7f774SJames Feist 15686ee7f774SJames Feist std::string path; 15696ee7f774SJames Feist if (pathItr != managedObj.end()) 15706ee7f774SJames Feist { 15716ee7f774SJames Feist path = pathItr->first.str; 15726ee7f774SJames Feist } 15736ee7f774SJames Feist 157462598e31SEd Tanous BMCWEB_LOG_DEBUG("Create new = {}", createNewObject); 1575e69d9de2SJames Feist 1576e69d9de2SJames Feist // arbitrary limit to avoid attacks 1577e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 157814b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1579e69d9de2SJames Feist { 1580e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1581e69d9de2SJames Feist continue; 1582e69d9de2SJames Feist } 1583a170f275SEd Tanous std::string escaped = name; 1584a170f275SEd Tanous std::replace(escaped.begin(), escaped.end(), '_', ' '); 1585a170f275SEd Tanous output.emplace_back("Name", escaped); 158673df0db0SJames Feist 158773df0db0SJames Feist std::string chassis; 158873df0db0SJames Feist CreatePIDRet ret = createPidInterface( 15896ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 15906ee7f774SJames Feist output, chassis, currentProfile); 159173df0db0SJames Feist if (ret == CreatePIDRet::fail) 159273df0db0SJames Feist { 159373df0db0SJames Feist return; 159473df0db0SJames Feist } 15953174e4dfSEd Tanous if (ret == CreatePIDRet::del) 159673df0db0SJames Feist { 159773df0db0SJames Feist continue; 159873df0db0SJames Feist } 159973df0db0SJames Feist 160073df0db0SJames Feist if (!createNewObject) 160173df0db0SJames Feist { 160273df0db0SJames Feist for (const auto& property : output) 160373df0db0SJames Feist { 16047a696974SPotin Lai crow::connections::systemBus->async_method_call( 160573df0db0SJames Feist [response, 160673df0db0SJames Feist propertyName{std::string(property.first)}]( 16075e7e2dc5SEd Tanous const boost::system::error_code& ec) { 160873df0db0SJames Feist if (ec) 160973df0db0SJames Feist { 161062598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", 161162598e31SEd Tanous propertyName, ec); 161273df0db0SJames Feist messages::internalError(response->res); 161373df0db0SJames Feist return; 161473df0db0SJames Feist } 161573df0db0SJames Feist messages::success(response->res); 16167a696974SPotin Lai }, 16177a696974SPotin Lai "xyz.openbmc_project.EntityManager", path, 16187a696974SPotin Lai "org.freedesktop.DBus.Properties", "Set", iface, 16197a696974SPotin Lai property.first, property.second); 162073df0db0SJames Feist } 162173df0db0SJames Feist } 162273df0db0SJames Feist else 162373df0db0SJames Feist { 162473df0db0SJames Feist if (chassis.empty()) 162573df0db0SJames Feist { 162662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config"); 1627ace85d60SEd Tanous messages::internalError(response->res); 162873df0db0SJames Feist return; 162973df0db0SJames Feist } 163073df0db0SJames Feist 163173df0db0SJames Feist bool foundChassis = false; 163273df0db0SJames Feist for (const auto& obj : managedObj) 163373df0db0SJames Feist { 163418f8f608SEd Tanous if (obj.first.parent_path() == chassis) 163573df0db0SJames Feist { 163673df0db0SJames Feist chassis = obj.first.str; 163773df0db0SJames Feist foundChassis = true; 163873df0db0SJames Feist break; 163973df0db0SJames Feist } 164073df0db0SJames Feist } 164173df0db0SJames Feist if (!foundChassis) 164273df0db0SJames Feist { 164362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find chassis on dbus"); 164473df0db0SJames Feist messages::resourceMissingAtURI( 1645ace85d60SEd Tanous response->res, 1646ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", 1647ef4c65b7SEd Tanous chassis)); 164873df0db0SJames Feist return; 164973df0db0SJames Feist } 165073df0db0SJames Feist 165173df0db0SJames Feist crow::connections::systemBus->async_method_call( 16525e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 165373df0db0SJames Feist if (ec) 165473df0db0SJames Feist { 165562598e31SEd Tanous BMCWEB_LOG_ERROR("Error Adding Pid Object {}", ec); 165673df0db0SJames Feist messages::internalError(response->res); 165773df0db0SJames Feist return; 165873df0db0SJames Feist } 165973df0db0SJames Feist messages::success(response->res); 166073df0db0SJames Feist }, 166173df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 166273df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 166373df0db0SJames Feist } 166473df0db0SJames Feist } 166573df0db0SJames Feist } 166673df0db0SJames Feist } 166724b2fe81SEd Tanous 166824b2fe81SEd Tanous ~SetPIDValues() 166924b2fe81SEd Tanous { 167024b2fe81SEd Tanous try 167124b2fe81SEd Tanous { 167224b2fe81SEd Tanous pidSetDone(); 167324b2fe81SEd Tanous } 167424b2fe81SEd Tanous catch (...) 167524b2fe81SEd Tanous { 167662598e31SEd Tanous BMCWEB_LOG_CRITICAL("pidSetDone threw exception"); 167724b2fe81SEd Tanous } 167824b2fe81SEd Tanous } 167924b2fe81SEd Tanous 16808d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 168173df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 168273df0db0SJames Feist configuration; 168373df0db0SJames Feist std::optional<std::string> profile; 168473df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 168573df0db0SJames Feist std::vector<std::string> supportedProfiles; 168673df0db0SJames Feist std::string currentProfile; 168773df0db0SJames Feist std::string profileConnection; 168873df0db0SJames Feist std::string profilePath; 168914b0b8d5SJames Feist size_t objectCount = 0; 169073df0db0SJames Feist }; 169173df0db0SJames Feist 1692071d8fdfSSunnySrivastava1984 /** 1693071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1694071d8fdfSSunnySrivastava1984 * 1695ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 1696071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1697071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1698071d8fdfSSunnySrivastava1984 * @return none 1699071d8fdfSSunnySrivastava1984 */ 1700ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1701071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1702071d8fdfSSunnySrivastava1984 const std::string& path) 1703071d8fdfSSunnySrivastava1984 { 170462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get BMC manager Location data."); 1705071d8fdfSSunnySrivastava1984 17061e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 17071e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 17081e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 1709ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17101e1e598dSJonathan Doman const std::string& property) { 1711071d8fdfSSunnySrivastava1984 if (ec) 1712071d8fdfSSunnySrivastava1984 { 171362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error for " 171462598e31SEd Tanous "Location"); 1715ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1716071d8fdfSSunnySrivastava1984 return; 1717071d8fdfSSunnySrivastava1984 } 1718071d8fdfSSunnySrivastava1984 1719ac106bf6SEd Tanous asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 17201e1e598dSJonathan Doman property; 17211e1e598dSJonathan Doman }); 1722071d8fdfSSunnySrivastava1984 } 17237e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17247e860f15SJohn Edward Broadbent inline void 1725ac106bf6SEd Tanous managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 17264bf2b033SGunnar Mills { 172762598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); 17284bf2b033SGunnar Mills 17291e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 17301e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.BMC", 17311e1e598dSJonathan Doman "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC", 17321e1e598dSJonathan Doman "LastRebootTime", 1733ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17341e1e598dSJonathan Doman const uint64_t lastResetTime) { 17354bf2b033SGunnar Mills if (ec) 17364bf2b033SGunnar Mills { 173762598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 17384bf2b033SGunnar Mills return; 17394bf2b033SGunnar Mills } 17404bf2b033SGunnar Mills 17414bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17424bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17431e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 17444bf2b033SGunnar Mills 17454bf2b033SGunnar Mills // Convert to ISO 8601 standard 1746ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 17472b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 17481e1e598dSJonathan Doman }); 17494bf2b033SGunnar Mills } 17504bf2b033SGunnar Mills 17514bfefa74SGunnar Mills /** 17524bfefa74SGunnar Mills * @brief Set the running firmware image 17534bfefa74SGunnar Mills * 1754ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object 17554bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17564bfefa74SGunnar Mills * 17574bfefa74SGunnar Mills * @return void 17584bfefa74SGunnar Mills */ 17597e860f15SJohn Edward Broadbent inline void 1760ac106bf6SEd Tanous setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1761f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17624bfefa74SGunnar Mills { 17634bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1764f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17654bfefa74SGunnar Mills if (idPos == std::string::npos) 17664bfefa74SGunnar Mills { 1767ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17684bfefa74SGunnar Mills "@odata.id"); 176962598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); 17704bfefa74SGunnar Mills return; 17714bfefa74SGunnar Mills } 17724bfefa74SGunnar Mills idPos++; 17734bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 17744bfefa74SGunnar Mills { 1775ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17764bfefa74SGunnar Mills "@odata.id"); 177762598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 17784bfefa74SGunnar Mills return; 17794bfefa74SGunnar Mills } 17804bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 17814bfefa74SGunnar Mills 17824bfefa74SGunnar Mills // Make sure the image is valid before setting priority 17835eb468daSGeorge Liu sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); 17845eb468daSGeorge Liu dbus::utility::getManagedObjects( 17855eb468daSGeorge Liu "xyz.openbmc_project.Software.BMC.Updater", objPath, 17865eb468daSGeorge Liu [asyncResp, firmwareId, runningFirmwareTarget]( 17875eb468daSGeorge Liu const boost::system::error_code& ec, 17885eb468daSGeorge Liu const dbus::utility::ManagedObjectType& subtree) { 17894bfefa74SGunnar Mills if (ec) 17904bfefa74SGunnar Mills { 179162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); 1792ac106bf6SEd Tanous messages::internalError(asyncResp->res); 17934bfefa74SGunnar Mills return; 17944bfefa74SGunnar Mills } 17954bfefa74SGunnar Mills 179626f6976fSEd Tanous if (subtree.empty()) 17974bfefa74SGunnar Mills { 179862598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find image!"); 1799ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18004bfefa74SGunnar Mills return; 18014bfefa74SGunnar Mills } 18024bfefa74SGunnar Mills 18034bfefa74SGunnar Mills bool foundImage = false; 180402cad96eSEd Tanous for (const auto& object : subtree) 18054bfefa74SGunnar Mills { 18064bfefa74SGunnar Mills const std::string& path = 18074bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1808f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18094bfefa74SGunnar Mills 18104bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18114bfefa74SGunnar Mills { 18124bfefa74SGunnar Mills continue; 18134bfefa74SGunnar Mills } 18144bfefa74SGunnar Mills 18154bfefa74SGunnar Mills idPos2++; 18164bfefa74SGunnar Mills if (idPos2 >= path.size()) 18174bfefa74SGunnar Mills { 18184bfefa74SGunnar Mills continue; 18194bfefa74SGunnar Mills } 18204bfefa74SGunnar Mills 18214bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18224bfefa74SGunnar Mills { 18234bfefa74SGunnar Mills foundImage = true; 18244bfefa74SGunnar Mills break; 18254bfefa74SGunnar Mills } 18264bfefa74SGunnar Mills } 18274bfefa74SGunnar Mills 18284bfefa74SGunnar Mills if (!foundImage) 18294bfefa74SGunnar Mills { 1830ac106bf6SEd Tanous messages::propertyValueNotInList( 1831ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id"); 183262598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 18334bfefa74SGunnar Mills return; 18344bfefa74SGunnar Mills } 18354bfefa74SGunnar Mills 183662598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", 183762598e31SEd Tanous firmwareId); 18384bfefa74SGunnar Mills 18394bfefa74SGunnar Mills // Only support Immediate 18404bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18414bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18429ae226faSGeorge Liu sdbusplus::asio::setProperty( 18439ae226faSGeorge Liu *crow::connections::systemBus, 18449ae226faSGeorge Liu "xyz.openbmc_project.Software.BMC.Updater", 18459ae226faSGeorge Liu "/xyz/openbmc_project/software/" + firmwareId, 18469ae226faSGeorge Liu "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 18479ae226faSGeorge Liu static_cast<uint8_t>(0), 1848ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) { 18498a592810SEd Tanous if (ec2) 18504bfefa74SGunnar Mills { 185162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error setting."); 1852ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18534bfefa74SGunnar Mills return; 18544bfefa74SGunnar Mills } 1855ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp); 18569ae226faSGeorge Liu }); 18575eb468daSGeorge Liu }); 18584bfefa74SGunnar Mills } 18594bfefa74SGunnar Mills 1860*c51afd54SEd Tanous inline void 1861*c51afd54SEd Tanous afterSetDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1862*c51afd54SEd Tanous const boost::system::error_code& ec, 1863*c51afd54SEd Tanous const sdbusplus::message_t& msg) 1864*c51afd54SEd Tanous { 1865*c51afd54SEd Tanous if (ec) 1866*c51afd54SEd Tanous { 1867*c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", 1868*c51afd54SEd Tanous ec); 1869*c51afd54SEd Tanous const sd_bus_error* dbusError = msg.get_error(); 1870*c51afd54SEd Tanous if (dbusError != nullptr) 1871*c51afd54SEd Tanous { 1872*c51afd54SEd Tanous std::string_view errorName(dbusError->name); 1873*c51afd54SEd Tanous if (errorName == 1874*c51afd54SEd Tanous "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") 1875*c51afd54SEd Tanous { 1876*c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Setting conflict"); 1877*c51afd54SEd Tanous messages::propertyValueConflict( 1878*c51afd54SEd Tanous asyncResp->res, "DateTime", 1879*c51afd54SEd Tanous "Managers/NetworkProtocol/NTPProcotolEnabled"); 1880*c51afd54SEd Tanous return; 1881*c51afd54SEd Tanous } 1882*c51afd54SEd Tanous } 1883*c51afd54SEd Tanous messages::internalError(asyncResp->res); 1884*c51afd54SEd Tanous return; 1885*c51afd54SEd Tanous } 1886*c51afd54SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 1887*c51afd54SEd Tanous } 1888*c51afd54SEd Tanous 1889*c51afd54SEd Tanous inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1890*c51afd54SEd Tanous const std::string& datetime) 1891af5d6058SSantosh Puranik { 189262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set date time: {}", datetime); 1893af5d6058SSantosh Puranik 1894c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 1895c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 1896c2e32007SEd Tanous if (!us) 1897af5d6058SSantosh Puranik { 1898ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime, 1899ac106bf6SEd Tanous "DateTime"); 1900c2e32007SEd Tanous return; 1901c2e32007SEd Tanous } 1902*c51afd54SEd Tanous // Set the absolute datetime 1903*c51afd54SEd Tanous bool relative = false; 1904*c51afd54SEd Tanous bool interactive = false; 1905*c51afd54SEd Tanous crow::connections::systemBus->async_method_call( 1906*c51afd54SEd Tanous [asyncResp](const boost::system::error_code& ec, 1907*c51afd54SEd Tanous const sdbusplus::message_t& msg) { 1908*c51afd54SEd Tanous afterSetDateTime(asyncResp, ec, msg); 1909*c51afd54SEd Tanous }, 1910*c51afd54SEd Tanous "org.freedesktop.timedate1", "/org/freedesktop/timedate1", 1911*c51afd54SEd Tanous "org.freedesktop.timedate1", "SetTime", us->count(), relative, 1912*c51afd54SEd Tanous interactive); 191383ff9ab6SJames Feist } 19149c310685SBorawski.Lukasz 191575815e5cSEd Tanous inline void 191675815e5cSEd Tanous checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 191775815e5cSEd Tanous { 191875815e5cSEd Tanous sdbusplus::asio::getProperty<std::string>( 191975815e5cSEd Tanous *crow::connections::systemBus, "org.freedesktop.systemd1", 192075815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 192175815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState", 192275815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, 192375815e5cSEd Tanous const std::string& val) { 192475815e5cSEd Tanous if (!ec) 192575815e5cSEd Tanous { 192675815e5cSEd Tanous if (val == "active") 192775815e5cSEd Tanous { 192875815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; 192975815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Quiesced"; 193075815e5cSEd Tanous return; 193175815e5cSEd Tanous } 193275815e5cSEd Tanous } 193375815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 193475815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 193575815e5cSEd Tanous }); 193675815e5cSEd Tanous } 193775815e5cSEd Tanous 19387e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 19397e860f15SJohn Edward Broadbent { 19407e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 19419c310685SBorawski.Lukasz 19427e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1943ed398213SEd Tanous .privileges(redfish::privileges::getManager) 1944002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1945002d39b4SEd Tanous [&app, uuid](const crow::Request& req, 194645ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 19473ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 194845ca1b86SEd Tanous { 194945ca1b86SEd Tanous return; 195045ca1b86SEd Tanous } 19517e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 1952a51fc2d2SSui Chen asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager"; 19537e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19547e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19557e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19567e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19577e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19581476687dSEd Tanous 19597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19607e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19617e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 1962002d39b4SEd Tanous asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 19637e860f15SJohn Edward Broadbent 19641476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 19651476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices"; 19661476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 19671476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 19681476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 19691476687dSEd Tanous "/redfish/v1/Managers/bmc/EthernetInterfaces"; 19707e860f15SJohn Edward Broadbent 19717e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19721476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 19731476687dSEd Tanous "/redfish/v1/Managers/bmc/VirtualMedia"; 19747e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19757e860f15SJohn Edward Broadbent 19767e860f15SJohn Edward Broadbent // default oem data 19777e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19787e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19797e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19807e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19817e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19827e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19831476687dSEd Tanous 19841476687dSEd Tanous nlohmann::json::object_t certificates; 19851476687dSEd Tanous certificates["@odata.id"] = 19861476687dSEd Tanous "/redfish/v1/Managers/bmc/Truststore/Certificates"; 19871476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 19887e860f15SJohn Edward Broadbent 19897e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19907e860f15SJohn Edward Broadbent // supports BMC reboot. 19917e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19927e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 19937e860f15SJohn Edward Broadbent managerReset["target"] = 19947e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 19957e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 19967e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 19977e860f15SJohn Edward Broadbent 19987e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 19997e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 20007e860f15SJohn Edward Broadbent // on OpenBMC 20017e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 20027e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 20037e860f15SJohn Edward Broadbent resetToDefaults["target"] = 20047e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 2005613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 2006613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 20077e860f15SJohn Edward Broadbent 20087c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20092b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 20107c8c4058STejas Patil 20117c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 20127c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 20137c8c4058STejas Patil redfishDateTimeOffset.second; 20147e860f15SJohn Edward Broadbent 20150e8ac5e7SGunnar Mills // TODO (Gunnar): Remove these one day since moved to ComputerSystem 20160e8ac5e7SGunnar Mills // Still used by OCP profiles 20170e8ac5e7SGunnar Mills // https://github.com/opencomputeproject/OCP-Profiles/issues/23 20187e860f15SJohn Edward Broadbent // Fill in SerialConsole info 20197e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 2020002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 2021613dabeaSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = 2022613dabeaSEd Tanous nlohmann::json::array_t({"IPMI", "SSH"}); 20237e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 20247e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 2025002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 2026002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 2027002d39b4SEd Tanous 4; 2028613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 2029613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 20307e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 20317f3e84a1SEd Tanous if constexpr (!bmcwebEnableMultiHost) 20327f3e84a1SEd Tanous { 20337f3e84a1SEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 20347f3e84a1SEd Tanous 1; 20351476687dSEd Tanous 20361476687dSEd Tanous nlohmann::json::array_t managerForServers; 20371476687dSEd Tanous nlohmann::json::object_t manager; 20381476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Systems/system"; 2039ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 20401476687dSEd Tanous 20411476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 20421476687dSEd Tanous std::move(managerForServers); 20437f3e84a1SEd Tanous } 204413451e39SWilly Tu if constexpr (bmcwebEnableHealthPopulate) 204513451e39SWilly Tu { 20467e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 20477e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20487e860f15SJohn Edward Broadbent health->populate(); 204913451e39SWilly Tu } 20507e860f15SJohn Edward Broadbent 2051eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 20527e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20537e860f15SJohn Edward Broadbent 20547e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20557e860f15SJohn Edward Broadbent 2056a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2057a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2058a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2059a51fc2d2SSui Chen managerDiagnosticData["@odata.id"] = 2060a51fc2d2SSui Chen "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; 2061a51fc2d2SSui Chen 206254dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 20637e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20647e860f15SJohn Edward Broadbent pids->run(); 206554dce7f5SGunnar Mills #endif 20667e860f15SJohn Edward Broadbent 2067002d39b4SEd Tanous getMainChassisId(asyncResp, 2068002d39b4SEd Tanous [](const std::string& chassisId, 2069002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2070002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 20711476687dSEd Tanous nlohmann::json::array_t managerForChassis; 20728a592810SEd Tanous nlohmann::json::object_t managerObj; 2073ef4c65b7SEd Tanous boost::urls::url chassiUrl = 2074ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 2075eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 2076ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 20771476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 20781476687dSEd Tanous std::move(managerForChassis); 20791476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 2080eddfc437SWilly Tu chassiUrl; 20817e860f15SJohn Edward Broadbent }); 20827e860f15SJohn Edward Broadbent 20831e1e598dSJonathan Doman sdbusplus::asio::getProperty<double>( 20841e1e598dSJonathan Doman *crow::connections::systemBus, "org.freedesktop.systemd1", 2085002d39b4SEd Tanous "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 2086002d39b4SEd Tanous "Progress", 208775815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 20887e860f15SJohn Edward Broadbent if (ec) 20891abe55efSEd Tanous { 209062598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress"); 20917e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20927e860f15SJohn Edward Broadbent return; 20937e860f15SJohn Edward Broadbent } 20941e1e598dSJonathan Doman if (val < 1.0) 20957e860f15SJohn Edward Broadbent { 209675815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 2097002d39b4SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 209875815e5cSEd Tanous return; 20997e860f15SJohn Edward Broadbent } 210075815e5cSEd Tanous checkForQuiesced(asyncResp); 21011e1e598dSJonathan Doman }); 21029c310685SBorawski.Lukasz 2103e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2104e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 2105e99073f5SGeorge Liu dbus::utility::getSubTree( 2106e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 21077e860f15SJohn Edward Broadbent [asyncResp]( 2108e99073f5SGeorge Liu const boost::system::error_code& ec, 2109b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 21107e860f15SJohn Edward Broadbent if (ec) 21111abe55efSEd Tanous { 211262598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); 21137e860f15SJohn Edward Broadbent return; 21147e860f15SJohn Edward Broadbent } 211526f6976fSEd Tanous if (subtree.empty()) 21167e860f15SJohn Edward Broadbent { 211762598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 21187e860f15SJohn Edward Broadbent return; 21197e860f15SJohn Edward Broadbent } 21207e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 21217e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 21227e860f15SJohn Edward Broadbent if (subtree.size() > 1) 21237e860f15SJohn Edward Broadbent { 212462598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 21257e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21267e860f15SJohn Edward Broadbent return; 21277e860f15SJohn Edward Broadbent } 21287e860f15SJohn Edward Broadbent 2129002d39b4SEd Tanous if (subtree[0].first.empty() || subtree[0].second.size() != 1) 21307e860f15SJohn Edward Broadbent { 213162598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 21327e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21337e860f15SJohn Edward Broadbent return; 21347e860f15SJohn Edward Broadbent } 21357e860f15SJohn Edward Broadbent 21367e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2137002d39b4SEd Tanous const std::string& connectionName = subtree[0].second[0].first; 21387e860f15SJohn Edward Broadbent 2139002d39b4SEd Tanous for (const auto& interfaceName : subtree[0].second[0].second) 21407e860f15SJohn Edward Broadbent { 21417e860f15SJohn Edward Broadbent if (interfaceName == 21427e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 21437e860f15SJohn Edward Broadbent { 2144fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2145fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, connectionName, path, 2146fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 21475e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 2148b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 21497e860f15SJohn Edward Broadbent propertiesList) { 21508a592810SEd Tanous if (ec2) 21517e860f15SJohn Edward Broadbent { 215262598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't get bmc asset!"); 21537e860f15SJohn Edward Broadbent return; 21547e860f15SJohn Edward Broadbent } 21557e860f15SJohn Edward Broadbent 2156fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 2157fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 2158fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 2159fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 2160fac6e53bSKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 2161fac6e53bSKrzysztof Grobelny 2162fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2163fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), propertiesList, 2164fac6e53bSKrzysztof Grobelny "PartNumber", partNumber, "SerialNumber", 2165fac6e53bSKrzysztof Grobelny serialNumber, "Manufacturer", manufacturer, "Model", 2166fac6e53bSKrzysztof Grobelny model, "SparePartNumber", sparePartNumber); 2167fac6e53bSKrzysztof Grobelny 2168fac6e53bSKrzysztof Grobelny if (!success) 21697e860f15SJohn Edward Broadbent { 2170002d39b4SEd Tanous messages::internalError(asyncResp->res); 21717e860f15SJohn Edward Broadbent return; 21727e860f15SJohn Edward Broadbent } 2173fac6e53bSKrzysztof Grobelny 2174fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 2175fac6e53bSKrzysztof Grobelny { 2176fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 2177fac6e53bSKrzysztof Grobelny *partNumber; 21787e860f15SJohn Edward Broadbent } 2179fac6e53bSKrzysztof Grobelny 2180fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 2181fac6e53bSKrzysztof Grobelny { 2182fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SerialNumber"] = 2183fac6e53bSKrzysztof Grobelny *serialNumber; 21847e860f15SJohn Edward Broadbent } 2185fac6e53bSKrzysztof Grobelny 2186fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 2187fac6e53bSKrzysztof Grobelny { 2188fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Manufacturer"] = 2189fac6e53bSKrzysztof Grobelny *manufacturer; 2190fac6e53bSKrzysztof Grobelny } 2191fac6e53bSKrzysztof Grobelny 2192fac6e53bSKrzysztof Grobelny if (model != nullptr) 2193fac6e53bSKrzysztof Grobelny { 2194fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Model"] = *model; 2195fac6e53bSKrzysztof Grobelny } 2196fac6e53bSKrzysztof Grobelny 2197fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 2198fac6e53bSKrzysztof Grobelny { 2199fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SparePartNumber"] = 2200fac6e53bSKrzysztof Grobelny *sparePartNumber; 2201fac6e53bSKrzysztof Grobelny } 2202fac6e53bSKrzysztof Grobelny }); 22037e860f15SJohn Edward Broadbent } 2204002d39b4SEd Tanous else if (interfaceName == 22050fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 22067e860f15SJohn Edward Broadbent { 22077e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 22087e860f15SJohn Edward Broadbent } 22097e860f15SJohn Edward Broadbent } 2210e99073f5SGeorge Liu }); 22117e860f15SJohn Edward Broadbent }); 22127e860f15SJohn Edward Broadbent 22137e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2214ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 221545ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 221645ca1b86SEd Tanous [&app](const crow::Request& req, 22177e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22183ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 221945ca1b86SEd Tanous { 222045ca1b86SEd Tanous return; 222145ca1b86SEd Tanous } 22227e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 22237e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 22247e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 22257e860f15SJohn Edward Broadbent 222615ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem, 2227002d39b4SEd Tanous "DateTime", datetime, "Links", links)) 22287e860f15SJohn Edward Broadbent { 22297e860f15SJohn Edward Broadbent return; 22307e860f15SJohn Edward Broadbent } 22317e860f15SJohn Edward Broadbent 22327e860f15SJohn Edward Broadbent if (oem) 22337e860f15SJohn Edward Broadbent { 223454dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 22357e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 2236002d39b4SEd Tanous if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc", 2237002d39b4SEd Tanous openbmc)) 22387e860f15SJohn Edward Broadbent { 22397e860f15SJohn Edward Broadbent return; 22407e860f15SJohn Edward Broadbent } 22417e860f15SJohn Edward Broadbent if (openbmc) 22427e860f15SJohn Edward Broadbent { 22437e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 2244002d39b4SEd Tanous if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 2245002d39b4SEd Tanous "Fan", fan)) 22467e860f15SJohn Edward Broadbent { 22477e860f15SJohn Edward Broadbent return; 22487e860f15SJohn Edward Broadbent } 22497e860f15SJohn Edward Broadbent if (fan) 22507e860f15SJohn Edward Broadbent { 2251002d39b4SEd Tanous auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan); 22527e860f15SJohn Edward Broadbent pid->run(); 22537e860f15SJohn Edward Broadbent } 22547e860f15SJohn Edward Broadbent } 225554dce7f5SGunnar Mills #else 225654dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem"); 225754dce7f5SGunnar Mills return; 225854dce7f5SGunnar Mills #endif 22597e860f15SJohn Edward Broadbent } 22607e860f15SJohn Edward Broadbent if (links) 22617e860f15SJohn Edward Broadbent { 22627e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22637e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22647e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22657e860f15SJohn Edward Broadbent activeSoftwareImage)) 22667e860f15SJohn Edward Broadbent { 22677e860f15SJohn Edward Broadbent return; 22687e860f15SJohn Edward Broadbent } 22697e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22707e860f15SJohn Edward Broadbent { 22717e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 2272002d39b4SEd Tanous if (!json_util::readJson(*activeSoftwareImage, asyncResp->res, 2273002d39b4SEd Tanous "@odata.id", odataId)) 22747e860f15SJohn Edward Broadbent { 22757e860f15SJohn Edward Broadbent return; 22767e860f15SJohn Edward Broadbent } 22777e860f15SJohn Edward Broadbent 22787e860f15SJohn Edward Broadbent if (odataId) 22797e860f15SJohn Edward Broadbent { 22807e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22817e860f15SJohn Edward Broadbent } 22827e860f15SJohn Edward Broadbent } 22837e860f15SJohn Edward Broadbent } 22847e860f15SJohn Edward Broadbent if (datetime) 22857e860f15SJohn Edward Broadbent { 2286*c51afd54SEd Tanous setDateTime(asyncResp, *datetime); 22877e860f15SJohn Edward Broadbent } 22887e860f15SJohn Edward Broadbent }); 22897e860f15SJohn Edward Broadbent } 22907e860f15SJohn Edward Broadbent 22917e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22927e860f15SJohn Edward Broadbent { 22937e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2294ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 22957e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 229645ca1b86SEd Tanous [&app](const crow::Request& req, 22977e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22983ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 229945ca1b86SEd Tanous { 230045ca1b86SEd Tanous return; 230145ca1b86SEd Tanous } 230283ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 230383ff9ab6SJames Feist // because it has a duplicate entry for members 23048d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 23058d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 23068d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 23078d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 23088d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 23091476687dSEd Tanous nlohmann::json::array_t members; 23101476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 23111476687dSEd Tanous bmc["@odata.id"] = "/redfish/v1/Managers/bmc"; 23121476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 23137e860f15SJohn Edward Broadbent }); 23149c310685SBorawski.Lukasz } 23159c310685SBorawski.Lukasz } // namespace redfish 2316