Remove the providers interface from systems
The providers class is entirely static, and has no real purpose at this
point in time. This commit removes it so we don't copy the pattern in
other places.
Tested By:
Ran a subset of gets and patches to the computer system schema,
observed the same behavior.
Change-Id: Ia9e49aee6bd944aeadb2536de38a905b25047d9e
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 229ec0b..44c1170 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -24,613 +24,563 @@
namespace redfish
{
-/**
- * OnDemandSystemsProvider
- * Board provider class that retrieves data directly from dbus, before seting
- * it into JSON output. This does not cache any data.
- *
- * Class can be a good example on how to scale different data providing
- * solutions to produce single schema output.
- *
- * TODO(Pawel)
- * This perhaps shall be different file, which has to be chosen on compile time
- * depending on OEM needs
- */
-class OnDemandSystemsProvider
+template <typename CallbackFunc> void getBaseboardList(CallbackFunc &&callback)
{
- public:
- template <typename CallbackFunc>
- void getBaseboardList(CallbackFunc &&callback)
- {
- BMCWEB_LOG_DEBUG << "Get list of available boards.";
- crow::connections::systemBus->async_method_call(
- [callback{std::move(callback)}](
- const boost::system::error_code ec,
- const std::vector<std::string> &resp) {
- // Callback requires vector<string> to retrieve all available
- // board list.
- std::vector<std::string> boardList;
- if (ec)
+ BMCWEB_LOG_DEBUG << "Get list of available boards.";
+ crow::connections::systemBus->async_method_call(
+ [callback{std::move(callback)}](const boost::system::error_code ec,
+ const std::vector<std::string> &resp) {
+ // Callback requires vector<string> to retrieve all available board
+ // list.
+ std::vector<std::string> boardList;
+ if (ec)
+ {
+ // Something wrong on DBus, the error_code is not important at
+ // this moment, just return success=false, and empty output.
+ // Since size of vector may vary depending on information from
+ // Entity Manager, and empty output could not be treated same
+ // way as error.
+ callback(false, boardList);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got " << resp.size() << " boards.";
+ // Iterate over all retrieved ObjectPaths.
+ for (const std::string &objpath : resp)
+ {
+ std::size_t lastPos = objpath.rfind("/");
+ if (lastPos != std::string::npos)
{
- // Something wrong on DBus, the error_code is not important
- // at this moment, just return success=false, and empty
- // output. Since size of vector may vary depending on
- // information from Entity Manager, and empty output could
- // not be treated same way as error.
- callback(false, boardList);
- return;
+ boardList.emplace_back(objpath.substr(lastPos + 1));
}
- BMCWEB_LOG_DEBUG << "Got " << resp.size() << " boards.";
- // Iterate over all retrieved ObjectPaths.
- for (const std::string &objpath : resp)
- {
- std::size_t lastPos = objpath.rfind("/");
- if (lastPos != std::string::npos)
- {
- boardList.emplace_back(objpath.substr(lastPos + 1));
- }
- }
- // Finally make a callback with useful data
- callback(true, boardList);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
- "/xyz/openbmc_project/inventory", int32_t(0),
- std::array<const char *, 1>{
- "xyz.openbmc_project.Inventory.Item.Board"});
- };
-
- /**
- * @brief Retrieves computer system properties over dbus
- *
- * @param[in] aResp Shared pointer for completing asynchronous calls
- * @param[in] name Computer system name from request
- *
- * @return None.
- */
- void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
- const std::string &name)
- {
- const std::array<const char *, 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",
- };
- BMCWEB_LOG_DEBUG << "Get available system components.";
- crow::connections::systemBus->async_method_call(
- [name, aResp{std::move(aResp)}](
- const boost::system::error_code ec,
- const std::vector<std::pair<
- std::string, std::vector<std::pair<
- std::string, std::vector<std::string>>>>>
- &subtree) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error";
- aResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- bool foundName = false;
- // 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.size() < 1)
- {
- continue;
- }
- // Check if computer system exist
- if (boost::ends_with(path, name))
- {
- foundName = true;
- BMCWEB_LOG_DEBUG << "Found name: " << name;
- const std::string connectionName =
- connectionNames[0].first;
- crow::connections::systemBus->async_method_call(
- [aResp, name(std::string(name))](
- const boost::system::error_code ec,
- const std::vector<
- std::pair<std::string, VariantType>>
- &propertiesList) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "DBUS response error: "
- << ec;
- aResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG << "Got "
- << propertiesList.size()
- << "properties for system";
- for (const std::pair<std::string, VariantType>
- &property : propertiesList)
- {
- const std::string *value =
- mapbox::getPtr<const std::string>(
- property.second);
- if (value != nullptr)
- {
- aResp->res.jsonValue[property.first] =
- *value;
- }
- }
- aResp->res.jsonValue["Name"] = name;
- aResp->res.jsonValue["Id"] =
- aResp->res.jsonValue["SerialNumber"];
- },
- connectionName, path,
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Inventory.Decorator.Asset");
- }
- else
- {
- // This is not system, so check if it's cpu, dimm, UUID
- // or BiosVer
- for (auto const &s : connectionNames)
- {
- for (auto const &i : s.second)
- {
- if (boost::ends_with(i, "Dimm"))
- {
- BMCWEB_LOG_DEBUG
- << "Found Dimm, now get it properties.";
- crow::connections::systemBus->async_method_call(
- [&, aResp](
- const boost::system::error_code ec,
- const std::vector<std::pair<
- std::string, VariantType>>
- &properties) {
- if (ec)
- {
- BMCWEB_LOG_ERROR
- << "DBUS response error "
- << ec;
- aResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG
- << "Got " << properties.size()
- << "Dimm properties.";
- for (const auto &p : properties)
- {
- if (p.first == "MemorySize")
- {
- const std::string *value =
- mapbox::getPtr<
- const std::string>(
- p.second);
- if ((value != nullptr) &&
- (*value != "NULL"))
- {
- // Remove units char
- int32_t unitCoeff;
- if (boost::ends_with(
- *value, "MB"))
- {
- unitCoeff = 1000;
- }
- else if (boost::
- ends_with(
- *value,
- "KB"))
- {
- unitCoeff = 1000000;
- }
- else
- {
- BMCWEB_LOG_ERROR
- << "Unsupported"
- " memory "
- "units";
- aResp->res.result(
- boost::beast::
- http::status::
- internal_server_error);
- return;
- }
-
- auto memSize =
- boost::lexical_cast<
- int>(value->substr(
- 0,
- value->length() -
- 2));
- aResp->res.jsonValue
- ["TotalSystemMemory"
- "GiB"] +=
- memSize * unitCoeff;
- aResp->res.jsonValue
- ["MemorySummary"]
- ["Status"]
- ["State"] =
- "Enabled";
- }
- }
- }
- },
- s.first, path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- "xyz.openbmc_project.Inventory.Item."
- "Dimm");
- }
- else if (boost::ends_with(i, "Cpu"))
- {
- BMCWEB_LOG_DEBUG
- << "Found Cpu, now get it properties.";
- crow::connections::systemBus->async_method_call(
- [&, aResp](
- const boost::system::error_code ec,
- const std::vector<std::pair<
- std::string, VariantType>>
- &properties) {
- if (ec)
- {
- BMCWEB_LOG_ERROR
- << "DBUS response error "
- << ec;
- aResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG
- << "Got " << properties.size()
- << "Cpu properties.";
- for (const auto &p : properties)
- {
- if (p.first ==
- "ProcessorFamily")
- {
- const std::string *value =
- mapbox::getPtr<
- const std::string>(
- p.second);
- if (value != nullptr)
- {
- aResp->res.jsonValue
- ["ProcessorSummary"]
- ["Count"] =
- aResp->res
- .jsonValue
- ["Processor"
- "Summary"]
- ["Count"]
- .get<int>() +
- 1;
- aResp->res.jsonValue
- ["ProcessorSummary"]
- ["Status"]
- ["State"] =
- "Enabled";
- aResp->res.jsonValue
- ["ProcessorSummary"]
- ["Model"] = *value;
- }
- }
- }
- },
- s.first, path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- "xyz.openbmc_project.Inventory.Item."
- "Cpu");
- }
- else if (boost::ends_with(i, "UUID"))
- {
- BMCWEB_LOG_DEBUG
- << "Found UUID, now get it properties.";
- crow::connections::systemBus->async_method_call(
- [aResp](
- const boost::system::error_code ec,
- const std::vector<std::pair<
- std::string, VariantType>>
- &properties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "DBUS response error "
- << ec;
- aResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG
- << "Got " << properties.size()
- << "UUID properties.";
- for (const std::pair<std::string,
- VariantType>
- &p : properties)
- {
- if (p.first == "BIOSVer")
- {
- const std::string *value =
- mapbox::getPtr<
- const std::string>(
- p.second);
- if (value != nullptr)
- {
- aResp->res.jsonValue
- ["BiosVersion"] =
- *value;
- }
- }
- if (p.first == "UUID")
- {
- const std::string *value =
- mapbox::getPtr<
- const std::string>(
- p.second);
- BMCWEB_LOG_DEBUG
- << "UUID = " << *value
- << " length "
- << value->length();
- if (value != nullptr)
- {
- // Workaround for to
- // short return str in
- // smbios demo app, 32
- // bytes are described
- // by spec
- if (value->length() >
- 0 &&
- value->length() <
- 32)
- {
- std::string
- correctedValue =
- *value;
- correctedValue.append(
- 32 -
- value
- ->length(),
- '0');
- value =
- &correctedValue;
- }
- else if (
- value->length() ==
- 32)
- {
- aResp->res.jsonValue
- ["UUID"] =
- value->substr(
- 0, 8) +
- "-" +
- value->substr(
- 8, 4) +
- "-" +
- value->substr(
- 12, 4) +
- "-" +
- value->substr(
- 16, 4) +
- "-" +
- value->substr(
- 20, 12);
- }
- }
- }
- }
- },
- s.first, path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- "xyz.openbmc_project.Common.UUID");
- }
- }
- }
- }
- }
- if (foundName == false)
- {
- aResp->res.result(
- boost::beast::http::status::internal_server_error);
- }
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", int32_t(0), interfaces);
- }
-
- /**
- * @brief Retrieves identify led group properties over dbus
- *
- * @param[in] aResp Shared pointer for completing asynchronous calls.
- * @param[in] callback Callback for process retrieved data.
- *
- * @return None.
- */
- template <typename CallbackFunc>
- void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
- CallbackFunc &&callback)
- {
- BMCWEB_LOG_DEBUG << "Get led groups";
- crow::connections::systemBus->async_method_call(
- [aResp{std::move(aResp)},
- &callback](const boost::system::error_code &ec,
- const ManagedObjectsType &resp) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
- aResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG << "Got " << resp.size()
- << "led group objects.";
- for (const auto &objPath : resp)
- {
- const std::string &path = objPath.first;
- if (path.rfind("enclosure_identify") != std::string::npos)
- {
- for (const auto &interface : objPath.second)
- {
- if (interface.first ==
- "xyz.openbmc_project.Led.Group")
- {
- for (const auto &property : interface.second)
- {
- if (property.first == "Asserted")
- {
- const bool *asserted =
- mapbox::getPtr<const bool>(
- property.second);
- if (nullptr != asserted)
- {
- callback(*asserted, aResp);
- }
- else
- {
- callback(false, aResp);
- }
- }
- }
- }
- }
- }
- }
- },
- "xyz.openbmc_project.LED.GroupManager",
- "/xyz/openbmc_project/led/groups",
- "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
- }
-
- template <typename CallbackFunc>
- void getLedIdentify(std::shared_ptr<AsyncResp> aResp,
- CallbackFunc &&callback)
- {
- BMCWEB_LOG_DEBUG << "Get identify led properties";
- crow::connections::systemBus->async_method_call(
- [aResp{std::move(aResp)},
- &callback](const boost::system::error_code ec,
- const PropertiesType &properties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
- aResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG << "Got " << properties.size()
- << "led properties.";
- std::string output;
- for (const auto &property : properties)
- {
- if (property.first == "State")
- {
- const std::string *s =
- mapbox::getPtr<std::string>(property.second);
- if (nullptr != s)
- {
- BMCWEB_LOG_DEBUG << "Identify Led State: " << *s;
- const auto pos = s->rfind('.');
- if (pos != std::string::npos)
- {
- auto led = s->substr(pos + 1);
- for (const std::pair<const char *, const char *>
- &p :
- std::array<
- std::pair<const char *, const char *>,
- 3>{{{"On", "Lit"},
- {"Blink", "Blinking"},
- {"Off", "Off"}}})
- {
- if (led == p.first)
- {
- output = p.second;
- }
- }
- }
- }
- }
- }
- callback(output, aResp);
- },
- "xyz.openbmc_project.LED.Controller.identify",
- "/xyz/openbmc_project/led/physical/identify",
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Led.Physical");
- }
-
- /**
- * @brief Retrieves host state properties over dbus
- *
- * @param[in] aResp Shared pointer for completing asynchronous calls.
- *
- * @return None.
- */
- void getHostState(std::shared_ptr<AsyncResp> aResp)
- {
- BMCWEB_LOG_DEBUG << "Get host information.";
- crow::connections::systemBus->async_method_call(
- [aResp{std::move(aResp)}](const boost::system::error_code ec,
- const PropertiesType &properties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
- aResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- BMCWEB_LOG_DEBUG << "Got " << properties.size()
- << "host properties.";
- for (const auto &property : properties)
- {
- if (property.first == "CurrentHostState")
- {
- const std::string *s =
- mapbox::getPtr<const std::string>(property.second);
- BMCWEB_LOG_DEBUG << "Host state: " << *s;
- if (nullptr != s)
- {
- const auto pos = s->rfind('.');
- if (pos != std::string::npos)
- {
- // Verify Host State
- if (s->substr(pos + 1) == "Running")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] =
- "Enabled";
- }
- else
- {
- aResp->res.jsonValue["PowerState"] = "Off";
- aResp->res.jsonValue["Status"]["State"] =
- "Disabled";
- }
- }
- }
- }
- }
- },
- "xyz.openbmc_project.State.Host",
- "/xyz/openbmc_project/state/host0",
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.State.Host");
- }
+ }
+ // Finally make a callback with useful data
+ callback(true, boardList);
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
+ "/xyz/openbmc_project/inventory", int32_t(0),
+ std::array<const char *, 1>{
+ "xyz.openbmc_project.Inventory.Item.Board"});
};
/**
+ * @brief Retrieves computer system properties over dbus
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls
+ * @param[in] name Computer system name from request
+ *
+ * @return None.
+ */
+void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
+ const std::string &name)
+{
+ const std::array<const char *, 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",
+ };
+ BMCWEB_LOG_DEBUG << "Get available system components.";
+ crow::connections::systemBus->async_method_call(
+ [name, aResp{std::move(aResp)}](
+ const boost::system::error_code ec,
+ const std::vector<std::pair<
+ std::string,
+ std::vector<std::pair<std::string, std::vector<std::string>>>>>
+ &subtree) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error";
+ aResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ bool foundName = false;
+ // 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.size() < 1)
+ {
+ continue;
+ }
+ // Check if computer system exist
+ if (boost::ends_with(path, name))
+ {
+ foundName = true;
+ BMCWEB_LOG_DEBUG << "Found name: " << name;
+ const std::string connectionName = connectionNames[0].first;
+ crow::connections::systemBus->async_method_call(
+ [aResp, name(std::string(name))](
+ const boost::system::error_code ec,
+ const std::vector<std::pair<
+ std::string, VariantType>> &propertiesList) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error: "
+ << ec;
+ aResp->res.result(boost::beast::http::status::
+ internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got " << propertiesList.size()
+ << "properties for system";
+ for (const std::pair<std::string, VariantType>
+ &property : propertiesList)
+ {
+ const std::string *value =
+ mapbox::getPtr<const std::string>(
+ property.second);
+ if (value != nullptr)
+ {
+ aResp->res.jsonValue[property.first] =
+ *value;
+ }
+ }
+ aResp->res.jsonValue["Name"] = name;
+ aResp->res.jsonValue["Id"] =
+ aResp->res.jsonValue["SerialNumber"];
+ },
+ connectionName, path, "org.freedesktop.DBus.Properties",
+ "GetAll",
+ "xyz.openbmc_project.Inventory.Decorator.Asset");
+ }
+ else
+ {
+ // This is not system, so check if it's cpu, dimm, UUID or
+ // BiosVer
+ for (auto const &s : connectionNames)
+ {
+ for (auto const &i : s.second)
+ {
+ if (boost::ends_with(i, "Dimm"))
+ {
+ BMCWEB_LOG_DEBUG
+ << "Found Dimm, now get it properties.";
+ crow::connections::systemBus->async_method_call(
+ [&, aResp](
+ const boost::system::error_code ec,
+ const std::vector<
+ std::pair<std::string, VariantType>>
+ &properties) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR
+ << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::
+ internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got "
+ << properties.size()
+ << "Dimm properties.";
+ for (const auto &p : properties)
+ {
+ if (p.first == "MemorySize")
+ {
+ const std::string *value =
+ mapbox::getPtr<
+ const std::string>(
+ p.second);
+ if ((value != nullptr) &&
+ (*value != "NULL"))
+ {
+ // Remove units char
+ int32_t unitCoeff;
+ if (boost::ends_with(*value,
+ "MB"))
+ {
+ unitCoeff = 1000;
+ }
+ else if (boost::ends_with(
+ *value, "KB"))
+ {
+ unitCoeff = 1000000;
+ }
+ else
+ {
+ BMCWEB_LOG_ERROR
+ << "Unsupported "
+ "memory units";
+ aResp->res.result(
+ boost::beast::http::
+ status::
+ internal_server_error);
+ return;
+ }
+
+ auto memSize =
+ boost::lexical_cast<
+ int>(value->substr(
+ 0, value->length() -
+ 2));
+ aResp->res.jsonValue
+ ["TotalSystemMemoryGi"
+ "B"] +=
+ memSize * unitCoeff;
+ aResp->res.jsonValue
+ ["MemorySummary"]
+ ["Status"]["State"] =
+ "Enabled";
+ }
+ }
+ }
+ },
+ s.first, path,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Inventory.Item.Dimm");
+ }
+ else if (boost::ends_with(i, "Cpu"))
+ {
+ BMCWEB_LOG_DEBUG
+ << "Found Cpu, now get it properties.";
+ crow::connections::systemBus->async_method_call(
+ [&, aResp](
+ const boost::system::error_code ec,
+ const std::vector<
+ std::pair<std::string, VariantType>>
+ &properties) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR
+ << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::
+ internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got "
+ << properties.size()
+ << "Cpu properties.";
+ for (const auto &p : properties)
+ {
+ if (p.first == "ProcessorFamily")
+ {
+ const std::string *value =
+ mapbox::getPtr<
+ const std::string>(
+ p.second);
+ if (value != nullptr)
+ {
+ aResp->res.jsonValue
+ ["ProcessorSummary"]
+ ["Count"] =
+ aResp->res
+ .jsonValue
+ ["ProcessorSumm"
+ "ary"]["Count"]
+ .get<int>() +
+ 1;
+ aResp->res.jsonValue
+ ["ProcessorSummary"]
+ ["Status"]["State"] =
+ "Enabled";
+ aResp->res.jsonValue
+ ["ProcessorSummary"]
+ ["Model"] = *value;
+ }
+ }
+ }
+ },
+ s.first, path,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Inventory.Item.Cpu");
+ }
+ else if (boost::ends_with(i, "UUID"))
+ {
+ BMCWEB_LOG_DEBUG
+ << "Found UUID, now get it properties.";
+ crow::connections::systemBus->async_method_call(
+ [aResp](
+ const boost::system::error_code ec,
+ const std::vector<
+ std::pair<std::string, VariantType>>
+ &properties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG
+ << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::
+ internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got "
+ << properties.size()
+ << "UUID properties.";
+ for (const std::pair<std::string,
+ VariantType> &p :
+ properties)
+ {
+ if (p.first == "BIOSVer")
+ {
+ const std::string *value =
+ mapbox::getPtr<
+ const std::string>(
+ p.second);
+ if (value != nullptr)
+ {
+ aResp->res.jsonValue
+ ["BiosVersion"] =
+ *value;
+ }
+ }
+ if (p.first == "UUID")
+ {
+ const std::string *value =
+ mapbox::getPtr<
+ const std::string>(
+ p.second);
+ BMCWEB_LOG_DEBUG
+ << "UUID = " << *value
+ << " length "
+ << value->length();
+ if (value != nullptr)
+ {
+ // Workaround for to short
+ // return str in smbios demo
+ // app, 32 bytes are
+ // described by spec
+ if (value->length() > 0 &&
+ value->length() < 32)
+ {
+ std::string
+ correctedValue =
+ *value;
+ correctedValue.append(
+ 32 -
+ value->length(),
+ '0');
+ value = &correctedValue;
+ }
+ else if (value->length() ==
+ 32)
+ {
+ aResp->res
+ .jsonValue["UUID"] =
+ value->substr(0,
+ 8) +
+ "-" +
+ value->substr(8,
+ 4) +
+ "-" +
+ value->substr(12,
+ 4) +
+ "-" +
+ value->substr(16,
+ 4) +
+ "-" +
+ value->substr(20,
+ 12);
+ }
+ }
+ }
+ }
+ },
+ s.first, path,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Common.UUID");
+ }
+ }
+ }
+ }
+ }
+ if (foundName == false)
+ {
+ aResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ }
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/inventory", int32_t(0), interfaces);
+}
+
+/**
+ * @brief Retrieves identify led group properties over dbus
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls.
+ * @param[in] callback Callback for process retrieved data.
+ *
+ * @return None.
+ */
+template <typename CallbackFunc>
+void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
+ CallbackFunc &&callback)
+{
+ BMCWEB_LOG_DEBUG << "Get led groups";
+ crow::connections::systemBus->async_method_call(
+ [aResp{std::move(aResp)},
+ &callback](const boost::system::error_code &ec,
+ const ManagedObjectsType &resp) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects.";
+ for (const auto &objPath : resp)
+ {
+ const std::string &path = objPath.first;
+ if (path.rfind("enclosure_identify") != std::string::npos)
+ {
+ for (const auto &interface : objPath.second)
+ {
+ if (interface.first == "xyz.openbmc_project.Led.Group")
+ {
+ for (const auto &property : interface.second)
+ {
+ if (property.first == "Asserted")
+ {
+ const bool *asserted =
+ mapbox::getPtr<const bool>(
+ property.second);
+ if (nullptr != asserted)
+ {
+ callback(*asserted, aResp);
+ }
+ else
+ {
+ callback(false, aResp);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "xyz.openbmc_project.LED.GroupManager",
+ "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager",
+ "GetManagedObjects");
+}
+
+template <typename CallbackFunc>
+void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback)
+{
+ BMCWEB_LOG_DEBUG << "Get identify led properties";
+ crow::connections::systemBus->async_method_call(
+ [aResp{std::move(aResp)}, &callback](const boost::system::error_code ec,
+ const PropertiesType &properties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got " << properties.size()
+ << "led properties.";
+ std::string output;
+ for (const auto &property : properties)
+ {
+ if (property.first == "State")
+ {
+ const std::string *s =
+ mapbox::getPtr<std::string>(property.second);
+ if (nullptr != s)
+ {
+ BMCWEB_LOG_DEBUG << "Identify Led State: " << *s;
+ const auto pos = s->rfind('.');
+ if (pos != std::string::npos)
+ {
+ auto led = s->substr(pos + 1);
+ for (const std::pair<const char *, const char *>
+ &p :
+ std::array<
+ std::pair<const char *, const char *>, 3>{
+ {{"On", "Lit"},
+ {"Blink", "Blinking"},
+ {"Off", "Off"}}})
+ {
+ if (led == p.first)
+ {
+ output = p.second;
+ }
+ }
+ }
+ }
+ }
+ }
+ callback(output, aResp);
+ },
+ "xyz.openbmc_project.LED.Controller.identify",
+ "/xyz/openbmc_project/led/physical/identify",
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Led.Physical");
+}
+
+/**
+ * @brief Retrieves host state properties over dbus
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls.
+ *
+ * @return None.
+ */
+void getHostState(std::shared_ptr<AsyncResp> aResp)
+{
+ BMCWEB_LOG_DEBUG << "Get host information.";
+ crow::connections::systemBus->async_method_call(
+ [aResp{std::move(aResp)}](const boost::system::error_code ec,
+ const PropertiesType &properties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ aResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Got " << properties.size()
+ << "host properties.";
+ for (const auto &property : properties)
+ {
+ if (property.first == "CurrentHostState")
+ {
+ const std::string *s =
+ mapbox::getPtr<const std::string>(property.second);
+ BMCWEB_LOG_DEBUG << "Host state: " << *s;
+ if (nullptr != s)
+ {
+ const auto pos = s->rfind('.');
+ if (pos != std::string::npos)
+ {
+ // Verify Host State
+ if (s->substr(pos + 1) == "Running")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] =
+ "Enabled";
+ }
+ else
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] =
+ "Disabled";
+ }
+ }
+ }
+ }
+ }
+ },
+ "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.State.Host");
+}
+
+/**
* SystemsCollection derived class for delivering ComputerSystems Collection
* Schema
*/
@@ -664,8 +614,8 @@
const std::vector<std::string> ¶ms) override
{
// Get board list, and call the below callback for JSON preparation
- provider.getBaseboardList([&](const bool &success,
- const std::vector<std::string> &output) {
+ getBaseboardList([&](const bool &success,
+ const std::vector<std::string> &output) {
if (success)
{
// ... prepare json array with appropriate @odata.id links
@@ -688,8 +638,6 @@
res.end();
});
}
-
- OnDemandSystemsProvider provider;
};
/**
@@ -734,8 +682,6 @@
}
private:
- OnDemandSystemsProvider provider;
-
/**
* Functions triggers appropriate requests on DBus
*/
@@ -758,14 +704,14 @@
auto asyncResp = std::make_shared<AsyncResp>(res);
- provider.getLedGroupIdentify(
+ getLedGroupIdentify(
asyncResp,
[&](const bool &asserted, const std::shared_ptr<AsyncResp> &aResp) {
if (asserted)
{
// If led group is asserted, then another call is needed to
// get led status
- provider.getLedIdentify(
+ getLedIdentify(
aResp, [](const std::string &ledStatus,
const std::shared_ptr<AsyncResp> &aResp) {
if (!ledStatus.empty())
@@ -780,8 +726,8 @@
aResp->res.jsonValue["IndicatorLED"] = "Off";
}
});
- provider.getComputerSystem(asyncResp, name);
- provider.getHostState(asyncResp);
+ getComputerSystem(asyncResp, name);
+ getHostState(asyncResp);
}
void doPatch(crow::Response &res, const crow::Request &req,
@@ -832,8 +778,8 @@
res.jsonValue = Node::json;
res.jsonValue["@odata.id"] = "/redfish/v1/Systems/" + name;
- provider.getHostState(asyncResp);
- provider.getComputerSystem(asyncResp, name);
+ getHostState(asyncResp);
+ getComputerSystem(asyncResp, name);
if (dbusLedState.empty())
{