Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "node.hpp" |
| 19 | |
| 20 | namespace redfish { |
| 21 | |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 22 | class Manager : public Node { |
| 23 | public: |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 24 | Manager(CrowApp& app) : Node(app, "/redfish/v1/Managers/openbmc/") { |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 25 | Node::json["@odata.id"] = "/redfish/v1/Managers/openbmc"; |
| 26 | Node::json["@odata.type"] = "#Manager.v1_3_0.Manager"; |
| 27 | Node::json["@odata.context"] = "/redfish/v1/$metadata#Manager.Manager"; |
| 28 | Node::json["Id"] = "openbmc"; |
| 29 | Node::json["Name"] = "OpenBmc Manager"; |
| 30 | Node::json["Description"] = "Baseboard Management Controller"; |
| 31 | Node::json["PowerState"] = "On"; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 32 | Node::json["UUID"] = |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 33 | app.template getMiddleware<crow::persistent_data::Middleware>() |
| 34 | .systemUuid; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 35 | Node::json["Model"] = "OpenBmc"; // TODO(ed), get model |
| 36 | Node::json["FirmwareVersion"] = "1234456789"; // TODO(ed), get fwversion |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 37 | Node::json["EthernetInterfaces"] = nlohmann::json( |
| 38 | {{"@odata.id", |
| 39 | "/redfish/v1/Managers/openbmc/EthernetInterfaces"}}); // TODO(Pawel), |
| 40 | // remove this |
| 41 | // when |
| 42 | // subroutes |
| 43 | // will work |
| 44 | // correctly |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 45 | |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 46 | entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}, |
| 47 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 48 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 49 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 50 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 51 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | private: |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 55 | void doGet(crow::Response& res, const crow::Request& req, |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 56 | const std::vector<std::string>& params) override { |
| 57 | Node::json["DateTime"] = getDateTime(); |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 58 | // Copy over the static data to include the entries added by SubRoute |
| 59 | res.jsonValue = Node::json; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 60 | res.end(); |
| 61 | } |
| 62 | |
| 63 | std::string getDateTime() const { |
| 64 | std::array<char, 128> dateTime; |
| 65 | std::string redfishDateTime("0000-00-00T00:00:00Z00:00"); |
| 66 | std::time_t time = std::time(nullptr); |
| 67 | |
| 68 | if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z", |
| 69 | std::localtime(&time))) { |
| 70 | // insert the colon required by the ISO 8601 standard |
| 71 | redfishDateTime = std::string(dateTime.data()); |
| 72 | redfishDateTime.insert(redfishDateTime.end() - 2, ':'); |
| 73 | } |
| 74 | |
| 75 | return redfishDateTime; |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | class ManagerCollection : public Node { |
| 80 | public: |
| 81 | ManagerCollection(CrowApp& app) |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 82 | : Node(app, "/redfish/v1/Managers/"), memberManager(app) { |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 83 | Node::json["@odata.id"] = "/redfish/v1/Managers"; |
| 84 | Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection"; |
| 85 | Node::json["@odata.context"] = |
| 86 | "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; |
| 87 | Node::json["Name"] = "Manager Collection"; |
| 88 | Node::json["Members@odata.count"] = 1; |
Ed Tanous | 6c23301 | 2018-03-15 14:43:56 -0700 | [diff] [blame] | 89 | Node::json["Members"] = {{{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 90 | |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 91 | entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}, |
| 92 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 93 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 94 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 95 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 96 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | private: |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 100 | void doGet(crow::Response& res, const crow::Request& req, |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 101 | const std::vector<std::string>& params) override { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 102 | // Collections don't include the static data added by SubRoute because it |
| 103 | // has a duplicate entry for members |
| 104 | res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; |
| 105 | res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection"; |
| 106 | res.jsonValue["@odata.context"] = |
| 107 | "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; |
| 108 | res.jsonValue["Name"] = "Manager Collection"; |
| 109 | res.jsonValue["Members@odata.count"] = 1; |
| 110 | res.jsonValue["Members"] = { |
| 111 | {{"@odata.id", "/redfish/v1/Managers/openbmc"}}}; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 112 | res.end(); |
| 113 | } |
| 114 | |
| 115 | Manager memberManager; |
| 116 | }; |
| 117 | |
| 118 | } // namespace redfish |