blob: bf66c2e655d00e0382410dbe8d6910fa5c1765f8 [file] [log] [blame]
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +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
Ed Tanous1abe55e2018-09-05 08:30:59 -070020#include <systemd/sd-id128.h>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010021
Ed Tanous1abe55e2018-09-05 08:30:59 -070022namespace redfish
23{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080024
Ed Tanous1abe55e2018-09-05 08:30:59 -070025class ServiceRoot : public Node
26{
27 public:
28 ServiceRoot(CrowApp& app) : Node(app, "/redfish/v1/")
29 {
30 Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
31 Node::json["@odata.id"] = "/redfish/v1/";
32 Node::json["@odata.context"] =
33 "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
34 Node::json["Id"] = "RootService";
35 Node::json["Name"] = "Root Service";
36 Node::json["RedfishVersion"] = "1.1.0";
37 Node::json["Links"]["Sessions"] = {
38 {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
Ed Tanous683f7272018-07-26 12:47:19 -070039 Node::json["JsonSchemas"] = {{"@odata.id", "/redfish/v1/JsonSchemas"}};
Ed Tanouse0625902018-05-16 13:35:08 -070040
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 Node::json["UUID"] = getUuid();
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010042
Ed Tanous1abe55e2018-09-05 08:30:59 -070043 entityPrivileges = {
44 {boost::beast::http::verb::get, {}},
45 {boost::beast::http::verb::head, {}},
46 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
47 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
48 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
49 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanouse0625902018-05-16 13:35:08 -070050 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070051
52 private:
53 void doGet(crow::Response& res, const crow::Request& req,
54 const std::vector<std::string>& params) override
55 {
56 res.jsonValue = Node::json;
57 res.end();
58 }
59
60 const std::string getUuid()
61 {
62 // If we are using a version of systemd that can get the app specific
63 // uuid, use that
64#ifdef sd_id128_get_machine_app_specific
65 std::array<char, SD_ID128_STRING_MAX> string;
66 sd_id128_t id = SD_ID128_NULL;
67
68 // This ID needs to match the one in ipmid
69 int r = sd_id128_get_machine_app_specific(
70 SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64,
71 12, 45, 78),
72 &id);
73 if (r < 0)
74 {
75 return "00000000-0000-0000-0000-000000000000";
76 }
77 return string.data();
Ed Tanouse0625902018-05-16 13:35:08 -070078#else
Ed Tanous1abe55e2018-09-05 08:30:59 -070079 return "00000000-0000-0000-0000-000000000000";
Ed Tanouse0625902018-05-16 13:35:08 -070080#endif
Ed Tanous1abe55e2018-09-05 08:30:59 -070081 }
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010082};
83
Ed Tanous1abe55e2018-09-05 08:30:59 -070084} // namespace redfish