blob: d43275ec6d2f5ae882440bf9af829da2c6aa8b14 [file] [log] [blame]
#include "tlbmc/redfish/routes/power_subsystem.h"
#include <functional>
#include <string>
#include "absl/functional/bind_front.h"
#include "absl/status/statusor.h"
#include "tlbmc/redfish/app.h"
#include "tlbmc/redfish/request.h"
#include "tlbmc/redfish/response.h"
#include "tlbmc/redfish/url.h"
#include "tlbmc/store/store.h"
namespace milotic_tlbmc::power_subsystem {
namespace {
void HandlePowerSubsystem(const RedfishApp& app, const RedfishRequest& req,
RedfishResponse& resp,
const std::string& chassis_id) {
// Assume chassis dosen't exist if it doesn't have a FRU key.
const Store& store = *app.GetStore();
absl::StatusOr<std::string> fru_key = store.GetFruKeyByConfigKey(chassis_id);
if (!fru_key.ok()) {
resp.SetToAbslStatus(fru_key.status());
return;
}
resp.SetKeyInJsonBody(
"/@odata.id",
CreateUrl({"redfish", "v1", "Chassis", chassis_id, "PowerSubsystem"}));
resp.SetKeyInJsonBody("/@odata.type",
"#PowerSubsystem.v1_1_0.PowerSubsystem");
resp.SetKeyInJsonBody("/Id", "PowerSubsystem");
resp.SetKeyInJsonBody("/Name", "Power Subsystem");
resp.SetKeyInJsonBody("/PowerSupplies/@odata.id",
CreateUrl({"redfish", "v1", "Chassis", chassis_id,
"PowerSubsystem", "PowerSupplies"}));
resp.SetKeyInJsonBody("/Status/Health", "OK");
resp.SetKeyInJsonBody("/Status/State", "Enabled");
}
} // namespace
void RegisterRoutes(RedfishApp& app) {
TLBMC_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
.methods(boost::beast::http::verb::get)(
absl::bind_front(HandlePowerSubsystem, std::cref(app)));
}
} // namespace milotic_tlbmc::power_subsystem