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 46e0d918bcSEd Tanous entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}, 47e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 48e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 49e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 50e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 51e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 529c310685SBorawski.Lukasz } 539c310685SBorawski.Lukasz 549c310685SBorawski.Lukasz private: 5555c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 569c310685SBorawski.Lukasz const std::vector<std::string>& params) override { 579c310685SBorawski.Lukasz Node::json["DateTime"] = getDateTime(); 5855c7b7a2SEd Tanous // Copy over the static data to include the entries added by SubRoute 5955c7b7a2SEd Tanous res.jsonValue = Node::json; 609c310685SBorawski.Lukasz res.end(); 619c310685SBorawski.Lukasz } 629c310685SBorawski.Lukasz 639c310685SBorawski.Lukasz std::string getDateTime() const { 649c310685SBorawski.Lukasz std::array<char, 128> dateTime; 659c310685SBorawski.Lukasz std::string redfishDateTime("0000-00-00T00:00:00Z00:00"); 669c310685SBorawski.Lukasz std::time_t time = std::time(nullptr); 679c310685SBorawski.Lukasz 689c310685SBorawski.Lukasz if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z", 699c310685SBorawski.Lukasz std::localtime(&time))) { 709c310685SBorawski.Lukasz // insert the colon required by the ISO 8601 standard 719c310685SBorawski.Lukasz redfishDateTime = std::string(dateTime.data()); 729c310685SBorawski.Lukasz redfishDateTime.insert(redfishDateTime.end() - 2, ':'); 739c310685SBorawski.Lukasz } 749c310685SBorawski.Lukasz 759c310685SBorawski.Lukasz return redfishDateTime; 769c310685SBorawski.Lukasz } 779c310685SBorawski.Lukasz }; 789c310685SBorawski.Lukasz 799c310685SBorawski.Lukasz class ManagerCollection : public Node { 809c310685SBorawski.Lukasz public: 81*530bc74dSEd Tanous ManagerCollection(CrowApp& app) : Node(app, "/redfish/v1/Managers/") { 829c310685SBorawski.Lukasz Node::json["@odata.id"] = "/redfish/v1/Managers"; 839c310685SBorawski.Lukasz Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection"; 849c310685SBorawski.Lukasz Node::json["@odata.context"] = 859c310685SBorawski.Lukasz "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; 869c310685SBorawski.Lukasz Node::json["Name"] = "Manager Collection"; 879c310685SBorawski.Lukasz Node::json["Members@odata.count"] = 1; 886c233015SEd Tanous Node::json["Members"] = {{{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; 893ebd75f7SEd Tanous 90e0d918bcSEd Tanous entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}, 91e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 92e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 93e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 94e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 95e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 969c310685SBorawski.Lukasz } 979c310685SBorawski.Lukasz 989c310685SBorawski.Lukasz private: 9955c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 1009c310685SBorawski.Lukasz const std::vector<std::string>& params) override { 10155c7b7a2SEd Tanous // Collections don't include the static data added by SubRoute because it 10255c7b7a2SEd Tanous // has a duplicate entry for members 10355c7b7a2SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 10455c7b7a2SEd Tanous res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection"; 10555c7b7a2SEd Tanous res.jsonValue["@odata.context"] = 10655c7b7a2SEd Tanous "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; 10755c7b7a2SEd Tanous res.jsonValue["Name"] = "Manager Collection"; 10855c7b7a2SEd Tanous res.jsonValue["Members@odata.count"] = 1; 10955c7b7a2SEd Tanous res.jsonValue["Members"] = { 11055c7b7a2SEd Tanous {{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; 1119c310685SBorawski.Lukasz res.end(); 1129c310685SBorawski.Lukasz } 1139c310685SBorawski.Lukasz }; 1149c310685SBorawski.Lukasz 1159c310685SBorawski.Lukasz } // namespace redfish 116