diff options
author | Lakshmi Yadlapati <lakshmiy@us.ibm.com> | 2023-10-25 23:31:25 +0300 |
---|---|---|
committer | Lakshmi Yadlapati <lakshmiy@us.ibm.com> | 2023-10-26 19:38:26 +0300 |
commit | a974c132c8eaa591acaa92019f9b0088b4815ff1 (patch) | |
tree | 299b8925d6d04ea53fbf27af93a9f85813bdc511 /redfish-core | |
parent | db7b3876bc537dc927f162952e060d91ed1e3f7b (diff) | |
download | bmcweb-a974c132c8eaa591acaa92019f9b0088b4815ff1.tar.xz |
Refactor getComputerSystem
This commit refactors the getComputerSystem function into smaller
functions. There is no functional change in this commit.
Tested: Validator passed
'''
curl -k https://$bmc/redfish/v1/Systems/system
{
"@odata.id": "/redfish/v1/Systems/system",
"@odata.type": "#ComputerSystem.v1_16_0.ComputerSystem",
"Actions": {
"#ComputerSystem.Reset": {
"@Redfish.ActionInfo": "/redfish/v1/Systems/system/ResetActionInfo",
"target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"
}
},
"Bios": {
"@odata.id": "/redfish/v1/Systems/system/Bios"
},
"Boot": {
"AutomaticRetryAttempts": 3,
"AutomaticRetryConfig": "RetryAttempts",
"AutomaticRetryConfig@Redfish.AllowableValues": [
"Disabled",
"RetryAttempts"
],
"BootSourceOverrideEnabled": "Disabled",
"BootSourceOverrideMode": "UEFI",
"BootSourceOverrideMode@Redfish.AllowableValues": [
"Legacy",
"UEFI"
],
"BootSourceOverrideTarget": "None",
"BootSourceOverrideTarget@Redfish.AllowableValues": [
"None",
"Pxe",
"Hdd",
"Cd",
"Diags",
"BiosSetup",
"Usb"
],
"RemainingAutomaticRetryAttempts": 3,
"StopBootOnFault": "Never",
"TrustedModuleRequiredToBoot": "Required"
},
"BootProgress": {
"LastState": "None",
"LastStateTime": "1970-01-01T00:00:00.000000+00:00"
},
"Description": "Computer System",
"FabricAdapters": {
"@odata.id": "/redfish/v1/Systems/system/FabricAdapters"
},
"GraphicalConsole": {
"ConnectTypesSupported": [
"KVMIP"
],
"MaxConcurrentSessions": 4,
"ServiceEnabled": true
},
"Id": "system",
"IndicatorLED": "Off",
"LastResetTime": "2023-09-29T13:27:47+00:00",
"Links": {
"Chassis": [
{
"@odata.id": "/redfish/v1/Chassis/chassis"
}
],
"ManagedBy": [
{
"@odata.id": "/redfish/v1/Managers/bmc"
}
]
},
"LocationIndicatorActive": false,
"LogServices": {
"@odata.id": "/redfish/v1/Systems/system/LogServices"
},
"Memory": {
"@odata.id": "/redfish/v1/Systems/system/Memory"
},
"MemorySummary": {
"TotalSystemMemoryGiB": 0.0
},
"Name": "system",
"PCIeDevices": [],
"PCIeDevices@odata.count": 0,
"PowerRestorePolicy": "LastState",
"PowerState": "Off",
"ProcessorSummary": {
"Count": 0
},
"Processors": {
"@odata.id": "/redfish/v1/Systems/system/Processors"
},
"SerialConsole": {
"IPMI": {
"ServiceEnabled": true
},
"MaxConcurrentSessions": 15,
"SSH": {
"HotKeySequenceDisplay": "Press ~. to exit console",
"Port": 2200,
"ServiceEnabled": true
}
},
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Disabled"
},
"Storage": {
"@odata.id": "/redfish/v1/Systems/system/Storage"
},
"SystemType": "Physical"
}
'''
Change-Id: I16a0c054dfff4ace0b43e156a64fd07b3244fbc1
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/lib/systems.hpp | 440 |
1 files changed, 225 insertions, 215 deletions
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index d8cf644cb5..399989848b 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -346,243 +346,253 @@ inline void }); } -/* - * @brief Retrieves computer system properties over dbus - * - * @param[in] asyncResp Shared pointer for completing asynchronous calls - * @param[in] systemHealth Shared HealthPopulate pointer - * - * @return None. - */ -inline void - getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::shared_ptr<HealthPopulate>& systemHealth) +inline void afterGetUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const boost::system::error_code& ec, + const dbus::utility::DBusPropertiesMap& properties) { - BMCWEB_LOG_DEBUG("Get available system components."); - constexpr std::array<std::string_view, 5> interfaces = { - "xyz.openbmc_project.Inventory.Decorator.Asset", - "xyz.openbmc_project.Inventory.Item.Cpu", - "xyz.openbmc_project.Inventory.Item.Dimm", - "xyz.openbmc_project.Inventory.Item.System", - "xyz.openbmc_project.Common.UUID", - }; - dbus::utility::getSubTree( - "/xyz/openbmc_project/inventory", 0, interfaces, - [asyncResp, - systemHealth](const boost::system::error_code& ec, - const dbus::utility::MapperGetSubTreeResponse& subtree) { - if (ec) + if (ec) + { + BMCWEB_LOG_ERROR("DBUS response error {}", ec); + messages::internalError(asyncResp->res); + return; + } + BMCWEB_LOG_DEBUG("Got {} UUID properties.", properties.size()); + + const std::string* uUID = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), properties, "UUID", uUID); + + if (!success) + { + messages::internalError(asyncResp->res); + return; + } + + if (uUID != nullptr) + { + std::string valueStr = *uUID; + if (valueStr.size() == 32) { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; + valueStr.insert(8, 1, '-'); + valueStr.insert(13, 1, '-'); + valueStr.insert(18, 1, '-'); + valueStr.insert(23, 1, '-'); } - // Iterate over all retrieved ObjectPaths. - for (const std::pair< - std::string, - std::vector<std::pair<std::string, std::vector<std::string>>>>& - object : subtree) + BMCWEB_LOG_DEBUG("UUID = {}", valueStr); + asyncResp->res.jsonValue["UUID"] = valueStr; + } +} + +inline void + afterGetInventory(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const boost::system::error_code& ec, + const dbus::utility::DBusPropertiesMap& propertiesList) +{ + if (ec) + { + // doesn't have to include this + // interface + return; + } + BMCWEB_LOG_DEBUG("Got {} properties for system", propertiesList.size()); + + const std::string* partNumber = nullptr; + const std::string* serialNumber = nullptr; + const std::string* manufacturer = nullptr; + const std::string* model = nullptr; + const std::string* subModel = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", + partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, + "Model", model, "SubModel", subModel); + + if (!success) + { + messages::internalError(asyncResp->res); + return; + } + + if (partNumber != nullptr) + { + asyncResp->res.jsonValue["PartNumber"] = *partNumber; + } + + if (serialNumber != nullptr) + { + asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; + } + + if (manufacturer != nullptr) + { + asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; + } + + if (model != nullptr) + { + asyncResp->res.jsonValue["Model"] = *model; + } + + if (subModel != nullptr) + { + asyncResp->res.jsonValue["SubModel"] = *subModel; + } + + // Grab the bios version + sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, + "BiosVersion", false); +} + +inline void + afterGetAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const boost::system::error_code& ec, + const std::string& value) +{ + if (ec) + { + // doesn't have to include this + // interface + return; + } + + asyncResp->res.jsonValue["AssetTag"] = value; +} + +inline void afterSystemGetSubTree( + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::shared_ptr<HealthPopulate>& systemHealth, + const boost::system::error_code& ec, + const dbus::utility::MapperGetSubTreeResponse& subtree) +{ + if (ec) + { + BMCWEB_LOG_ERROR("DBUS response error {}", ec); + messages::internalError(asyncResp->res); + return; + } + // Iterate over all retrieved ObjectPaths. + for (const std::pair< + std::string, + std::vector<std::pair<std::string, std::vector<std::string>>>>& + object : subtree) + { + const std::string& path = object.first; + BMCWEB_LOG_DEBUG("Got path: {}", path); + const std::vector<std::pair<std::string, std::vector<std::string>>>& + connectionNames = object.second; + if (connectionNames.empty()) { - const std::string& path = object.first; - BMCWEB_LOG_DEBUG("Got path: {}", path); - const std::vector<std::pair<std::string, std::vector<std::string>>>& - connectionNames = object.second; - if (connectionNames.empty()) - { - continue; - } + continue; + } - std::shared_ptr<HealthPopulate> memoryHealth = nullptr; - std::shared_ptr<HealthPopulate> cpuHealth = nullptr; + std::shared_ptr<HealthPopulate> memoryHealth = nullptr; + std::shared_ptr<HealthPopulate> cpuHealth = nullptr; - if constexpr (bmcwebEnableProcMemStatus) - { - memoryHealth = std::make_shared<HealthPopulate>( - asyncResp, "/MemorySummary/Status"_json_pointer); - systemHealth->children.emplace_back(memoryHealth); + if constexpr (bmcwebEnableProcMemStatus) + { + memoryHealth = std::make_shared<HealthPopulate>( + asyncResp, "/MemorySummary/Status"_json_pointer); + systemHealth->children.emplace_back(memoryHealth); - if constexpr (bmcwebEnableHealthPopulate) - { - cpuHealth = std::make_shared<HealthPopulate>( - asyncResp, "/ProcessorSummary/Status"_json_pointer); + if constexpr (bmcwebEnableHealthPopulate) + { + cpuHealth = std::make_shared<HealthPopulate>( + asyncResp, "/ProcessorSummary/Status"_json_pointer); - systemHealth->children.emplace_back(cpuHealth); - } + systemHealth->children.emplace_back(cpuHealth); } + } - // This is not system, so check if it's cpu, dimm, UUID or - // BiosVer - for (const auto& connection : connectionNames) + // This is not system, so check if it's cpu, dimm, UUID or + // BiosVer + for (const auto& connection : connectionNames) + { + for (const auto& interfaceName : connection.second) { - for (const auto& interfaceName : connection.second) + if (interfaceName == "xyz.openbmc_project.Inventory.Item.Dimm") { - if (interfaceName == - "xyz.openbmc_project.Inventory.Item.Dimm") - { - BMCWEB_LOG_DEBUG("Found Dimm, now get its properties."); + BMCWEB_LOG_DEBUG("Found Dimm, now get its properties."); - getMemorySummary(asyncResp, connection.first, path); + getMemorySummary(asyncResp, connection.first, path); - if constexpr (bmcwebEnableProcMemStatus) - { - memoryHealth->inventory.emplace_back(path); - } - } - else if (interfaceName == - "xyz.openbmc_project.Inventory.Item.Cpu") + if constexpr (bmcwebEnableProcMemStatus) { - BMCWEB_LOG_DEBUG("Found Cpu, now get its properties."); + memoryHealth->inventory.emplace_back(path); + } + } + else if (interfaceName == + "xyz.openbmc_project.Inventory.Item.Cpu") + { + BMCWEB_LOG_DEBUG("Found Cpu, now get its properties."); - getProcessorSummary(asyncResp, connection.first, path); + getProcessorSummary(asyncResp, connection.first, path); - if constexpr (bmcwebEnableProcMemStatus) - { - cpuHealth->inventory.emplace_back(path); - } - } - else if (interfaceName == "xyz.openbmc_project.Common.UUID") + if constexpr (bmcwebEnableProcMemStatus) { - BMCWEB_LOG_DEBUG("Found UUID, now get its properties."); - - sdbusplus::asio::getAllProperties( - *crow::connections::systemBus, connection.first, - path, "xyz.openbmc_project.Common.UUID", - [asyncResp](const boost::system::error_code& ec3, - const dbus::utility::DBusPropertiesMap& - properties) { - if (ec3) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec3); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Got {} UUID properties.", - properties.size()); - - const std::string* uUID = nullptr; - - const bool success = - sdbusplus::unpackPropertiesNoThrow( - dbus_utils::UnpackErrorPrinter(), - properties, "UUID", uUID); - - if (!success) - { - messages::internalError(asyncResp->res); - return; - } - - if (uUID != nullptr) - { - std::string valueStr = *uUID; - if (valueStr.size() == 32) - { - valueStr.insert(8, 1, '-'); - valueStr.insert(13, 1, '-'); - valueStr.insert(18, 1, '-'); - valueStr.insert(23, 1, '-'); - } - BMCWEB_LOG_DEBUG("UUID = {}", valueStr); - asyncResp->res.jsonValue["UUID"] = valueStr; - } - }); - } - else if (interfaceName == - "xyz.openbmc_project.Inventory.Item.System") - { - sdbusplus::asio::getAllProperties( - *crow::connections::systemBus, connection.first, - path, - "xyz.openbmc_project.Inventory.Decorator.Asset", - [asyncResp](const boost::system::error_code& ec2, - const dbus::utility::DBusPropertiesMap& - propertiesList) { - if (ec2) - { - // doesn't have to include this - // interface - return; - } - BMCWEB_LOG_DEBUG("Got {} properties for system", - propertiesList.size()); - - const std::string* partNumber = nullptr; - const std::string* serialNumber = nullptr; - const std::string* manufacturer = nullptr; - const std::string* model = nullptr; - const std::string* subModel = nullptr; - - const bool success = - sdbusplus::unpackPropertiesNoThrow( - dbus_utils::UnpackErrorPrinter(), - propertiesList, "PartNumber", partNumber, - "SerialNumber", serialNumber, - "Manufacturer", manufacturer, "Model", - model, "SubModel", subModel); - - if (!success) - { - messages::internalError(asyncResp->res); - return; - } - - if (partNumber != nullptr) - { - asyncResp->res.jsonValue["PartNumber"] = - *partNumber; - } - - if (serialNumber != nullptr) - { - asyncResp->res.jsonValue["SerialNumber"] = - *serialNumber; - } - - if (manufacturer != nullptr) - { - asyncResp->res.jsonValue["Manufacturer"] = - *manufacturer; - } - - if (model != nullptr) - { - asyncResp->res.jsonValue["Model"] = *model; - } - - if (subModel != nullptr) - { - asyncResp->res.jsonValue["SubModel"] = - *subModel; - } - - // Grab the bios version - sw_util::populateSoftwareInformation( - asyncResp, sw_util::biosPurpose, "BiosVersion", - false); - }); - - sdbusplus::asio::getProperty<std::string>( - *crow::connections::systemBus, connection.first, - path, - "xyz.openbmc_project.Inventory.Decorator." - "AssetTag", - "AssetTag", - [asyncResp](const boost::system::error_code& ec2, - const std::string& value) { - if (ec2) - { - // doesn't have to include this - // interface - return; - } - - asyncResp->res.jsonValue["AssetTag"] = value; - }); + cpuHealth->inventory.emplace_back(path); } } + else if (interfaceName == "xyz.openbmc_project.Common.UUID") + { + BMCWEB_LOG_DEBUG("Found UUID, now get its properties."); + + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, connection.first, path, + "xyz.openbmc_project.Common.UUID", + [asyncResp](const boost::system::error_code& ec3, + const dbus::utility::DBusPropertiesMap& + properties) { + afterGetUUID(asyncResp, ec3, properties); + }); + } + else if (interfaceName == + "xyz.openbmc_project.Inventory.Item.System") + { + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, connection.first, path, + "xyz.openbmc_project.Inventory.Decorator.Asset", + [asyncResp](const boost::system::error_code& ec3, + const dbus::utility::DBusPropertiesMap& + properties) { + afterGetInventory(asyncResp, ec3, properties); + }); + + sdbusplus::asio::getProperty<std::string>( + *crow::connections::systemBus, connection.first, path, + "xyz.openbmc_project.Inventory.Decorator." + "AssetTag", + "AssetTag", + std::bind_front(afterGetAssetTag, asyncResp)); + } } } - }); + } +} + +/* + * @brief Retrieves computer system properties over dbus + * + * @param[in] asyncResp Shared pointer for completing asynchronous calls + * @param[in] systemHealth Shared HealthPopulate pointer + * + * @return None. + */ +inline void + getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::shared_ptr<HealthPopulate>& systemHealth) +{ + BMCWEB_LOG_DEBUG("Get available system components."); + constexpr std::array<std::string_view, 5> interfaces = { + "xyz.openbmc_project.Inventory.Decorator.Asset", + "xyz.openbmc_project.Inventory.Item.Cpu", + "xyz.openbmc_project.Inventory.Item.Dimm", + "xyz.openbmc_project.Inventory.Item.System", + "xyz.openbmc_project.Common.UUID", + }; + dbus::utility::getSubTree( + "/xyz/openbmc_project/inventory", 0, interfaces, + std::bind_front(afterSystemGetSubTree, asyncResp, systemHealth)); } /** |