blob: a4d882201a0ef731db0d8759c567724472f76b3a [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",
Ed Tanous271584a2019-07-09 16:24:22 -070066 "/xyz/openbmc_project/inventory", 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
Ed Tanous99131cd2019-10-24 11:12:47 -070074 const bool *present = nullptr;
75 const bool *functional = nullptr;
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -060076 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 }
Gunnar Millsf9dcc112020-02-13 13:19:43 -0600142 else if (property.first == "PartNumber")
143 {
144 aResp->res.jsonValue["PartNumber"] = property.second;
145 }
146 else if (property.first == "SerialNumber")
147 {
148 aResp->res.jsonValue["SerialNumber"] = property.second;
149 }
150 else if (property.first == "Version")
151 {
152 aResp->res.jsonValue["Version"] = property.second;
153 }
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600154 else if (property.first == "Present")
155 {
156 present = std::get_if<bool>(&property.second);
157 }
158 else if (property.first == "Functional")
159 {
160 functional = std::get_if<bool>(&property.second);
161 }
162 }
163 }
164
165 if ((present == nullptr) || (functional == nullptr))
166 {
167 // Important property not in desired type
168 messages::internalError(aResp->res);
169 return;
170 }
171
172 if (*present == false)
173 {
174 aResp->res.jsonValue["Status"]["State"] = "Absent";
175 aResp->res.jsonValue["Status"]["Health"] = "OK";
176 }
177 else
178 {
179 aResp->res.jsonValue["Status"]["State"] = "Enabled";
180 if (*functional == true)
181 {
182 aResp->res.jsonValue["Status"]["Health"] = "OK";
183 }
184 else
185 {
186 aResp->res.jsonValue["Status"]["Health"] = "Critical";
187 }
188 }
189
190 return;
191}
192
193void getCpuDataByService(std::shared_ptr<AsyncResp> aResp,
194 const std::string &cpuId, const std::string &service,
195 const std::string &objPath)
196{
197 BMCWEB_LOG_DEBUG << "Get available system cpu resources by service.";
198
199 crow::connections::systemBus->async_method_call(
200 [cpuId, service, objPath, aResp{std::move(aResp)}](
201 const boost::system::error_code ec,
202 const dbus::utility::ManagedObjectType &dbusData) {
203 if (ec)
204 {
205 BMCWEB_LOG_DEBUG << "DBUS response error";
206 messages::internalError(aResp->res);
207 return;
208 }
209 aResp->res.jsonValue["Id"] = cpuId;
210 aResp->res.jsonValue["Name"] = "Processor";
211 aResp->res.jsonValue["ProcessorType"] = "CPU";
212
213 std::string corePath = objPath + "/core";
214 size_t totalCores = 0;
215 for (const auto &object : dbusData)
216 {
217 if (object.first.str == objPath)
218 {
219 getCpuDataByInterface(aResp, object.second);
220 }
221 else if (boost::starts_with(object.first.str, corePath))
222 {
223 for (const auto &interface : object.second)
224 {
225 if (interface.first ==
226 "xyz.openbmc_project.Inventory.Item")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200227 {
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600228 for (const auto &property : interface.second)
229 {
230 if (property.first == "Present")
231 {
232 const bool *present =
233 std::get_if<bool>(&property.second);
234 if (present != nullptr)
235 {
236 if (*present == true)
237 {
238 totalCores++;
239 }
240 }
241 }
242 }
Gunnar Millsb957ba52019-01-31 15:58:15 -0600243 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200244 }
245 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200246 }
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600247 // In getCpuDataByInterface(), state and health are set
248 // based on the present and functional status. If core
249 // count is zero, then it has a higher precedence.
250 if (totalCores == 0)
251 {
252 // Slot is not populated, set status end return
253 aResp->res.jsonValue["Status"]["State"] = "Absent";
254 aResp->res.jsonValue["Status"]["Health"] = "OK";
255 }
256 aResp->res.jsonValue["TotalCores"] = totalCores;
257 return;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200258 },
RAJESWARAN THILLAIGOVINDANec8faf92019-02-21 10:59:03 -0600259 service, "/xyz/openbmc_project/inventory",
260 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200261}
262
Alpana Kumari32bee762019-04-25 04:47:57 -0500263void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp,
264 const std::string &acclrtrId,
265 const std::string &service,
266 const std::string &objPath)
267{
268 BMCWEB_LOG_DEBUG
269 << "Get available system Accelerator resources by service.";
270 crow::connections::systemBus->async_method_call(
271 [acclrtrId, aResp{std::move(aResp)}](
272 const boost::system::error_code ec,
273 const boost::container::flat_map<
Santosh Puranik94e1b822019-07-24 04:48:32 -0500274 std::string, std::variant<std::string, uint32_t, uint16_t,
275 bool>> &properties) {
Alpana Kumari32bee762019-04-25 04:47:57 -0500276 if (ec)
277 {
278 BMCWEB_LOG_DEBUG << "DBUS response error";
279 messages::internalError(aResp->res);
280 return;
281 }
282 aResp->res.jsonValue["Id"] = acclrtrId;
283 aResp->res.jsonValue["Name"] = "Processor";
Santosh Puranik94e1b822019-07-24 04:48:32 -0500284 const bool *accPresent = nullptr;
285 const bool *accFunctional = nullptr;
Alpana Kumari32bee762019-04-25 04:47:57 -0500286 std::string state = "";
287
288 for (const auto &property : properties)
289 {
290 if (property.first == "Functional")
291 {
Santosh Puranik94e1b822019-07-24 04:48:32 -0500292 accFunctional = std::get_if<bool>(&property.second);
Alpana Kumari32bee762019-04-25 04:47:57 -0500293 }
294 else if (property.first == "Present")
295 {
Santosh Puranik94e1b822019-07-24 04:48:32 -0500296 accPresent = std::get_if<bool>(&property.second);
Alpana Kumari32bee762019-04-25 04:47:57 -0500297 }
298 }
299
300 if (!accPresent || !accFunctional)
301 {
302 BMCWEB_LOG_DEBUG << "Required properties missing in DBUS "
303 "response";
304 messages::internalError(aResp->res);
305 return;
306 }
307
Santosh Puranik94e1b822019-07-24 04:48:32 -0500308 if (*accPresent && *accFunctional)
Alpana Kumari32bee762019-04-25 04:47:57 -0500309 {
310 state = "Enabled";
311 }
Santosh Puranik94e1b822019-07-24 04:48:32 -0500312 else if (*accPresent)
Alpana Kumari32bee762019-04-25 04:47:57 -0500313 {
314 state = "UnavailableOffline";
315 }
316 else
317 {
318 state = "Absent";
319 }
320 aResp->res.jsonValue["Status"]["State"] = state;
321 aResp->res.jsonValue["Status"]["Health"] = "OK";
322 aResp->res.jsonValue["ProcessorType"] = "Accelerator";
323 },
324 service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
325}
326
327void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string &cpuId,
328 const std::vector<const char *> inventoryItems)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200329{
330 BMCWEB_LOG_DEBUG << "Get available system cpu resources.";
Alpana Kumari32bee762019-04-25 04:47:57 -0500331
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200332 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800333 [cpuId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200334 const boost::system::error_code ec,
335 const boost::container::flat_map<
336 std::string, boost::container::flat_map<
337 std::string, std::vector<std::string>>>
338 &subtree) {
339 if (ec)
340 {
341 BMCWEB_LOG_DEBUG << "DBUS response error";
342 messages::internalError(aResp->res);
343 return;
344 }
345 for (const auto &object : subtree)
346 {
347 if (boost::ends_with(object.first, cpuId))
348 {
349 for (const auto &service : object.second)
350 {
Alpana Kumari32bee762019-04-25 04:47:57 -0500351 for (const auto &inventory : service.second)
352 if (inventory ==
353 "xyz.openbmc_project.Inventory.Item.Cpu")
354 {
355 getCpuDataByService(aResp, cpuId, service.first,
356 object.first);
357 }
358 else if (inventory == "xyz.openbmc_project."
359 "Inventory.Item.Accelerator")
360 {
361 getAcceleratorDataByService(
362 aResp, cpuId, service.first, object.first);
363 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200364 return;
365 }
366 }
367 }
368 // Object not found
369 messages::resourceNotFound(aResp->res, "Processor", cpuId);
370 return;
371 },
372 "xyz.openbmc_project.ObjectMapper",
373 "/xyz/openbmc_project/object_mapper",
374 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous271584a2019-07-09 16:24:22 -0700375 "/xyz/openbmc_project/inventory", 0, inventoryItems);
376}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200377
378void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
Ed Tanous029573d2019-02-01 10:57:49 -0800379 const std::string &dimmId, const std::string &service,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200380 const std::string &objPath)
381{
382 BMCWEB_LOG_DEBUG << "Get available system components.";
383 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800384 [dimmId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200385 const boost::system::error_code ec,
386 const boost::container::flat_map<
Ed Tanousabf2add2019-01-22 16:40:12 -0800387 std::string, std::variant<std::string, uint32_t, uint16_t>>
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200388 &properties) {
389 if (ec)
390 {
391 BMCWEB_LOG_DEBUG << "DBUS response error";
392 messages::internalError(aResp->res);
393
394 return;
395 }
396 aResp->res.jsonValue["Id"] = dimmId;
397 aResp->res.jsonValue["Name"] = "DIMM Slot";
398
399 const auto memorySizeProperty = properties.find("MemorySizeInKB");
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600400 if (memorySizeProperty != properties.end())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200401 {
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600402 const uint32_t *memorySize =
Ed Tanousabf2add2019-01-22 16:40:12 -0800403 std::get_if<uint32_t>(&memorySizeProperty->second);
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600404 if (memorySize == nullptr)
405 {
406 // Important property not in desired type
407 messages::internalError(aResp->res);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200408
Gunnar Millsaceb7fc2018-12-10 15:17:20 -0600409 return;
410 }
411 if (*memorySize == 0)
412 {
413 // Slot is not populated, set status end return
414 aResp->res.jsonValue["Status"]["State"] = "Absent";
415 aResp->res.jsonValue["Status"]["Health"] = "OK";
416 // HTTP Code will be set up automatically, just return
417 return;
418 }
419 aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200420 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200421 aResp->res.jsonValue["Status"]["State"] = "Enabled";
422 aResp->res.jsonValue["Status"]["Health"] = "OK";
423
424 for (const auto &property : properties)
425 {
426 if (property.first == "MemoryDataWidth")
427 {
428 aResp->res.jsonValue["DataWidthBits"] = property.second;
429 }
Manojkiran Eda7e236ca2019-06-25 23:06:32 +0530430 else if (property.first == "PartNumber")
431 {
432 aResp->res.jsonValue["PartNumber"] = property.second;
433 }
434 else if (property.first == "SerialNumber")
435 {
436 aResp->res.jsonValue["SerialNumber"] = property.second;
437 }
438 else if (property.first == "Manufacturer")
439 {
440 aResp->res.jsonValue["Manufacturer"] = property.second;
441 }
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200442 else if (property.first == "MemoryType")
443 {
444 const auto *value =
Ed Tanousabf2add2019-01-22 16:40:12 -0800445 std::get_if<std::string>(&property.second);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200446 if (value != nullptr)
447 {
448 aResp->res.jsonValue["MemoryDeviceType"] = *value;
449 if (boost::starts_with(*value, "DDR"))
450 {
451 aResp->res.jsonValue["MemoryType"] = "DRAM";
452 }
453 }
454 }
455 }
456 },
457 service, objPath, "org.freedesktop.DBus.Properties", "GetAll", "");
458}
459
Ed Tanous029573d2019-02-01 10:57:49 -0800460void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string &dimmId)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200461{
462 BMCWEB_LOG_DEBUG << "Get available system dimm resources.";
463 crow::connections::systemBus->async_method_call(
Ed Tanous029573d2019-02-01 10:57:49 -0800464 [dimmId, aResp{std::move(aResp)}](
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200465 const boost::system::error_code ec,
466 const boost::container::flat_map<
467 std::string, boost::container::flat_map<
468 std::string, std::vector<std::string>>>
469 &subtree) {
470 if (ec)
471 {
472 BMCWEB_LOG_DEBUG << "DBUS response error";
473 messages::internalError(aResp->res);
474
475 return;
476 }
477 for (const auto &object : subtree)
478 {
479 if (boost::ends_with(object.first, dimmId))
480 {
481 for (const auto &service : object.second)
482 {
Ed Tanous029573d2019-02-01 10:57:49 -0800483 getDimmDataByService(aResp, dimmId, service.first,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200484 object.first);
485 return;
486 }
487 }
488 }
489 // Object not found
490 messages::resourceNotFound(aResp->res, "Memory", dimmId);
491 return;
492 },
493 "xyz.openbmc_project.ObjectMapper",
494 "/xyz/openbmc_project/object_mapper",
495 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous271584a2019-07-09 16:24:22 -0700496 "/xyz/openbmc_project/inventory", 0,
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200497 std::array<const char *, 1>{"xyz.openbmc_project.Inventory.Item.Dimm"});
Ed Tanous271584a2019-07-09 16:24:22 -0700498}
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200499
500class ProcessorCollection : public Node
501{
502 public:
503 /*
504 * Default Constructor
505 */
506 ProcessorCollection(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800507 Node(app, "/redfish/v1/Systems/system/Processors/")
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200508 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200509 entityPrivileges = {
510 {boost::beast::http::verb::get, {{"Login"}}},
511 {boost::beast::http::verb::head, {{"Login"}}},
512 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
513 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
514 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
515 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
516 }
517
518 private:
519 /**
520 * Functions triggers appropriate requests on DBus
521 */
522 void doGet(crow::Response &res, const crow::Request &req,
523 const std::vector<std::string> &params) override
524 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800525 res.jsonValue["@odata.type"] =
526 "#ProcessorCollection.ProcessorCollection";
527 res.jsonValue["Name"] = "Processor Collection";
Ed Tanous0f74e642018-11-12 15:17:05 -0800528
Ed Tanous029573d2019-02-01 10:57:49 -0800529 res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200530 auto asyncResp = std::make_shared<AsyncResp>(res);
531
Ed Tanous029573d2019-02-01 10:57:49 -0800532 getResourceList(asyncResp, "Processors",
Alpana Kumari32bee762019-04-25 04:47:57 -0500533 {"xyz.openbmc_project.Inventory.Item.Cpu",
534 "xyz.openbmc_project.Inventory.Item.Accelerator"});
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200535 }
536};
537
538class Processor : public Node
539{
540 public:
541 /*
542 * Default Constructor
543 */
544 Processor(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800545 Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200546 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200547 entityPrivileges = {
548 {boost::beast::http::verb::get, {{"Login"}}},
549 {boost::beast::http::verb::head, {{"Login"}}},
550 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
551 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
552 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
553 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
554 }
555
556 private:
557 /**
558 * Functions triggers appropriate requests on DBus
559 */
560 void doGet(crow::Response &res, const crow::Request &req,
561 const std::vector<std::string> &params) override
562 {
563 // Check if there is required param, truly entering this shall be
564 // impossible
565 if (params.size() != 1)
566 {
567 messages::internalError(res);
568
569 res.end();
570 return;
571 }
Alpana Kumari32bee762019-04-25 04:47:57 -0500572 const std::string &processorId = params[0];
Gunnar Millsf9dcc112020-02-13 13:19:43 -0600573 res.jsonValue["@odata.type"] = "#Processor.v1_7_0.Processor";
Ed Tanous029573d2019-02-01 10:57:49 -0800574 res.jsonValue["@odata.id"] =
Alpana Kumari32bee762019-04-25 04:47:57 -0500575 "/redfish/v1/Systems/system/Processors/" + processorId;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200576
Ed Tanous029573d2019-02-01 10:57:49 -0800577 auto asyncResp = std::make_shared<AsyncResp>(res);
578
Alpana Kumari32bee762019-04-25 04:47:57 -0500579 getCpuData(asyncResp, processorId,
580 {"xyz.openbmc_project.Inventory.Item.Cpu",
581 "xyz.openbmc_project.Inventory.Item.Accelerator"});
Ed Tanous029573d2019-02-01 10:57:49 -0800582 }
583};
584
585class MemoryCollection : public Node
586{
587 public:
588 /*
589 * Default Constructor
590 */
591 MemoryCollection(CrowApp &app) :
592 Node(app, "/redfish/v1/Systems/system/Memory/")
593 {
594 entityPrivileges = {
595 {boost::beast::http::verb::get, {{"Login"}}},
596 {boost::beast::http::verb::head, {{"Login"}}},
597 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
598 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
599 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
600 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
601 }
602
603 private:
604 /**
605 * Functions triggers appropriate requests on DBus
606 */
607 void doGet(crow::Response &res, const crow::Request &req,
608 const std::vector<std::string> &params) override
609 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800610 res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection";
611 res.jsonValue["Name"] = "Memory Module Collection";
Ed Tanous029573d2019-02-01 10:57:49 -0800612 res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory/";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200613 auto asyncResp = std::make_shared<AsyncResp>(res);
614
Ed Tanous029573d2019-02-01 10:57:49 -0800615 getResourceList(asyncResp, "Memory",
Alpana Kumari32bee762019-04-25 04:47:57 -0500616 {"xyz.openbmc_project.Inventory.Item.Dimm"});
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200617 }
618};
619
620class Memory : public Node
621{
622 public:
623 /*
624 * Default Constructor
625 */
626 Memory(CrowApp &app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800627 Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string())
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200628 {
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200629 entityPrivileges = {
630 {boost::beast::http::verb::get, {{"Login"}}},
631 {boost::beast::http::verb::head, {{"Login"}}},
632 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
633 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
634 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
635 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
636 }
637
638 private:
639 /**
640 * Functions triggers appropriate requests on DBus
641 */
642 void doGet(crow::Response &res, const crow::Request &req,
643 const std::vector<std::string> &params) override
644 {
645 // Check if there is required param, truly entering this shall be
646 // impossible
Ed Tanous029573d2019-02-01 10:57:49 -0800647 if (params.size() != 1)
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200648 {
649 messages::internalError(res);
650 res.end();
651 return;
652 }
Ed Tanous029573d2019-02-01 10:57:49 -0800653 const std::string &dimmId = params[0];
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200654
Rapkiewicz, Pawelbb3d9942018-11-22 10:59:11 +0100655 res.jsonValue["@odata.type"] = "#Memory.v1_6_0.Memory";
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200656 res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800657 "/redfish/v1/Systems/system/Memory/" + dimmId;
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200658 auto asyncResp = std::make_shared<AsyncResp>(res);
659
Ed Tanous029573d2019-02-01 10:57:49 -0800660 getDimmData(asyncResp, dimmId);
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +0200661 }
662};
663
664} // namespace redfish