19c310685SBorawski.Lukasz /* 29c310685SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation 39c310685SBorawski.Lukasz // 49c310685SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License"); 59c310685SBorawski.Lukasz // you may not use this file except in compliance with the License. 69c310685SBorawski.Lukasz // You may obtain a copy of the License at 79c310685SBorawski.Lukasz // 89c310685SBorawski.Lukasz // http://www.apache.org/licenses/LICENSE-2.0 99c310685SBorawski.Lukasz // 109c310685SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software 119c310685SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS, 129c310685SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139c310685SBorawski.Lukasz // See the License for the specific language governing permissions and 149c310685SBorawski.Lukasz // limitations under the License. 159c310685SBorawski.Lukasz */ 169c310685SBorawski.Lukasz #pragma once 179c310685SBorawski.Lukasz 189c310685SBorawski.Lukasz #include "node.hpp" 199c310685SBorawski.Lukasz 209c310685SBorawski.Lukasz namespace redfish { 219c310685SBorawski.Lukasz 229c310685SBorawski.Lukasz class Manager : public Node { 239c310685SBorawski.Lukasz public: 243ebd75f7SEd Tanous Manager(CrowApp& app) : Node(app, "/redfish/v1/Managers/openbmc/") { 259c310685SBorawski.Lukasz Node::json["@odata.id"] = "/redfish/v1/Managers/openbmc"; 269c310685SBorawski.Lukasz Node::json["@odata.type"] = "#Manager.v1_3_0.Manager"; 279c310685SBorawski.Lukasz Node::json["@odata.context"] = "/redfish/v1/$metadata#Manager.Manager"; 289c310685SBorawski.Lukasz Node::json["Id"] = "openbmc"; 299c310685SBorawski.Lukasz Node::json["Name"] = "OpenBmc Manager"; 309c310685SBorawski.Lukasz Node::json["Description"] = "Baseboard Management Controller"; 319c310685SBorawski.Lukasz Node::json["PowerState"] = "On"; 329c310685SBorawski.Lukasz Node::json["UUID"] = 3355c7b7a2SEd Tanous app.template getMiddleware<crow::persistent_data::Middleware>() 3455c7b7a2SEd Tanous .systemUuid; 359c310685SBorawski.Lukasz Node::json["Model"] = "OpenBmc"; // TODO(ed), get model 369c310685SBorawski.Lukasz Node::json["FirmwareVersion"] = "1234456789"; // TODO(ed), get fwversion 379391bb9cSRapkiewicz, Pawel Node::json["EthernetInterfaces"] = nlohmann::json( 389391bb9cSRapkiewicz, Pawel {{"@odata.id", 399391bb9cSRapkiewicz, Pawel "/redfish/v1/Managers/openbmc/EthernetInterfaces"}}); // TODO(Pawel), 409391bb9cSRapkiewicz, Pawel // remove this 419391bb9cSRapkiewicz, Pawel // when 429391bb9cSRapkiewicz, Pawel // subroutes 439391bb9cSRapkiewicz, Pawel // will work 449391bb9cSRapkiewicz, Pawel // correctly 453ebd75f7SEd Tanous 46*a434f2bdSEd Tanous entityPrivileges = { 47*a434f2bdSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 48e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 49e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 50e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 51e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 52e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 539c310685SBorawski.Lukasz } 549c310685SBorawski.Lukasz 559c310685SBorawski.Lukasz private: 5655c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 579c310685SBorawski.Lukasz const std::vector<std::string>& params) override { 589c310685SBorawski.Lukasz Node::json["DateTime"] = getDateTime(); 5955c7b7a2SEd Tanous // Copy over the static data to include the entries added by SubRoute 6055c7b7a2SEd Tanous res.jsonValue = Node::json; 619c310685SBorawski.Lukasz res.end(); 629c310685SBorawski.Lukasz } 639c310685SBorawski.Lukasz 649c310685SBorawski.Lukasz std::string getDateTime() const { 659c310685SBorawski.Lukasz std::array<char, 128> dateTime; 669c310685SBorawski.Lukasz std::string redfishDateTime("0000-00-00T00:00:00Z00:00"); 679c310685SBorawski.Lukasz std::time_t time = std::time(nullptr); 689c310685SBorawski.Lukasz 699c310685SBorawski.Lukasz if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z", 709c310685SBorawski.Lukasz std::localtime(&time))) { 719c310685SBorawski.Lukasz // insert the colon required by the ISO 8601 standard 729c310685SBorawski.Lukasz redfishDateTime = std::string(dateTime.data()); 739c310685SBorawski.Lukasz redfishDateTime.insert(redfishDateTime.end() - 2, ':'); 749c310685SBorawski.Lukasz } 759c310685SBorawski.Lukasz 769c310685SBorawski.Lukasz return redfishDateTime; 779c310685SBorawski.Lukasz } 789c310685SBorawski.Lukasz }; 799c310685SBorawski.Lukasz 809c310685SBorawski.Lukasz class ManagerCollection : public Node { 819c310685SBorawski.Lukasz public: 82530bc74dSEd Tanous ManagerCollection(CrowApp& app) : Node(app, "/redfish/v1/Managers/") { 839c310685SBorawski.Lukasz Node::json["@odata.id"] = "/redfish/v1/Managers"; 849c310685SBorawski.Lukasz Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection"; 859c310685SBorawski.Lukasz Node::json["@odata.context"] = 869c310685SBorawski.Lukasz "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; 879c310685SBorawski.Lukasz Node::json["Name"] = "Manager Collection"; 889c310685SBorawski.Lukasz Node::json["Members@odata.count"] = 1; 896c233015SEd Tanous Node::json["Members"] = {{{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; 903ebd75f7SEd Tanous 91*a434f2bdSEd Tanous entityPrivileges = { 92*a434f2bdSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 93e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 94e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 95e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 96e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 97e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 989c310685SBorawski.Lukasz } 999c310685SBorawski.Lukasz 1009c310685SBorawski.Lukasz private: 10155c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 1029c310685SBorawski.Lukasz const std::vector<std::string>& params) override { 10355c7b7a2SEd Tanous // Collections don't include the static data added by SubRoute because it 10455c7b7a2SEd Tanous // has a duplicate entry for members 10555c7b7a2SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 10655c7b7a2SEd Tanous res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection"; 10755c7b7a2SEd Tanous res.jsonValue["@odata.context"] = 10855c7b7a2SEd Tanous "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; 10955c7b7a2SEd Tanous res.jsonValue["Name"] = "Manager Collection"; 11055c7b7a2SEd Tanous res.jsonValue["Members@odata.count"] = 1; 11155c7b7a2SEd Tanous res.jsonValue["Members"] = { 11255c7b7a2SEd Tanous {{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; 1139c310685SBorawski.Lukasz res.end(); 1149c310685SBorawski.Lukasz } 1159c310685SBorawski.Lukasz }; 1169c310685SBorawski.Lukasz 1179c310685SBorawski.Lukasz } // namespace redfish 118