blob: 2e084d4481eda35dc2e1146a5bee145c63b4bbcc [file] [log] [blame]
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02001/*
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 <boost/container/flat_map.hpp>
19#include <node.hpp>
20#include <utils/json_utils.hpp>
21
22namespace redfish
23{
24
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060025using InterfacesProperties = boost::container::flat_map<
26 std::string,
27 boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>;
28
Ed Tanous029573d2019-02-01 10:57:49 -080029void getResourceList(std::shared_ptr<AsyncResp> aResp,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020030 const std::string &subclass,
Alpana Kumari32bee762019-04-25 04:47:57 -050031 const std::vector<const char *> &collectionName)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020032{
33 BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources.";
34 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -080035 [subclass, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020036 const boost::system::error_code ec,
37 const boost::container::flat_map<
38 std::string, boost::container::flat_map<
39 std::string, std::vector<std::string>>>
40 &subtree) {
41 if (ec)
42 {
43 BMCWEB_LOG_DEBUG << "DBUS response error";
44 messages::internalError(aResp->res);
45 return;
46 }
47 nlohmann::json &members = aResp->res.jsonValue["Members"];
48 members = nlohmann::json::array();
49
50 for (const auto &object : subtree)
51 {
52 auto iter = object.first.rfind("/");
53 if ((iter != std::string::npos) && (iter < object.first.size()))
54 {
55 members.push_back(
Ed Tanous029573d2019-02-01 10:57:49 -080056 {{"@odata.id", "/redfish/v1/Systems/system/" +
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020057 subclass + "/" +
58 object.first.substr(iter + 1)}});
59 }
60 }
61 aResp->res.jsonValue["Members@odata.count"] = members.size();
62 },
63 "xyz.openbmc_project.ObjectMapper",
64 "/xyz/openbmc_project/object_mapper",
65 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Alpana Kumari32bee762019-04-25 04:47:57 -050066 "/xyz/openbmc_project/inventory", int32_t(0), collectionName);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020067}
68
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060069void getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp,
70 const InterfacesProperties &cpuInterfacesProperties)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020071{
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060072 BMCWEB_LOG_DEBUG << "Get CPU resources by interface.";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020073
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060074 const bool *present = NULL;
75 const bool *functional = NULL;
76 for (const auto &interface : cpuInterfacesProperties)
77 {
78 for (const auto &property : interface.second)
79 {
80 if (property.first == "ProcessorCoreCount")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +020081 {
Ed Tanous883b3112018-12-06 16:13:35 -080082 const uint16_t *coresCount =
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060083 std::get_if<uint16_t>(&property.second);
Ed Tanous883b3112018-12-06 16:13:35 -080084 if (coresCount == nullptr)
85 {
86 // Important property not in desired type
87 messages::internalError(aResp->res);
88 return;
89 }
90 if (*coresCount == 0)
91 {
92 // Slot is not populated, set status end return
93 aResp->res.jsonValue["Status"]["State"] = "Absent";
94 aResp->res.jsonValue["Status"]["Health"] = "OK";
95 // HTTP Code will be set up automatically, just return
96 return;
97 }
98
99 aResp->res.jsonValue["TotalCores"] = *coresCount;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200100 }
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600101 else if (property.first == "ProcessorType")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200102 {
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600103 aResp->res.jsonValue["Name"] = property.second;
104 }
105 else if (property.first == "Manufacturer")
106 {
107 const std::string *value =
108 std::get_if<std::string>(&property.second);
109 if (value != nullptr)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200110 {
111 aResp->res.jsonValue["Manufacturer"] = property.second;
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600112 // Otherwise would be unexpected.
113 if (value->find("Intel") != std::string::npos)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200114 {
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600115 aResp->res.jsonValue["ProcessorArchitecture"] = "x86";
116 aResp->res.jsonValue["InstructionSet"] = "x86-64";
117 }
118 else if (value->find("IBM") != std::string::npos)
119 {
120 aResp->res.jsonValue["ProcessorArchitecture"] = "Power";
121 aResp->res.jsonValue["InstructionSet"] = "PowerISA";
122 }
123 }
124 }
125 else if (property.first == "ProcessorMaxSpeed")
126 {
127 aResp->res.jsonValue["MaxSpeedMHz"] = property.second;
128 }
129 else if (property.first == "ProcessorThreadCount")
130 {
131 aResp->res.jsonValue["TotalThreads"] = property.second;
132 }
133 else if (property.first == "Model")
134 {
135 const std::string *value =
136 std::get_if<std::string>(&property.second);
137 if (value != nullptr)
138 {
139 aResp->res.jsonValue["Model"] = *value;
140 }
141 }
142 else if (property.first == "Present")
143 {
144 present = std::get_if<bool>(&property.second);
145 }
146 else if (property.first == "Functional")
147 {
148 functional = std::get_if<bool>(&property.second);
149 }
150 }
151 }
152
153 if ((present == nullptr) || (functional == nullptr))
154 {
155 // Important property not in desired type
156 messages::internalError(aResp->res);
157 return;
158 }
159
160 if (*present == false)
161 {
162 aResp->res.jsonValue["Status"]["State"] = "Absent";
163 aResp->res.jsonValue["Status"]["Health"] = "OK";
164 }
165 else
166 {
167 aResp->res.jsonValue["Status"]["State"] = "Enabled";
168 if (*functional == true)
169 {
170 aResp->res.jsonValue["Status"]["Health"] = "OK";
171 }
172 else
173 {
174 aResp->res.jsonValue["Status"]["Health"] = "Critical";
175 }
176 }
177
178 return;
179}
180
181void getCpuDataByService(std::shared_ptr<AsyncResp> aResp,
182 const std::string &cpuId, const std::string &service,
183 const std::string &objPath)
184{
185 BMCWEB_LOG_DEBUG << "Get available system cpu resources by service.";
186
187 crow::connections::systemBus->async_method_call(
188 [cpuId, service, objPath, aResp{std::move(aResp)}](
189 const boost::system::error_code ec,
190 const dbus::utility::ManagedObjectType &dbusData) {
191 if (ec)
192 {
193 BMCWEB_LOG_DEBUG << "DBUS response error";
194 messages::internalError(aResp->res);
195 return;
196 }
197 aResp->res.jsonValue["Id"] = cpuId;
198 aResp->res.jsonValue["Name"] = "Processor";
199 aResp->res.jsonValue["ProcessorType"] = "CPU";
200
201 std::string corePath = objPath + "/core";
202 size_t totalCores = 0;
203 for (const auto &object : dbusData)
204 {
205 if (object.first.str == objPath)
206 {
207 getCpuDataByInterface(aResp, object.second);
208 }
209 else if (boost::starts_with(object.first.str, corePath))
210 {
211 for (const auto &interface : object.second)
212 {
213 if (interface.first ==
214 "xyz.openbmc_project.Inventory.Item")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200215 {
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600216 for (const auto &property : interface.second)
217 {
218 if (property.first == "Present")
219 {
220 const bool *present =
221 std::get_if<bool>(&property.second);
222 if (present != nullptr)
223 {
224 if (*present == true)
225 {
226 totalCores++;
227 }
228 }
229 }
230 }
Gunnar Millsb957ba52019-01-31 15:58:15 -0600231 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200232 }
233 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200234 }
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600235 // In getCpuDataByInterface(), state and health are set
236 // based on the present and functional status. If core
237 // count is zero, then it has a higher precedence.
238 if (totalCores == 0)
239 {
240 // Slot is not populated, set status end return
241 aResp->res.jsonValue["Status"]["State"] = "Absent";
242 aResp->res.jsonValue["Status"]["Health"] = "OK";
243 }
244 aResp->res.jsonValue["TotalCores"] = totalCores;
245 return;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200246 },
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600247 service, "/xyz/openbmc_project/inventory",
248 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200249}
250
Alpana Kumari32bee762019-04-25 04:47:57 -0500251void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp,
252 const std::string &acclrtrId,
253 const std::string &service,
254 const std::string &objPath)
255{
256 BMCWEB_LOG_DEBUG
257 << "Get available system Accelerator resources by service.";
258 crow::connections::systemBus->async_method_call(
259 [acclrtrId, aResp{std::move(aResp)}](
260 const boost::system::error_code ec,
261 const boost::container::flat_map<
Santosh Puranik94e1b822019-07-24 04:48:32 -0500262 std::string, std::variant<std::string, uint32_t, uint16_t,
263 bool>> &properties) {
Alpana Kumari32bee762019-04-25 04:47:57 -0500264 if (ec)
265 {
266 BMCWEB_LOG_DEBUG << "DBUS response error";
267 messages::internalError(aResp->res);
268 return;
269 }
270 aResp->res.jsonValue["Id"] = acclrtrId;
271 aResp->res.jsonValue["Name"] = "Processor";
Santosh Puranik94e1b822019-07-24 04:48:32 -0500272 const bool *accPresent = nullptr;
273 const bool *accFunctional = nullptr;
Alpana Kumari32bee762019-04-25 04:47:57 -0500274 std::string state = "";
275
276 for (const auto &property : properties)
277 {
278 if (property.first == "Functional")
279 {
Santosh Puranik94e1b822019-07-24 04:48:32 -0500280 accFunctional = std::get_if<bool>(&property.second);
Alpana Kumari32bee762019-04-25 04:47:57 -0500281 }
282 else if (property.first == "Present")
283 {
Santosh Puranik94e1b822019-07-24 04:48:32 -0500284 accPresent = std::get_if<bool>(&property.second);
Alpana Kumari32bee762019-04-25 04:47:57 -0500285 }
286 }
287
288 if (!accPresent || !accFunctional)
289 {
290 BMCWEB_LOG_DEBUG << "Required properties missing in DBUS "
291 "response";
292 messages::internalError(aResp->res);
293 return;
294 }
295
Santosh Puranik94e1b822019-07-24 04:48:32 -0500296 if (*accPresent && *accFunctional)
Alpana Kumari32bee762019-04-25 04:47:57 -0500297 {
298 state = "Enabled";
299 }
Santosh Puranik94e1b822019-07-24 04:48:32 -0500300 else if (*accPresent)
Alpana Kumari32bee762019-04-25 04:47:57 -0500301 {
302 state = "UnavailableOffline";
303 }
304 else
305 {
306 state = "Absent";
307 }
308 aResp->res.jsonValue["Status"]["State"] = state;
309 aResp->res.jsonValue["Status"]["Health"] = "OK";
310 aResp->res.jsonValue["ProcessorType"] = "Accelerator";
311 },
312 service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
313}
314
315void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string &cpuId,
316 const std::vector<const char *> inventoryItems)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200317{
318 BMCWEB_LOG_DEBUG << "Get available system cpu resources.";
Alpana Kumari32bee762019-04-25 04:47:57 -0500319
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200320 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800321 [cpuId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200322 const boost::system::error_code ec,
323 const boost::container::flat_map<
324 std::string, boost::container::flat_map<
325 std::string, std::vector<std::string>>>
326 &subtree) {
327 if (ec)
328 {
329 BMCWEB_LOG_DEBUG << "DBUS response error";
330 messages::internalError(aResp->res);
331 return;
332 }
333 for (const auto &object : subtree)
334 {
335 if (boost::ends_with(object.first, cpuId))
336 {
337 for (const auto &service : object.second)
338 {
Alpana Kumari32bee762019-04-25 04:47:57 -0500339 for (const auto &inventory : service.second)
340 if (inventory ==
341 "xyz.openbmc_project.Inventory.Item.Cpu")
342 {
343 getCpuDataByService(aResp, cpuId, service.first,
344 object.first);
345 }
346 else if (inventory == "xyz.openbmc_project."
347 "Inventory.Item.Accelerator")
348 {
349 getAcceleratorDataByService(
350 aResp, cpuId, service.first, object.first);
351 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200352 return;
353 }
354 }
355 }
356 // Object not found
357 messages::resourceNotFound(aResp->res, "Processor", cpuId);
358 return;
359 },
360 "xyz.openbmc_project.ObjectMapper",
361 "/xyz/openbmc_project/object_mapper",
362 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Alpana Kumari32bee762019-04-25 04:47:57 -0500363 "/xyz/openbmc_project/inventory", int32_t(0), inventoryItems);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200364};
365
366void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
Ed Tanous029573d2019-02-01 10:57:49 -0800367 const std::string &dimmId, const std::string &service,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200368 const std::string &objPath)
369{
370 BMCWEB_LOG_DEBUG << "Get available system components.";
371 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800372 [dimmId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200373 const boost::system::error_code ec,
374 const boost::container::flat_map<
Ed Tanousabf2add2019-01-22 16:40:12 -0800375 std::string, std::variant<std::string, uint32_t, uint16_t>>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200376 &properties) {
377 if (ec)
378 {
379 BMCWEB_LOG_DEBUG << "DBUS response error";
380 messages::internalError(aResp->res);
381
382 return;
383 }
384 aResp->res.jsonValue["Id"] = dimmId;
385 aResp->res.jsonValue["Name"] = "DIMM Slot";
386
387 const auto memorySizeProperty = properties.find("MemorySizeInKB");
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600388 if (memorySizeProperty != properties.end())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200389 {
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600390 const uint32_t *memorySize =
Ed Tanousabf2add2019-01-22 16:40:12 -0800391 std::get_if<uint32_t>(&memorySizeProperty->second);
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600392 if (memorySize == nullptr)
393 {
394 // Important property not in desired type
395 messages::internalError(aResp->res);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200396
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600397 return;
398 }
399 if (*memorySize == 0)
400 {
401 // Slot is not populated, set status end return
402 aResp->res.jsonValue["Status"]["State"] = "Absent";
403 aResp->res.jsonValue["Status"]["Health"] = "OK";
404 // HTTP Code will be set up automatically, just return
405 return;
406 }
407 aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200408 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200409 aResp->res.jsonValue["Status"]["State"] = "Enabled";
410 aResp->res.jsonValue["Status"]["Health"] = "OK";
411
412 for (const auto &property : properties)
413 {
414 if (property.first == "MemoryDataWidth")
415 {
416 aResp->res.jsonValue["DataWidthBits"] = property.second;
417 }
Manojkiran Eda7e236ca2019-06-25 23:06:32 +0530418 else if (property.first == "PartNumber")
419 {
420 aResp->res.jsonValue["PartNumber"] = property.second;
421 }
422 else if (property.first == "SerialNumber")
423 {
424 aResp->res.jsonValue["SerialNumber"] = property.second;
425 }
426 else if (property.first == "Manufacturer")
427 {
428 aResp->res.jsonValue["Manufacturer"] = property.second;
429 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200430 else if (property.first == "MemoryType")
431 {
432 const auto *value =
Ed Tanousabf2add2019-01-22 16:40:12 -0800433 std::get_if<std::string>(&property.second);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200434 if (value != nullptr)
435 {
436 aResp->res.jsonValue["MemoryDeviceType"] = *value;
437 if (boost::starts_with(*value, "DDR"))
438 {
439 aResp->res.jsonValue["MemoryType"] = "DRAM";
440 }
441 }
442 }
443 }
444 },
445 service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
446}
447
Ed Tanous029573d2019-02-01 10:57:49 -0800448void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string &dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200449{
450 BMCWEB_LOG_DEBUG << "Get available system dimm resources.";
451 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800452 [dimmId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200453 const boost::system::error_code ec,
454 const boost::container::flat_map<
455 std::string, boost::container::flat_map<
456 std::string, std::vector<std::string>>>
457 &subtree) {
458 if (ec)
459 {
460 BMCWEB_LOG_DEBUG << "DBUS response error";
461 messages::internalError(aResp->res);
462
463 return;
464 }
465 for (const auto &object : subtree)
466 {
467 if (boost::ends_with(object.first, dimmId))
468 {
469 for (const auto &service : object.second)
470 {
Ed Tanous029573d2019-02-01 10:57:49 -0800471 getDimmDataByService(aResp, dimmId, service.first,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200472 object.first);
473 return;
474 }
475 }
476 }
477 // Object not found
478 messages::resourceNotFound(aResp->res, "Memory", dimmId);
479 return;
480 },
481 "xyz.openbmc_project.ObjectMapper",
482 "/xyz/openbmc_project/object_mapper",
483 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
484 "/xyz/openbmc_project/inventory", int32_t(0),
485 std::array<const char *, 1>{"xyz.openbmc_project.Inventory.Item.Dimm"});
486};
487
488class ProcessorCollection : public Node
489{
490 public:
491 /*
492 * Default Constructor
493 */
494 ProcessorCollection(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800495 Node(app, "/redfish/v1/Systems/system/Processors/")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200496 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200497 entityPrivileges = {
498 {boost::beast::http::verb::get, {{"Login"}}},
499 {boost::beast::http::verb::head, {{"Login"}}},
500 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
501 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
502 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
503 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
504 }
505
506 private:
507 /**
508 * Functions triggers appropriate requests on DBus
509 */
510 void doGet(crow::Response &res, const crow::Request &req,
511 const std::vector<std::string> &params) override
512 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800513 res.jsonValue["@odata.type"] =
514 "#ProcessorCollection.ProcessorCollection";
515 res.jsonValue["Name"] = "Processor Collection";
516 res.jsonValue["@odata.context"] =
517 "/redfish/v1/$metadata#ProcessorCollection.ProcessorCollection";
518
Ed Tanous029573d2019-02-01 10:57:49 -0800519 res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200520 auto asyncResp = std::make_shared<AsyncResp>(res);
521
Ed Tanous029573d2019-02-01 10:57:49 -0800522 getResourceList(asyncResp, "Processors",
Alpana Kumari32bee762019-04-25 04:47:57 -0500523 {"xyz.openbmc_project.Inventory.Item.Cpu",
524 "xyz.openbmc_project.Inventory.Item.Accelerator"});
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200525 }
526};
527
528class Processor : public Node
529{
530 public:
531 /*
532 * Default Constructor
533 */
534 Processor(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800535 Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200536 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200537 entityPrivileges = {
538 {boost::beast::http::verb::get, {{"Login"}}},
539 {boost::beast::http::verb::head, {{"Login"}}},
540 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
541 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
542 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
543 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
544 }
545
546 private:
547 /**
548 * Functions triggers appropriate requests on DBus
549 */
550 void doGet(crow::Response &res, const crow::Request &req,
551 const std::vector<std::string> &params) override
552 {
553 // Check if there is required param, truly entering this shall be
554 // impossible
555 if (params.size() != 1)
556 {
557 messages::internalError(res);
558
559 res.end();
560 return;
561 }
Alpana Kumari32bee762019-04-25 04:47:57 -0500562 const std::string &processorId = params[0];
Ed Tanous029573d2019-02-01 10:57:49 -0800563 res.jsonValue["@odata.type"] = "#Processor.v1_3_1.Processor";
564 res.jsonValue["@odata.context"] =
565 "/redfish/v1/$metadata#Processor.Processor";
566 res.jsonValue["@odata.id"] =
Alpana Kumari32bee762019-04-25 04:47:57 -0500567 "/redfish/v1/Systems/system/Processors/" + processorId;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200568
Ed Tanous029573d2019-02-01 10:57:49 -0800569 auto asyncResp = std::make_shared<AsyncResp>(res);
570
Alpana Kumari32bee762019-04-25 04:47:57 -0500571 getCpuData(asyncResp, processorId,
572 {"xyz.openbmc_project.Inventory.Item.Cpu",
573 "xyz.openbmc_project.Inventory.Item.Accelerator"});
Ed Tanous029573d2019-02-01 10:57:49 -0800574 }
575};
576
577class MemoryCollection : public Node
578{
579 public:
580 /*
581 * Default Constructor
582 */
583 MemoryCollection(CrowApp &app) :
584 Node(app, "/redfish/v1/Systems/system/Memory/")
585 {
586 entityPrivileges = {
587 {boost::beast::http::verb::get, {{"Login"}}},
588 {boost::beast::http::verb::head, {{"Login"}}},
589 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
590 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
591 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
592 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
593 }
594
595 private:
596 /**
597 * Functions triggers appropriate requests on DBus
598 */
599 void doGet(crow::Response &res, const crow::Request &req,
600 const std::vector<std::string> &params) override
601 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800602 res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection";
603 res.jsonValue["Name"] = "Memory Module Collection";
604 res.jsonValue["@odata.context"] =
605 "/redfish/v1/$metadata#MemoryCollection.MemoryCollection";
Ed Tanous029573d2019-02-01 10:57:49 -0800606 res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory/";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200607 auto asyncResp = std::make_shared<AsyncResp>(res);
608
Ed Tanous029573d2019-02-01 10:57:49 -0800609 getResourceList(asyncResp, "Memory",
Alpana Kumari32bee762019-04-25 04:47:57 -0500610 {"xyz.openbmc_project.Inventory.Item.Dimm"});
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200611 }
612};
613
614class Memory : public Node
615{
616 public:
617 /*
618 * Default Constructor
619 */
620 Memory(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800621 Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200622 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200623 entityPrivileges = {
624 {boost::beast::http::verb::get, {{"Login"}}},
625 {boost::beast::http::verb::head, {{"Login"}}},
626 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
627 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
628 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
629 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
630 }
631
632 private:
633 /**
634 * Functions triggers appropriate requests on DBus
635 */
636 void doGet(crow::Response &res, const crow::Request &req,
637 const std::vector<std::string> &params) override
638 {
639 // Check if there is required param, truly entering this shall be
640 // impossible
Ed Tanous029573d2019-02-01 10:57:49 -0800641 if (params.size() != 1)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200642 {
643 messages::internalError(res);
644 res.end();
645 return;
646 }
Ed Tanous029573d2019-02-01 10:57:49 -0800647 const std::string &dimmId = params[0];
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200648
Rapkiewicz, Pawelbb3d9942018-11-22 10:59:11 +0100649 res.jsonValue["@odata.type"] = "#Memory.v1_6_0.Memory";
Ed Tanous0f74e642018-11-12 15:17:05 -0800650 res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Memory.Memory";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200651 res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800652 "/redfish/v1/Systems/system/Memory/" + dimmId;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200653 auto asyncResp = std::make_shared<AsyncResp>(res);
654
Ed Tanous029573d2019-02-01 10:57:49 -0800655 getDimmData(asyncResp, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200656 }
657};
658
659} // namespace redfish