blob: 0ad768fea91743341c8e5d4b297455dbf25949c2 [file] [log] [blame]
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001/*
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
20namespace redfish {
21
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010022class Manager : public Node {
23 public:
Ed Tanous3ebd75f2018-03-05 18:20:01 -080024 Manager(CrowApp& app) : Node(app, "/redfish/v1/Managers/openbmc/") {
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010025 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.Lukasz9c3106852018-02-09 15:24:22 +010032 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
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010037 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 Tanous3ebd75f2018-03-05 18:20:01 -080045
46 entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}},
47 {crow::HTTPMethod::HEAD, {{"Login"}}},
48 {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
49 {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
50 {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
51 {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010052 }
53
54 private:
55 void doGet(crow::response& res, const crow::request& req,
56 const std::vector<std::string>& params) override {
57 Node::json["DateTime"] = getDateTime();
58 res.json_value = Node::json;
59 res.end();
60 }
61
62 std::string getDateTime() const {
63 std::array<char, 128> dateTime;
64 std::string redfishDateTime("0000-00-00T00:00:00Z00:00");
65 std::time_t time = std::time(nullptr);
66
67 if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z",
68 std::localtime(&time))) {
69 // insert the colon required by the ISO 8601 standard
70 redfishDateTime = std::string(dateTime.data());
71 redfishDateTime.insert(redfishDateTime.end() - 2, ':');
72 }
73
74 return redfishDateTime;
75 }
76};
77
78class ManagerCollection : public Node {
79 public:
80 ManagerCollection(CrowApp& app)
Ed Tanous3ebd75f2018-03-05 18:20:01 -080081 : Node(app, "/redfish/v1/Managers/"), memberManager(app) {
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010082 Node::json["@odata.id"] = "/redfish/v1/Managers";
83 Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection";
84 Node::json["@odata.context"] =
85 "/redfish/v1/$metadata#ManagerCollection.ManagerCollection";
86 Node::json["Name"] = "Manager Collection";
87 Node::json["Members@odata.count"] = 1;
Ed Tanous6c233012018-03-15 14:43:56 -070088 Node::json["Members"] = {{{"@odata.id", "/redfish/v1/Managers/openbmc"}}};
Ed Tanous3ebd75f2018-03-05 18:20:01 -080089
90 entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}},
91 {crow::HTTPMethod::HEAD, {{"Login"}}},
92 {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
93 {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
94 {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
95 {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010096 }
97
98 private:
99 void doGet(crow::response& res, const crow::request& req,
100 const std::vector<std::string>& params) override {
101 res.json_value = Node::json;
102 res.end();
103 }
104
105 Manager memberManager;
106};
107
108} // namespace redfish