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