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 | { |
| 31 | Node::json["@odata.type"] = "#Power.v1_2_1.Power"; |
| 32 | Node::json["@odata.context"] = "/redfish/v1/$metadata#Power.Power"; |
| 33 | Node::json["Id"] = "Power"; |
| 34 | Node::json["Name"] = "Power"; |
| 35 | |
| 36 | entityPrivileges = { |
| 37 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 38 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 39 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 40 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 41 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 42 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | void doGet(crow::Response& res, const crow::Request& req, |
| 47 | const std::vector<std::string>& params) override |
| 48 | { |
| 49 | if (params.size() != 1) |
| 50 | { |
| 51 | res.result(boost::beast::http::status::internal_server_error); |
| 52 | res.end(); |
| 53 | return; |
| 54 | } |
| 55 | const std::string& chassis_name = params[0]; |
| 56 | |
| 57 | Node::json["@odata.id"] = |
| 58 | "/redfish/v1/Chassis/" + chassis_name + "/Power"; |
| 59 | res.jsonValue = Node::json; |
| 60 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 61 | res, chassis_name, |
| 62 | std::initializer_list<const char*>{ |
| 63 | "/xyz/openbmc_project/sensors/voltage", |
| 64 | "/xyz/openbmc_project/sensors/power"}, |
| 65 | "Power"); |
| 66 | // TODO Need to retrieve Power Control information. |
| 67 | getChassisData(sensorAsyncResp); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | } // namespace redfish |