Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | namespace redfish |
| 23 | { |
| 24 | |
| 25 | class Power : public Node |
| 26 | { |
| 27 | public: |
| 28 | Power(CrowApp& app) : |
| 29 | Node((app), "/redfish/v1/Chassis/<str>/Power/", std::string()) |
| 30 | { |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 31 | entityPrivileges = { |
| 32 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 33 | {boost::beast::http::verb::head, {{"Login"}}}, |
Richard Marian Thomaiyar | 6f4fd47 | 2019-02-13 10:10:59 +0530 | [diff] [blame] | 34 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 35 | {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 Tanous | b01bf29 | 2019-03-25 19:25:26 +0000 | [diff] [blame] | 41 | std::initializer_list<const char*> typeList = { |
| 42 | "/xyz/openbmc_project/sensors/voltage", |
| 43 | "/xyz/openbmc_project/sensors/power"}; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 44 | void doGet(crow::Response& res, const crow::Request& req, |
| 45 | const std::vector<std::string>& params) override |
| 46 | { |
| 47 | if (params.size() != 1) |
| 48 | { |
| 49 | res.result(boost::beast::http::status::internal_server_error); |
| 50 | res.end(); |
| 51 | return; |
| 52 | } |
| 53 | const std::string& chassis_name = params[0]; |
Gunnar Mills | 603a664 | 2019-01-21 17:03:51 -0600 | [diff] [blame] | 54 | #ifdef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS |
| 55 | // In a one chassis system the only supported name is "chassis" |
| 56 | if (chassis_name != "chassis") |
| 57 | { |
| 58 | messages::resourceNotFound(res, "#Chassis.v1_4_0.Chassis", |
| 59 | chassis_name); |
| 60 | res.end(); |
| 61 | return; |
| 62 | } |
| 63 | #endif |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 64 | |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 65 | res.jsonValue["@odata.id"] = |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 66 | "/redfish/v1/Chassis/" + chassis_name + "/Power"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 67 | res.jsonValue["@odata.type"] = "#Power.v1_2_1.Power"; |
| 68 | res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Power.Power"; |
| 69 | res.jsonValue["Id"] = "Power"; |
| 70 | res.jsonValue["Name"] = "Power"; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 71 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 72 | res, chassis_name, typeList, "Power"); |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 73 | // TODO Need to retrieve Power Control information. |
| 74 | getChassisData(sensorAsyncResp); |
| 75 | } |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 76 | void doPatch(crow::Response& res, const crow::Request& req, |
| 77 | const std::vector<std::string>& params) override |
| 78 | { |
| 79 | setSensorOverride(res, req, params, typeList, "Power"); |
| 80 | } |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace redfish |