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