12474adfaSEd Tanous /* 22474adfaSEd Tanous // Copyright (c) 2018 Intel Corporation 32474adfaSEd Tanous // Copyright (c) 2018 Ampere Computing LLC 42474adfaSEd Tanous / 52474adfaSEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 62474adfaSEd Tanous // you may not use this file except in compliance with the License. 72474adfaSEd Tanous // You may obtain a copy of the License at 82474adfaSEd Tanous // 92474adfaSEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 102474adfaSEd Tanous // 112474adfaSEd Tanous // Unless required by applicable law or agreed to in writing, software 122474adfaSEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 132474adfaSEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 142474adfaSEd Tanous // See the License for the specific language governing permissions and 152474adfaSEd Tanous // limitations under the License. 162474adfaSEd Tanous */ 172474adfaSEd Tanous #pragma once 182474adfaSEd Tanous 192474adfaSEd Tanous #include "node.hpp" 202474adfaSEd Tanous #include "sensors.hpp" 212474adfaSEd Tanous 222474adfaSEd Tanous namespace redfish 232474adfaSEd Tanous { 242474adfaSEd Tanous 252474adfaSEd Tanous class Power : public Node 262474adfaSEd Tanous { 272474adfaSEd Tanous public: 282474adfaSEd Tanous Power(CrowApp& app) : 292474adfaSEd Tanous Node((app), "/redfish/v1/Chassis/<str>/Power/", std::string()) 302474adfaSEd Tanous { 312474adfaSEd Tanous entityPrivileges = { 322474adfaSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 332474adfaSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 346f4fd479SRichard Marian Thomaiyar {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 352474adfaSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 362474adfaSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 372474adfaSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 382474adfaSEd Tanous } 392474adfaSEd Tanous 402474adfaSEd Tanous private: 41*b01bf299SEd Tanous std::initializer_list<const char*> typeList = { 42*b01bf299SEd Tanous "/xyz/openbmc_project/sensors/voltage", 43413961deSRichard Marian Thomaiyar "/xyz/openbmc_project/sensors/power"}; 442474adfaSEd Tanous void doGet(crow::Response& res, const crow::Request& req, 452474adfaSEd Tanous const std::vector<std::string>& params) override 462474adfaSEd Tanous { 472474adfaSEd Tanous if (params.size() != 1) 482474adfaSEd Tanous { 492474adfaSEd Tanous res.result(boost::beast::http::status::internal_server_error); 502474adfaSEd Tanous res.end(); 512474adfaSEd Tanous return; 522474adfaSEd Tanous } 532474adfaSEd Tanous const std::string& chassis_name = params[0]; 54603a6640SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS 55603a6640SGunnar Mills // In a one chassis system the only supported name is "chassis" 56603a6640SGunnar Mills if (chassis_name != "chassis") 57603a6640SGunnar Mills { 58603a6640SGunnar Mills messages::resourceNotFound(res, "#Chassis.v1_4_0.Chassis", 59603a6640SGunnar Mills chassis_name); 60603a6640SGunnar Mills res.end(); 61603a6640SGunnar Mills return; 62603a6640SGunnar Mills } 63603a6640SGunnar Mills #endif 642474adfaSEd Tanous 650f74e643SEd Tanous res.jsonValue["@odata.id"] = 662474adfaSEd Tanous "/redfish/v1/Chassis/" + chassis_name + "/Power"; 670f74e643SEd Tanous res.jsonValue["@odata.type"] = "#Power.v1_2_1.Power"; 680f74e643SEd Tanous res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Power.Power"; 690f74e643SEd Tanous res.jsonValue["Id"] = "Power"; 700f74e643SEd Tanous res.jsonValue["Name"] = "Power"; 712474adfaSEd Tanous auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 72413961deSRichard Marian Thomaiyar res, chassis_name, typeList, "Power"); 732474adfaSEd Tanous // TODO Need to retrieve Power Control information. 742474adfaSEd Tanous getChassisData(sensorAsyncResp); 752474adfaSEd Tanous } 76413961deSRichard Marian Thomaiyar void doPatch(crow::Response& res, const crow::Request& req, 77413961deSRichard Marian Thomaiyar const std::vector<std::string>& params) override 78413961deSRichard Marian Thomaiyar { 79413961deSRichard Marian Thomaiyar setSensorOverride(res, req, params, typeList, "Power"); 80413961deSRichard Marian Thomaiyar } 812474adfaSEd Tanous }; 822474adfaSEd Tanous 832474adfaSEd Tanous } // namespace redfish 84