summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBorawski.Lukasz <lukasz.borawski@intel.com>2018-02-09 17:24:22 +0300
committerEd Tanous <ed.tanous@intel.com>2018-03-28 00:02:27 +0300
commit9c31068502b9b86745dc144b11a77725e836d465 (patch)
treeec5e453ac4997c083c9f9234ab12eca636cf02f9
parent5d27b854e5b99a9ab3d3f5ad9f99094252d19092 (diff)
downloadbmcweb-9c31068502b9b86745dc144b11a77725e836d465.tar.xz
Redfish Manager and ManagerCollection
Node version of the Manager and ManagerCollection implementation. Change-Id: I693fa57add670fb0ecfc0cf0046e06142571c543 Signed-off-by: Borawski.Lukasz <lukasz.borawski@intel.com>
-rw-r--r--include/redfish_v1.hpp53
-rw-r--r--redfish-core/include/redfish.hpp2
-rw-r--r--redfish-core/lib/managers.hpp109
3 files changed, 111 insertions, 53 deletions
diff --git a/include/redfish_v1.hpp b/include/redfish_v1.hpp
index 99e0b3c271..57ac7ea328 100644
--- a/include/redfish_v1.hpp
+++ b/include/redfish_v1.hpp
@@ -139,59 +139,6 @@ void request_routes(Crow<Middlewares...>& app) {
{{"@odata.id", "/redfish/v1/AccountService/Roles/NoAccess"}}}}}};
res.end();
});
-
- CROW_ROUTE(app, "/redfish/v1/Managers/")
- .methods("GET"_method)(
- [&](const crow::request& req, crow::response& res) {
- res.json_value = {
- {"@odata.context",
- "/redfish/v1/$metadata#ManagerCollection.ManagerCollection"},
- {"@odata.id", "/redfish/v1/Managers"},
- {"@odata.type", "#ManagerCollection.ManagerCollection"},
- {"Name", "Manager Collection"},
- {"Members@odata.count", 1},
- {"Members", {{{"@odata.id", "/redfish/v1/Managers/openbmc"}}}}};
- res.end();
- });
-
- CROW_ROUTE(app, "/redfish/v1/Managers/openbmc/")
- .methods(
- "GET"_method)([&](const crow::request& req, crow::response& res) {
- time_t t = time(NULL);
- tm* mytime = std::localtime(&t);
- if (mytime == nullptr) {
- res.code = 500;
- res.end();
- return;
- }
- std::array<char, 100> time_buffer;
- std::size_t len = std::strftime(time_buffer.data(), time_buffer.size(),
- "%FT%TZ", mytime);
- if (len == 0) {
- res.code = 500;
- res.end();
- return;
- }
- res.json_value = {
- {"@odata.context", "/redfish/v1/$metadata#Manager.Manager"},
- {"@odata.id", "/redfish/v1/Managers/openbmc"},
- {"@odata.type", "#Manager.v1_3_0.Manager"},
- {"Id", "openbmc"},
- {"Name", "OpenBmc Manager"},
- {"Description", "Baseboard Management Controller"},
- {"UUID", app.template get_middleware<PersistentData::Middleware>()
- .system_uuid},
- {"Model", "OpenBmc"}, // TODO(ed), get model
- {"DateTime", time_buffer.data()},
- {"Status",
- {{"State", "Enabled"}, {"Health", "OK"}, {"HealthRollup", "OK"}}},
- {"FirmwareVersion", "1234456789"}, // TODO(ed) get fwversion
- {"PowerState", "On"}};
- get_redfish_sub_routes(app, "/redfish/v1/Managers/openbmc/",
- res.json_value);
- res.end();
- });
-
}
} // namespace redfish
} // namespace crow
diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index 7714ab7dd8..0c2a91224b 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -16,6 +16,7 @@
#pragma once
#include "../lib/account_service.hpp"
+#include "../lib/managers.hpp"
#include "../lib/network_protocol.hpp"
#include "../lib/redfish_sessions.hpp"
#include "../lib/roles.hpp"
@@ -43,6 +44,7 @@ class RedfishService {
nodes.emplace_back(std::make_unique<ServiceRoot>(app));
nodes.emplace_back(std::make_unique<NetworkProtocol>(app));
nodes.emplace_back(std::make_unique<SessionService>(app));
+ nodes.emplace_back(std::make_unique<ManagerCollection>(app));
for (auto& node : nodes) {
node->getSubRoutes(nodes);
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
new file mode 100644
index 0000000000..0a56da72c7
--- /dev/null
+++ b/redfish-core/lib/managers.hpp
@@ -0,0 +1,109 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#pragma once
+
+#include "node.hpp"
+
+namespace redfish {
+
+static OperationMap managerOpMap = {
+ {crow::HTTPMethod::GET, {{"Login"}}},
+ {crow::HTTPMethod::HEAD, {{"Login"}}},
+ {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
+
+static OperationMap managerCollectionOpMap = {
+ {crow::HTTPMethod::GET, {{"Login"}}},
+ {crow::HTTPMethod::HEAD, {{"Login"}}},
+ {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
+ {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
+
+class Manager : public Node {
+ public:
+ Manager(CrowApp& app)
+ : Node(app, EntityPrivileges(std::move(managerOpMap)),
+ "/redfish/v1/Managers/openbmc/") {
+ Node::json["@odata.id"] = "/redfish/v1/Managers/openbmc";
+ Node::json["@odata.type"] = "#Manager.v1_3_0.Manager";
+ Node::json["@odata.context"] = "/redfish/v1/$metadata#Manager.Manager";
+ Node::json["Id"] = "openbmc";
+ Node::json["Name"] = "OpenBmc Manager";
+ Node::json["Description"] = "Baseboard Management Controller";
+ Node::json["PowerState"] = "On";
+ Node::json["Status"]["Health"] = "OK";
+ Node::json["Status"]["HealthRollup"] = "OK";
+ Node::json["Status"]["State"] = "Enabled";
+ Node::json["UUID"] =
+ app.template get_middleware<crow::PersistentData::Middleware>()
+ .system_uuid;
+ Node::json["Model"] = "OpenBmc"; // TODO(ed), get model
+ Node::json["FirmwareVersion"] = "1234456789"; // TODO(ed), get fwversion
+ }
+
+ private:
+ void doGet(crow::response& res, const crow::request& req,
+ const std::vector<std::string>& params) override {
+ Node::json["DateTime"] = getDateTime();
+ res.json_value = Node::json;
+ res.end();
+ }
+
+ std::string getDateTime() const {
+ std::array<char, 128> dateTime;
+ std::string redfishDateTime("0000-00-00T00:00:00Z00:00");
+ std::time_t time = std::time(nullptr);
+
+ if (std::strftime(dateTime.begin(), dateTime.size(), "%FT%T%z",
+ std::localtime(&time))) {
+ // insert the colon required by the ISO 8601 standard
+ redfishDateTime = std::string(dateTime.data());
+ redfishDateTime.insert(redfishDateTime.end() - 2, ':');
+ }
+
+ return redfishDateTime;
+ }
+};
+
+class ManagerCollection : public Node {
+ public:
+ ManagerCollection(CrowApp& app)
+ : Node(app, EntityPrivileges(std::move(managerCollectionOpMap)),
+ "/redfish/v1/Managers/"),
+ memberManager(app) {
+ Node::json["@odata.id"] = "/redfish/v1/Managers";
+ Node::json["@odata.type"] = "#ManagerCollection.ManagerCollection";
+ Node::json["@odata.context"] =
+ "/redfish/v1/$metadata#ManagerCollection.ManagerCollection";
+ Node::json["Name"] = "Manager Collection";
+ Node::json["Members@odata.count"] = 1;
+ Node::json["Members"] = {{"@odata.id", "/redfish/v1/Managers/openbmc"}};
+ }
+
+ private:
+ void doGet(crow::response& res, const crow::request& req,
+ const std::vector<std::string>& params) override {
+ res.json_value = Node::json;
+ res.end();
+ }
+
+ Manager memberManager;
+};
+
+} // namespace redfish