blob: 78f1d8aecd304cf5185559db94cc0e3730076863 [file] [log] [blame]
Ed Tanous2474adf2018-09-05 16:31:16 -07001/*
2// Copyright (c) 2018 Intel Corporation
3// Copyright (c) 2018 Ampere Computing LLC
4/
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16*/
17#pragma once
18
19#include "node.hpp"
20#include "sensors.hpp"
21
22namespace redfish
23{
24
25class Power : public Node
26{
27 public:
28 Power(CrowApp& app) :
29 Node((app), "/redfish/v1/Chassis/<str>/Power/", std::string())
30 {
Ed Tanous2474adf2018-09-05 16:31:16 -070031 entityPrivileges = {
32 {boost::beast::http::verb::get, {{"Login"}}},
33 {boost::beast::http::verb::head, {{"Login"}}},
Richard Marian Thomaiyar6f4fd472019-02-13 10:10:59 +053034 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
Ed Tanous2474adf2018-09-05 16:31:16 -070035 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
36 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
37 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
38 }
39
40 private:
Ed Tanous6ea007a2019-02-13 22:48:25 -080041 std::vector<const char*> typeList = {"/xyz/openbmc_project/sensors/voltage",
42 "/xyz/openbmc_project/sensors/power"};
Ed Tanous2474adf2018-09-05 16:31:16 -070043 void doGet(crow::Response& res, const crow::Request& req,
44 const std::vector<std::string>& params) override
45 {
46 if (params.size() != 1)
47 {
48 res.result(boost::beast::http::status::internal_server_error);
49 res.end();
50 return;
51 }
52 const std::string& chassis_name = params[0];
Gunnar Mills603a6642019-01-21 17:03:51 -060053#ifdef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS
54 // In a one chassis system the only supported name is "chassis"
55 if (chassis_name != "chassis")
56 {
57 messages::resourceNotFound(res, "#Chassis.v1_4_0.Chassis",
58 chassis_name);
59 res.end();
60 return;
61 }
62#endif
Ed Tanous2474adf2018-09-05 16:31:16 -070063
Ed Tanous0f74e642018-11-12 15:17:05 -080064 res.jsonValue["@odata.id"] =
Ed Tanous2474adf2018-09-05 16:31:16 -070065 "/redfish/v1/Chassis/" + chassis_name + "/Power";
Ed Tanous0f74e642018-11-12 15:17:05 -080066 res.jsonValue["@odata.type"] = "#Power.v1_2_1.Power";
67 res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Power.Power";
68 res.jsonValue["Id"] = "Power";
69 res.jsonValue["Name"] = "Power";
Ed Tanous2474adf2018-09-05 16:31:16 -070070 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +053071 res, chassis_name, typeList, "Power");
Ed Tanous2474adf2018-09-05 16:31:16 -070072 // TODO Need to retrieve Power Control information.
73 getChassisData(sensorAsyncResp);
74 }
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +053075 void doPatch(crow::Response& res, const crow::Request& req,
76 const std::vector<std::string>& params) override
77 {
78 setSensorOverride(res, req, params, typeList, "Power");
79 }
Ed Tanous2474adf2018-09-05 16:31:16 -070080};
81
82} // namespace redfish