| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 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 |  | 
| Ed Tanous | e062590 | 2018-05-16 13:35:08 -0700 | [diff] [blame^] | 18 | #include <systemd/sd-id128.h> | 
| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 19 | #include "node.hpp" | 
 | 20 |  | 
 | 21 | namespace redfish { | 
 | 22 |  | 
 | 23 | class ServiceRoot : public Node { | 
 | 24 |  public: | 
| Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 25 |   ServiceRoot(CrowApp& app) : Node(app, "/redfish/v1/") { | 
| Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 26 |     Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot"; | 
 | 27 |     Node::json["@odata.id"] = "/redfish/v1/"; | 
 | 28 |     Node::json["@odata.context"] = | 
| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 29 |         "/redfish/v1/$metadata#ServiceRoot.ServiceRoot"; | 
| Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 30 |     Node::json["Id"] = "RootService"; | 
 | 31 |     Node::json["Name"] = "Root Service"; | 
 | 32 |     Node::json["RedfishVersion"] = "1.1.0"; | 
 | 33 |     Node::json["Links"]["Sessions"] = { | 
 | 34 |         {"@odata.id", "/redfish/v1/SessionService/Sessions"}}; | 
| Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 35 |  | 
| Ed Tanous | e062590 | 2018-05-16 13:35:08 -0700 | [diff] [blame^] | 36 |     Node::json["UUID"] = get_uuid(); | 
 | 37 |  | 
 | 38 |     entityPrivileges = { | 
 | 39 |         {boost::beast::http::verb::get, {}}, | 
 | 40 |         {boost::beast::http::verb::head, {}}, | 
 | 41 |         {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, | 
 | 42 |         {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, | 
 | 43 |         {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, | 
 | 44 |         {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; | 
| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 45 |   } | 
 | 46 |  | 
 | 47 |  private: | 
 | 48 |   void doGet(crow::response& res, const crow::request& req, | 
 | 49 |              const std::vector<std::string>& params) override { | 
| Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 50 |     res.json_value = Node::json; | 
| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 51 |     res.end(); | 
 | 52 |   } | 
| Ed Tanous | e062590 | 2018-05-16 13:35:08 -0700 | [diff] [blame^] | 53 |  | 
 | 54 |   const std::string get_uuid() { | 
 | 55 |   // If we are using a version of systemd that can get the app specific uuid, | 
 | 56 |   // use that | 
 | 57 | #ifdef sd_id128_get_machine_app_specific | 
 | 58 |     std::array<char, SD_ID128_STRING_MAX> string; | 
 | 59 |     sd_id128_t id = SD_ID128_NULL; | 
 | 60 |  | 
 | 61 |     // This ID needs to match the one in ipmid | 
 | 62 |     int r = sd_id128_get_machine_app_specific( | 
 | 63 |         SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64, 12, | 
 | 64 |                       45, 78), | 
 | 65 |         &id); | 
 | 66 |     if (r < 0) { | 
 | 67 |       return "00000000-0000-0000-0000-000000000000"; | 
 | 68 |     } | 
 | 69 |     return string.data(); | 
 | 70 | #else | 
 | 71 |     return "00000000-0000-0000-0000-000000000000"; | 
 | 72 | #endif | 
 | 73 |   } | 
| Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 74 | }; | 
 | 75 |  | 
 | 76 | }  // namespace redfish |