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 | |
| 22 | static OperationMap managerOpMap = { |
| 23 | {crow::HTTPMethod::GET, {{"Login"}}}, |
| 24 | {crow::HTTPMethod::HEAD, {{"Login"}}}, |
| 25 | {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}}, |
| 26 | {crow::HTTPMethod::PUT, {{"ConfigureManager"}}}, |
| 27 | {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}}, |
| 28 | {crow::HTTPMethod::POST, {{"ConfigureManager"}}}}; |
| 29 | |
| 30 | static OperationMap managerCollectionOpMap = { |
| 31 | {crow::HTTPMethod::GET, {{"Login"}}}, |
| 32 | {crow::HTTPMethod::HEAD, {{"Login"}}}, |
| 33 | {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}}, |
| 34 | {crow::HTTPMethod::PUT, {{"ConfigureManager"}}}, |
| 35 | {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}}, |
| 36 | {crow::HTTPMethod::POST, {{"ConfigureManager"}}}}; |
| 37 | |
| 38 | class Manager : public Node { |
| 39 | public: |
| 40 | Manager(CrowApp& app) |
| 41 | : Node(app, EntityPrivileges(std::move(managerOpMap)), |
| 42 | "/redfish/v1/Managers/openbmc/") { |
| 43 | Node::json["@odata.id"] = "/redfish/v1/Managers/openbmc"; |
| 44 | Node::json["@odata.type"] = "#Manager.v1_3_0.Manager"; |
| 45 | Node::json["@odata.context"] = "/redfish/v1/$metadata#Manager.Manager"; |
| 46 | Node::json["Id"] = "openbmc"; |
| 47 | Node::json["Name"] = "OpenBmc Manager"; |
| 48 | Node::json["Description"] = "Baseboard Management Controller"; |
| 49 | Node::json["PowerState"] = "On"; |
| 50 | Node::json["Status"]["Health"] = "OK"; |
| 51 | Node::json["Status"]["HealthRollup"] = "OK"; |
| 52 | Node::json["Status"]["State"] = "Enabled"; |
| 53 | Node::json["UUID"] = |
| 54 | app.template get_middleware<crow::PersistentData::Middleware>() |
| 55 | .system_uuid; |
| 56 | Node::json["Model"] = "OpenBmc"; // TODO(ed), get model |
| 57 | Node::json["FirmwareVersion"] = "1234456789"; // TODO(ed), get fwversion |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | void doGet(crow::response& res, const crow::request& req, |
| 62 | const std::vector<std::string>& params) override { |
| 63 | Node::json["DateTime"] = getDateTime(); |
| 64 | res.json_value = Node::json; |
| 65 | res.end(); |
| 66 | } |
| 67 | |
| 68 | std::string getDateTime() const { |
| 69 | std::array<char, 128> dateTime; |
| 70 | std::string redfishDateTime("0000-00-00T00:00:00Z00:00"); |
| 71 | std::time_t time = std::time(nullptr); |
| 72 | |
| 73 | if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z", |
| 74 | std::localtime(&time))) { |
| 75 | // insert the colon required by the ISO 8601 standard |
| 76 | redfishDateTime = std::string(dateTime.data()); |
| 77 | redfishDateTime.insert(redfishDateTime.end() - 2, ':'); |
| 78 | } |
| 79 | |
| 80 | return redfishDateTime; |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | class ManagerCollection : public Node { |
| 85 | public: |
| 86 | ManagerCollection(CrowApp& app) |
| 87 | : Node(app, EntityPrivileges(std::move(managerCollectionOpMap)), |
| 88 | "/redfish/v1/Managers/"), |
| 89 | memberManager(app) { |
| 90 | Node::json["@odata.id"] = "/redfish/v1/Managers"; |
| 91 | Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection"; |
| 92 | Node::json["@odata.context"] = |
| 93 | "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"; |
| 94 | Node::json["Name"] = "Manager Collection"; |
| 95 | Node::json["Members@odata.count"] = 1; |
| 96 | Node::json["Members"] = {{"@odata.id", "/redfish/v1/Managers/openbmc"}}; |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | void doGet(crow::response& res, const crow::request& req, |
| 101 | const std::vector<std::string>& params) override { |
| 102 | res.json_value = Node::json; |
| 103 | res.end(); |
| 104 | } |
| 105 | |
| 106 | Manager memberManager; |
| 107 | }; |
| 108 | |
| 109 | } // namespace redfish |