blob: 34ef39a2f876156acfdaf3e2239b08a600c3cdb0 [file] [log] [blame]
Nikhil Potadea25aecc2019-08-23 16:35:26 -07001/*
2// Copyright (c) 2019 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
James Feist2ad9c2f2019-10-29 16:26:48 -070018#include "health.hpp"
James Feiste284a7c2019-11-20 16:20:23 -080019#include "openbmc_dbus_rest.hpp"
James Feist2ad9c2f2019-10-29 16:26:48 -070020
Nikhil Potadea25aecc2019-08-23 16:35:26 -070021#include <node.hpp>
22
23namespace redfish
24{
25class StorageCollection : public Node
26{
27 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070028 StorageCollection(App& app) :
Nikhil Potadea25aecc2019-08-23 16:35:26 -070029 Node(app, "/redfish/v1/Systems/system/Storage/")
30 {
31 entityPrivileges = {
32 {boost::beast::http::verb::get, {{"Login"}}},
33 {boost::beast::http::verb::head, {{"Login"}}},
34 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
35 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
36 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
37 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
38 }
39
40 private:
zhanghch058d1b46d2021-04-01 11:18:24 +080041 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
42 const crow::Request&, const std::vector<std::string>&) override
Nikhil Potadea25aecc2019-08-23 16:35:26 -070043 {
zhanghch058d1b46d2021-04-01 11:18:24 +080044 asyncResp->res.jsonValue["@odata.type"] =
45 "#StorageCollection.StorageCollection";
46 asyncResp->res.jsonValue["@odata.id"] =
47 "/redfish/v1/Systems/system/Storage";
48 asyncResp->res.jsonValue["Name"] = "Storage Collection";
49 asyncResp->res.jsonValue["Members"] = {
Nikhil Potadea25aecc2019-08-23 16:35:26 -070050 {{"@odata.id", "/redfish/v1/Systems/system/Storage/1"}}};
zhanghch058d1b46d2021-04-01 11:18:24 +080051 asyncResp->res.jsonValue["Members@odata.count"] = 1;
Nikhil Potadea25aecc2019-08-23 16:35:26 -070052 }
53};
54
55class Storage : public Node
56{
57 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070058 Storage(App& app) : Node(app, "/redfish/v1/Systems/system/Storage/1/")
Nikhil Potadea25aecc2019-08-23 16:35:26 -070059 {
60 entityPrivileges = {
61 {boost::beast::http::verb::get, {{"Login"}}},
62 {boost::beast::http::verb::head, {{"Login"}}},
63 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
64 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
65 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
66 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
67 }
68
69 private:
zhanghch058d1b46d2021-04-01 11:18:24 +080070 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
71 const crow::Request&, const std::vector<std::string>&) override
Nikhil Potadea25aecc2019-08-23 16:35:26 -070072 {
zhanghch058d1b46d2021-04-01 11:18:24 +080073 asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_7_1.Storage";
74 asyncResp->res.jsonValue["@odata.id"] =
75 "/redfish/v1/Systems/system/Storage/1";
76 asyncResp->res.jsonValue["Name"] = "Storage";
77 asyncResp->res.jsonValue["Id"] = "1";
78 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
Nikhil Potadea25aecc2019-08-23 16:35:26 -070079
James Feiste284a7c2019-11-20 16:20:23 -080080 auto health = std::make_shared<HealthPopulate>(asyncResp);
81 health->populate();
82
Nikhil Potadea25aecc2019-08-23 16:35:26 -070083 crow::connections::systemBus->async_method_call(
James Feiste284a7c2019-11-20 16:20:23 -080084 [asyncResp, health](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050085 const std::vector<std::string>& storageList) {
86 nlohmann::json& storageArray =
Nikhil Potadea25aecc2019-08-23 16:35:26 -070087 asyncResp->res.jsonValue["Drives"];
88 storageArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -050089 auto& count = asyncResp->res.jsonValue["Drives@odata.count"];
James Feiste284a7c2019-11-20 16:20:23 -080090 count = 0;
James Feist2ad9c2f2019-10-29 16:26:48 -070091
Nikhil Potadea25aecc2019-08-23 16:35:26 -070092 if (ec)
93 {
94 BMCWEB_LOG_ERROR << "Drive mapper call error";
95 messages::internalError(asyncResp->res);
96 return;
97 }
James Feist2ad9c2f2019-10-29 16:26:48 -070098
James Feiste284a7c2019-11-20 16:20:23 -080099 health->inventory.insert(health->inventory.end(),
100 storageList.begin(),
101 storageList.end());
James Feist2ad9c2f2019-10-29 16:26:48 -0700102
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500103 for (const std::string& objpath : storageList)
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700104 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700105 std::size_t lastPos = objpath.rfind('/');
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700106 if (lastPos == std::string::npos ||
107 (objpath.size() <= lastPos + 1))
108 {
109 BMCWEB_LOG_ERROR << "Failed to find '/' in " << objpath;
110 continue;
111 }
112
113 storageArray.push_back(
114 {{"@odata.id",
James Feistbe13cec2019-10-30 16:38:16 -0700115 "/redfish/v1/Systems/system/Storage/1/Drives/" +
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700116 objpath.substr(lastPos + 1)}});
117 }
118
James Feiste284a7c2019-11-20 16:20:23 -0800119 count = storageArray.size();
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700120 },
121 "xyz.openbmc_project.ObjectMapper",
122 "/xyz/openbmc_project/object_mapper",
123 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
124 "/xyz/openbmc_project/inventory", int32_t(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500125 std::array<const char*, 1>{
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700126 "xyz.openbmc_project.Inventory.Item.Drive"});
James Feiste284a7c2019-11-20 16:20:23 -0800127
128 crow::connections::systemBus->async_method_call(
129 [asyncResp,
130 health](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500131 const crow::openbmc_mapper::GetSubTreeType& subtree) {
James Feiste284a7c2019-11-20 16:20:23 -0800132 if (ec || !subtree.size())
133 {
James Feistd819a422019-11-27 10:36:36 -0800134 // doesn't have to be there
James Feiste284a7c2019-11-20 16:20:23 -0800135 return;
136 }
137
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500138 nlohmann::json& root =
James Feiste284a7c2019-11-20 16:20:23 -0800139 asyncResp->res.jsonValue["StorageControllers"];
140 root = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500141 for (const auto& [path, interfaceDict] : subtree)
James Feiste284a7c2019-11-20 16:20:23 -0800142 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700143 std::size_t lastPos = path.rfind('/');
James Feiste284a7c2019-11-20 16:20:23 -0800144 if (lastPos == std::string::npos ||
145 (path.size() <= lastPos + 1))
146 {
147 BMCWEB_LOG_ERROR << "Failed to find '/' in " << path;
148 return;
149 }
150
151 if (interfaceDict.size() != 1)
152 {
153 BMCWEB_LOG_ERROR << "Connection size "
154 << interfaceDict.size()
155 << ", greater than 1";
156 messages::internalError(asyncResp->res);
157 return;
158 }
159
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500160 const std::string& connectionName =
James Feiste284a7c2019-11-20 16:20:23 -0800161 interfaceDict.front().first;
162
163 size_t index = root.size();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500164 nlohmann::json& storageController =
James Feiste284a7c2019-11-20 16:20:23 -0800165 root.emplace_back(nlohmann::json::object());
166
167 std::string id = path.substr(lastPos + 1);
168
169 storageController["@odata.type"] =
170 "#Storage.v1_7_0.StorageController";
James Feiste284a7c2019-11-20 16:20:23 -0800171 storageController["@odata.id"] =
172 "/redfish/v1/Systems/system/Storage/1"
173 "#/StorageControllers/" +
174 std::to_string(index);
175 storageController["Name"] = id;
176 storageController["MemberId"] = id;
177 storageController["Status"]["State"] = "Enabled";
178
179 crow::connections::systemBus->async_method_call(
Ed Tanous23a21a12020-07-25 04:45:05 +0000180 [asyncResp, index](const boost::system::error_code ec2,
James Feiste284a7c2019-11-20 16:20:23 -0800181 const std::variant<bool> present) {
182 // this interface isn't necessary, only check it if
183 // we get a good return
Ed Tanous23a21a12020-07-25 04:45:05 +0000184 if (ec2)
James Feiste284a7c2019-11-20 16:20:23 -0800185 {
186 return;
187 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500188 const bool* enabled = std::get_if<bool>(&present);
James Feiste284a7c2019-11-20 16:20:23 -0800189 if (enabled == nullptr)
190 {
191 BMCWEB_LOG_DEBUG << "Illegal property present";
192 messages::internalError(asyncResp->res);
193 return;
194 }
195 if (!(*enabled))
196 {
197 asyncResp->res
198 .jsonValue["StorageControllers"][index]
199 ["Status"]["State"] = "Disabled";
200 }
201 },
202 connectionName, path, "org.freedesktop.DBus.Properties",
203 "Get", "xyz.openbmc_project.Inventory.Item", "Present");
204
205 crow::connections::systemBus->async_method_call(
206 [asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000207 index](const boost::system::error_code ec2,
James Feiste284a7c2019-11-20 16:20:23 -0800208 const std::vector<std::pair<
209 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500210 std::variant<bool, std::string, uint64_t>>>&
211 propertiesList) {
Ed Tanous23a21a12020-07-25 04:45:05 +0000212 if (ec2)
James Feiste284a7c2019-11-20 16:20:23 -0800213 {
214 // this interface isn't necessary
215 return;
216 }
217 for (const std::pair<
218 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500219 std::variant<bool, std::string, uint64_t>>&
220 property : propertiesList)
James Feiste284a7c2019-11-20 16:20:23 -0800221 {
222 // Store DBus properties that are also
223 // Redfish properties with same name and a
224 // string value
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500225 const std::string& propertyName =
James Feiste284a7c2019-11-20 16:20:23 -0800226 property.first;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500227 nlohmann::json& object =
James Feiste284a7c2019-11-20 16:20:23 -0800228 asyncResp->res
229 .jsonValue["StorageControllers"][index];
230 if ((propertyName == "PartNumber") ||
231 (propertyName == "SerialNumber") ||
232 (propertyName == "Manufacturer") ||
233 (propertyName == "Model"))
234 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500235 const std::string* value =
James Feiste284a7c2019-11-20 16:20:23 -0800236 std::get_if<std::string>(
237 &property.second);
238 if (value == nullptr)
239 {
240 // illegal property
241 messages::internalError(asyncResp->res);
Chicago Duan601af5e2021-04-15 16:59:25 +0800242 return;
James Feiste284a7c2019-11-20 16:20:23 -0800243 }
244 object[propertyName] = *value;
245 }
246 }
247 },
248 connectionName, path, "org.freedesktop.DBus.Properties",
249 "GetAll",
250 "xyz.openbmc_project.Inventory.Decorator.Asset");
251 }
252
253 // this is done after we know the json array will no longer be
254 // resized, as json::array uses vector underneath and we need
255 // references to its members that won't change
256 size_t count = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500257 for (const auto& [path, interfaceDict] : subtree)
James Feiste284a7c2019-11-20 16:20:23 -0800258 {
259 auto subHealth = std::make_shared<HealthPopulate>(
260 asyncResp, root[count]["Status"]);
261 subHealth->inventory.emplace_back(path);
262 health->inventory.emplace_back(path);
263 health->children.emplace_back(subHealth);
264 count++;
265 }
266 },
267 "xyz.openbmc_project.ObjectMapper",
268 "/xyz/openbmc_project/object_mapper",
269 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
270 "/xyz/openbmc_project/inventory", int32_t(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500271 std::array<const char*, 1>{
James Feiste284a7c2019-11-20 16:20:23 -0800272 "xyz.openbmc_project.Inventory.Item.StorageController"});
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700273 }
274};
275
276class Drive : public Node
277{
278 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700279 Drive(App& app) :
James Feistbe13cec2019-10-30 16:38:16 -0700280 Node(app, "/redfish/v1/Systems/system/Storage/1/Drives/<str>/",
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700281 std::string())
282 {
283 entityPrivileges = {
284 {boost::beast::http::verb::get, {{"Login"}}},
285 {boost::beast::http::verb::head, {{"Login"}}},
286 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
287 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
288 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
289 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
290 }
291
292 private:
zhanghch058d1b46d2021-04-01 11:18:24 +0800293 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
294 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500295 const std::vector<std::string>& params) override
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700296 {
James Feiste284a7c2019-11-20 16:20:23 -0800297 if (params.size() != 1)
298 {
299 messages::internalError(asyncResp->res);
300 return;
301 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500302 const std::string& driveId = params[0];
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700303
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700304 crow::connections::systemBus->async_method_call(
James Feiste284a7c2019-11-20 16:20:23 -0800305 [asyncResp,
306 driveId](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500307 const crow::openbmc_mapper::GetSubTreeType& subtree) {
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700308 if (ec)
309 {
310 BMCWEB_LOG_ERROR << "Drive mapper call error";
311 messages::internalError(asyncResp->res);
312 return;
313 }
314
Ed Tanous23a21a12020-07-25 04:45:05 +0000315 auto object2 = std::find_if(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500316 subtree.begin(), subtree.end(), [&driveId](auto& object) {
317 const std::string& path = object.first;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700318 return boost::ends_with(path, "/" + driveId);
319 });
320
Ed Tanous23a21a12020-07-25 04:45:05 +0000321 if (object2 == subtree.end())
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700322 {
323 messages::resourceNotFound(asyncResp->res, "Drive",
324 driveId);
325 return;
326 }
327
Ed Tanous23a21a12020-07-25 04:45:05 +0000328 const std::string& path = object2->first;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700329 const std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500330 std::pair<std::string, std::vector<std::string>>>&
Ed Tanous23a21a12020-07-25 04:45:05 +0000331 connectionNames = object2->second;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700332
333 asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive";
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700334 asyncResp->res.jsonValue["@odata.id"] =
James Feistbe13cec2019-10-30 16:38:16 -0700335 "/redfish/v1/Systems/system/Storage/1/Drives/" + driveId;
James Feist2ad9c2f2019-10-29 16:26:48 -0700336 asyncResp->res.jsonValue["Name"] = driveId;
337 asyncResp->res.jsonValue["Id"] = driveId;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700338
339 if (connectionNames.size() != 1)
340 {
341 BMCWEB_LOG_ERROR << "Connection size "
342 << connectionNames.size()
343 << ", greater than 1";
344 messages::internalError(asyncResp->res);
345 return;
346 }
347
348 getMainChassisId(
zhanghch058d1b46d2021-04-01 11:18:24 +0800349 asyncResp,
350 [](const std::string& chassisId,
351 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700352 aRsp->res.jsonValue["Links"]["Chassis"] = {
353 {"@odata.id", "/redfish/v1/Chassis/" + chassisId}};
354 });
355
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500356 const std::string& connectionName = connectionNames[0].first;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700357 crow::connections::systemBus->async_method_call(
Ed Tanouscb13a392020-07-25 19:02:03 +0000358 [asyncResp](const boost::system::error_code ec2,
James Feist2ad9c2f2019-10-29 16:26:48 -0700359 const std::vector<std::pair<
360 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500361 std::variant<bool, std::string, uint64_t>>>&
362 propertiesList) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000363 if (ec2)
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700364 {
365 // this interface isn't necessary
366 return;
367 }
368 for (const std::pair<std::string,
369 std::variant<bool, std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500370 uint64_t>>& property :
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700371 propertiesList)
372 {
373 // Store DBus properties that are also
374 // Redfish properties with same name and a
375 // string value
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500376 const std::string& propertyName = property.first;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700377 if ((propertyName == "PartNumber") ||
378 (propertyName == "SerialNumber") ||
379 (propertyName == "Manufacturer") ||
380 (propertyName == "Model"))
381 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500382 const std::string* value =
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700383 std::get_if<std::string>(&property.second);
384 if (value == nullptr)
385 {
386 // illegal property
387 messages::internalError(asyncResp->res);
Chicago Duan601af5e2021-04-15 16:59:25 +0800388 return;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700389 }
390 asyncResp->res.jsonValue[propertyName] = *value;
391 }
392 }
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700393 },
394 connectionName, path, "org.freedesktop.DBus.Properties",
395 "GetAll", "xyz.openbmc_project.Inventory.Decorator.Asset");
396
397 // default it to Enabled
398 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
399
James Feist2ad9c2f2019-10-29 16:26:48 -0700400 auto health = std::make_shared<HealthPopulate>(asyncResp);
James Feiste284a7c2019-11-20 16:20:23 -0800401 health->inventory.emplace_back(path);
James Feist2ad9c2f2019-10-29 16:26:48 -0700402 health->populate();
403
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700404 crow::connections::systemBus->async_method_call(
Ed Tanouscb13a392020-07-25 19:02:03 +0000405 [asyncResp, path](const boost::system::error_code ec2,
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700406 const std::variant<bool> present) {
407 // this interface isn't necessary, only check it if we
408 // get a good return
Ed Tanouscb13a392020-07-25 19:02:03 +0000409 if (ec2)
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700410 {
James Feist2ad9c2f2019-10-29 16:26:48 -0700411 return;
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700412 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500413 const bool* enabled = std::get_if<bool>(&present);
James Feist2ad9c2f2019-10-29 16:26:48 -0700414 if (enabled == nullptr)
415 {
416 BMCWEB_LOG_DEBUG << "Illegal property present";
417 messages::internalError(asyncResp->res);
418 return;
419 }
420 if (!(*enabled))
421 {
422 asyncResp->res.jsonValue["Status"]["State"] =
423 "Disabled";
424 }
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700425 },
426 connectionName, path, "org.freedesktop.DBus.Properties",
427 "Get", "xyz.openbmc_project.Inventory.Item", "Present");
James Feist22984072019-10-21 16:10:49 -0700428
429 crow::connections::systemBus->async_method_call(
Ed Tanouscb13a392020-07-25 19:02:03 +0000430 [asyncResp](const boost::system::error_code ec2,
James Feist22984072019-10-21 16:10:49 -0700431 const std::variant<bool> rebuilding) {
432 // this interface isn't necessary, only check it if we
433 // get a good return
Ed Tanouscb13a392020-07-25 19:02:03 +0000434 if (ec2)
James Feist22984072019-10-21 16:10:49 -0700435 {
436 return;
437 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500438 const bool* updating = std::get_if<bool>(&rebuilding);
James Feist22984072019-10-21 16:10:49 -0700439 if (updating == nullptr)
440 {
441 BMCWEB_LOG_DEBUG << "Illegal property present";
442 messages::internalError(asyncResp->res);
443 return;
444 }
445
446 // updating and disabled in the backend shouldn't be
447 // able to be set at the same time, so we don't need to
448 // check for the race condition of these two calls
449 if ((*updating))
450 {
451 asyncResp->res.jsonValue["Status"]["State"] =
452 "Updating";
453 }
454 },
455 connectionName, path, "org.freedesktop.DBus.Properties",
456 "Get", "xyz.openbmc_project.State.Drive", "Rebuilding");
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700457 },
458 "xyz.openbmc_project.ObjectMapper",
459 "/xyz/openbmc_project/object_mapper",
460 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
461 "/xyz/openbmc_project/inventory", int32_t(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500462 std::array<const char*, 1>{
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700463 "xyz.openbmc_project.Inventory.Item.Drive"});
464 }
465};
466} // namespace redfish