blob: 0dca8ff275e997201e24262a03bda02a59bc0544 [file] [log] [blame]
#include "tlbmc/redfish/routes/thermal_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::thermal_subsystem {
namespace {
void HandleThermalSubsystem(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, "ThermalSubsystem"}));
resp.SetKeyInJsonBody("/@odata.type",
"#ThermalSubsystem.v1_0_0.ThermalSubsystem");
resp.SetKeyInJsonBody("/Name", "Thermal Subsystem");
resp.SetKeyInJsonBody("/Id", "ThermalSubsystem");
resp.SetKeyInJsonBody("/Fans/@odata.id",
CreateUrl({"redfish", "v1", "Chassis", chassis_id,
"ThermalSubsystem", "Fans"}));
resp.SetKeyInJsonBody("/Status/Health", "OK");
resp.SetKeyInJsonBody("/Status/State", "Enabled");
}
} // namespace
void RegisterRoutes(RedfishApp& app) {
TLBMC_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
.methods(boost::beast::http::verb::get)(
absl::bind_front(HandleThermalSubsystem, std::cref(app)));
}
} // namespace milotic_tlbmc::thermal_subsystem