blob: 6b1b38ce89edaf15e53322c66beca031da8908d7 [file] [log] [blame]
Jennifer Lee729dae72018-04-24 15:59:34 -07001/*
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"
Ed Tanous1abe55e2018-09-05 08:30:59 -070019
Jennifer Lee729dae72018-04-24 15:59:34 -070020#include <boost/container/flat_map.hpp>
Andrew Geissler87d84722019-02-28 14:28:39 -060021#include <utils/fw_utils.hpp>
Ed Tanousabf2add2019-01-22 16:40:12 -080022#include <variant>
Jennifer Lee729dae72018-04-24 15:59:34 -070023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024namespace redfish
25{
Ed Tanous27826b52018-10-29 11:40:58 -070026
Andrew Geissler0e7de462019-03-04 19:11:54 -060027// Match signals added on software path
Jennifer Leeacb7cfb2018-06-07 16:08:15 -070028static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher;
Andrew Geissler0e7de462019-03-04 19:11:54 -060029// Only allow one update at a time
30static bool fwUpdateInProgress = false;
Andrew Geissler86adcd62019-04-18 10:58:05 -050031// Timer for software available
32static std::unique_ptr<boost::asio::deadline_timer> fwAvailableTimer;
33
34static void cleanUp()
35{
36 fwUpdateInProgress = false;
37 fwUpdateMatcher = nullptr;
38}
39static void activateImage(const std::string &objPath,
40 const std::string &service)
41{
42 BMCWEB_LOG_DEBUG << "Activate image for " << objPath << " " << service;
43 crow::connections::systemBus->async_method_call(
44 [](const boost::system::error_code error_code) {
45 if (error_code)
46 {
47 BMCWEB_LOG_DEBUG << "error_code = " << error_code;
48 BMCWEB_LOG_DEBUG << "error msg = " << error_code.message();
49 }
50 },
51 service, objPath, "org.freedesktop.DBus.Properties", "Set",
52 "xyz.openbmc_project.Software.Activation", "RequestedActivation",
53 std::variant<std::string>(
54 "xyz.openbmc_project.Software.Activation.RequestedActivations."
55 "Active"));
56}
57static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp,
58 sdbusplus::message::message &m)
59{
60 std::vector<std::pair<
61 std::string,
62 std::vector<std::pair<std::string, std::variant<std::string>>>>>
63 interfacesProperties;
64
65 sdbusplus::message::object_path objPath;
66
67 m.read(objPath, interfacesProperties);
68
69 BMCWEB_LOG_DEBUG << "obj path = " << objPath.str;
70 for (auto &interface : interfacesProperties)
71 {
72 BMCWEB_LOG_DEBUG << "interface = " << interface.first;
73
74 if (interface.first == "xyz.openbmc_project.Software.Activation")
75 {
76 // Found our interface, disable callbacks
77 fwUpdateMatcher = nullptr;
78
79 // Retrieve service and activate
80 crow::connections::systemBus->async_method_call(
81 [objPath, asyncResp](
82 const boost::system::error_code error_code,
83 const std::vector<std::pair<
84 std::string, std::vector<std::string>>> &objInfo) {
85 if (error_code)
86 {
87 BMCWEB_LOG_DEBUG << "error_code = " << error_code;
88 BMCWEB_LOG_DEBUG << "error msg = "
89 << error_code.message();
90 messages::internalError(asyncResp->res);
91 cleanUp();
92 return;
93 }
94 // Ensure we only got one service back
95 if (objInfo.size() != 1)
96 {
97 BMCWEB_LOG_ERROR << "Invalid Object Size "
98 << objInfo.size();
99 messages::internalError(asyncResp->res);
100 cleanUp();
101 return;
102 }
103 // cancel timer only when
104 // xyz.openbmc_project.Software.Activation interface
105 // is added
106 fwAvailableTimer = nullptr;
107
108 activateImage(objPath.str, objInfo[0].first);
109 redfish::messages::success(asyncResp->res);
110 fwUpdateInProgress = false;
111 },
112 "xyz.openbmc_project.ObjectMapper",
113 "/xyz/openbmc_project/object_mapper",
114 "xyz.openbmc_project.ObjectMapper", "GetObject", objPath.str,
115 std::array<const char *, 1>{
116 "xyz.openbmc_project.Software.Activation"});
117 }
118 }
119}
120
121static void monitorForSoftwareAvailable(std::shared_ptr<AsyncResp> asyncResp,
122 const crow::Request &req)
123{
124 // Only allow one FW update at a time
125 if (fwUpdateInProgress != false)
126 {
127 asyncResp->res.addHeader("Retry-After", "30");
128 messages::serviceTemporarilyUnavailable(asyncResp->res, "30");
129 return;
130 }
131
132 fwAvailableTimer = std::make_unique<boost::asio::deadline_timer>(
133 *req.ioService, boost::posix_time::seconds(5));
134
135 fwAvailableTimer->expires_from_now(boost::posix_time::seconds(5));
136
137 fwAvailableTimer->async_wait(
138 [asyncResp](const boost::system::error_code &ec) {
139 cleanUp();
140 if (ec == boost::asio::error::operation_aborted)
141 {
142 // expected, we were canceled before the timer completed.
143 return;
144 }
145 BMCWEB_LOG_ERROR
146 << "Timed out waiting for firmware object being created";
147 BMCWEB_LOG_ERROR
148 << "FW image may has already been uploaded to server";
149 if (ec)
150 {
151 BMCWEB_LOG_ERROR << "Async_wait failed" << ec;
152 return;
153 }
154
155 redfish::messages::internalError(asyncResp->res);
156 });
157
158 auto callback = [asyncResp](sdbusplus::message::message &m) {
159 BMCWEB_LOG_DEBUG << "Match fired";
160 softwareInterfaceAdded(asyncResp, m);
161 };
162
163 fwUpdateInProgress = true;
164
165 fwUpdateMatcher = std::make_unique<sdbusplus::bus::match::match>(
166 *crow::connections::systemBus,
167 "interface='org.freedesktop.DBus.ObjectManager',type='signal',"
168 "member='InterfacesAdded',path='/xyz/openbmc_project/software'",
169 callback);
170}
Jennifer Lee729dae72018-04-24 15:59:34 -0700171
Ed Tanous1abe55e2018-09-05 08:30:59 -0700172class UpdateService : public Node
173{
174 public:
175 UpdateService(CrowApp &app) : Node(app, "/redfish/v1/UpdateService/")
176 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700177 entityPrivileges = {
178 {boost::beast::http::verb::get, {{"Login"}}},
179 {boost::beast::http::verb::head, {{"Login"}}},
180 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
181 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
182 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
183 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700184 }
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700185
Ed Tanous1abe55e2018-09-05 08:30:59 -0700186 private:
187 void doGet(crow::Response &res, const crow::Request &req,
188 const std::vector<std::string> &params) override
189 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800190 res.jsonValue["@odata.type"] = "#UpdateService.v1_2_0.UpdateService";
191 res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService";
192 res.jsonValue["@odata.context"] =
193 "/redfish/v1/$metadata#UpdateService.UpdateService";
194 res.jsonValue["Id"] = "UpdateService";
195 res.jsonValue["Description"] = "Service for Software Update";
196 res.jsonValue["Name"] = "Update Service";
197 res.jsonValue["HttpPushUri"] = "/redfish/v1/UpdateService";
198 // UpdateService cannot be disabled
199 res.jsonValue["ServiceEnabled"] = true;
200 res.jsonValue["FirmwareInventory"] = {
201 {"@odata.id", "/redfish/v1/UpdateService/FirmwareInventory"}};
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700202 res.end();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700203 }
Andrew Geissler0e7de462019-03-04 19:11:54 -0600204
Ed Tanous1abe55e2018-09-05 08:30:59 -0700205 void doPost(crow::Response &res, const crow::Request &req,
206 const std::vector<std::string> &params) override
207 {
208 BMCWEB_LOG_DEBUG << "doPost...";
Jennifer Leeacb7cfb2018-06-07 16:08:15 -0700209
Andrew Geissler0e7de462019-03-04 19:11:54 -0600210 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700211
Andrew Geissler86adcd62019-04-18 10:58:05 -0500212 // Setup callback for when new software detected
213 monitorForSoftwareAvailable(asyncResp, req);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700214
215 std::string filepath(
216 "/tmp/images/" +
217 boost::uuids::to_string(boost::uuids::random_generator()()));
218 BMCWEB_LOG_DEBUG << "Writing file to " << filepath;
219 std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
220 std::ofstream::trunc);
221 out << req.body;
222 out.close();
223 BMCWEB_LOG_DEBUG << "file upload complete!!";
224 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700225};
Ed Tanousc711bf82018-07-30 16:31:33 -0700226
Ed Tanous1abe55e2018-09-05 08:30:59 -0700227class SoftwareInventoryCollection : public Node
228{
229 public:
230 template <typename CrowApp>
231 SoftwareInventoryCollection(CrowApp &app) :
232 Node(app, "/redfish/v1/UpdateService/FirmwareInventory/")
233 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700234 entityPrivileges = {
235 {boost::beast::http::verb::get, {{"Login"}}},
236 {boost::beast::http::verb::head, {{"Login"}}},
237 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
238 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
239 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
240 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Jennifer Lee729dae72018-04-24 15:59:34 -0700241 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700242
Ed Tanous1abe55e2018-09-05 08:30:59 -0700243 private:
244 void doGet(crow::Response &res, const crow::Request &req,
245 const std::vector<std::string> &params) override
246 {
247 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous0f74e642018-11-12 15:17:05 -0800248 res.jsonValue["@odata.type"] =
249 "#SoftwareInventoryCollection.SoftwareInventoryCollection";
250 res.jsonValue["@odata.id"] =
251 "/redfish/v1/UpdateService/FirmwareInventory";
252 res.jsonValue["@odata.context"] =
253 "/redfish/v1/"
254 "$metadata#SoftwareInventoryCollection.SoftwareInventoryCollection";
255 res.jsonValue["Name"] = "Software Inventory Collection";
Ed Tanousc711bf82018-07-30 16:31:33 -0700256
Ed Tanous1abe55e2018-09-05 08:30:59 -0700257 crow::connections::systemBus->async_method_call(
258 [asyncResp](
259 const boost::system::error_code ec,
260 const std::vector<std::pair<
261 std::string, std::vector<std::pair<
262 std::string, std::vector<std::string>>>>>
263 &subtree) {
264 if (ec)
265 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700266 messages::internalError(asyncResp->res);
Ed Tanousc711bf82018-07-30 16:31:33 -0700267 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700268 }
269 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
270 asyncResp->res.jsonValue["Members@odata.count"] = 0;
Jennifer Lee6c4eb9d2018-05-22 10:58:31 -0700271
Ed Tanous1abe55e2018-09-05 08:30:59 -0700272 for (auto &obj : subtree)
273 {
274 const std::vector<
275 std::pair<std::string, std::vector<std::string>>>
276 &connections = obj.second;
277
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700278 // if can't parse fw id then return
Ed Tanous27826b52018-10-29 11:40:58 -0700279 std::size_t idPos;
280 if ((idPos = obj.first.rfind("/")) == std::string::npos)
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700281 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700282 messages::internalError(asyncResp->res);
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700283 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
284 return;
285 }
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700286 std::string swId = obj.first.substr(idPos + 1);
287
Ed Tanous1abe55e2018-09-05 08:30:59 -0700288 for (auto &conn : connections)
289 {
290 const std::string &connectionName = conn.first;
291 BMCWEB_LOG_DEBUG << "connectionName = "
292 << connectionName;
293 BMCWEB_LOG_DEBUG << "obj.first = " << obj.first;
294
295 crow::connections::systemBus->async_method_call(
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700296 [asyncResp,
297 swId](const boost::system::error_code error_code,
298 const VariantType &activation) {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700299 BMCWEB_LOG_DEBUG
300 << "safe returned in lambda function";
301 if (error_code)
302 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700303 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700304 return;
305 }
306
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700307 const std::string *swActivationStatus =
Ed Tanousabf2add2019-01-22 16:40:12 -0800308 std::get_if<std::string>(&activation);
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700309 if (swActivationStatus == nullptr)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700310 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700311 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700312 return;
313 }
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700314 if (swActivationStatus != nullptr &&
315 *swActivationStatus !=
316 "xyz.openbmc_project.Software."
317 "Activation."
318 "Activations.Active")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700319 {
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700320 // The activation status of this software is
321 // not currently active, so does not need to
322 // be listed in the response
Ed Tanous1abe55e2018-09-05 08:30:59 -0700323 return;
324 }
325 nlohmann::json &members =
326 asyncResp->res.jsonValue["Members"];
327 members.push_back(
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700328 {{"@odata.id", "/redfish/v1/UpdateService/"
329 "FirmwareInventory/" +
330 swId}});
Ed Tanous1abe55e2018-09-05 08:30:59 -0700331 asyncResp->res
332 .jsonValue["Members@odata.count"] =
333 members.size();
334 },
335 connectionName, obj.first,
336 "org.freedesktop.DBus.Properties", "Get",
337 "xyz.openbmc_project.Software.Activation",
338 "Activation");
Ed Tanousc711bf82018-07-30 16:31:33 -0700339 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700340 }
341 },
342 "xyz.openbmc_project.ObjectMapper",
343 "/xyz/openbmc_project/object_mapper",
344 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
345 "/xyz/openbmc_project/software", int32_t(1),
346 std::array<const char *, 1>{
347 "xyz.openbmc_project.Software.Version"});
348 }
Jennifer Lee729dae72018-04-24 15:59:34 -0700349};
350
Ed Tanous1abe55e2018-09-05 08:30:59 -0700351class SoftwareInventory : public Node
352{
353 public:
354 template <typename CrowApp>
355 SoftwareInventory(CrowApp &app) :
356 Node(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/",
357 std::string())
358 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700359 entityPrivileges = {
360 {boost::beast::http::verb::get, {{"Login"}}},
361 {boost::beast::http::verb::head, {{"Login"}}},
362 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
363 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
364 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
365 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
366 }
367
368 private:
Andrew Geissler87d84722019-02-28 14:28:39 -0600369 /* Fill related item links (i.e. bmc, bios) in for inventory */
370 static void getRelatedItems(std::shared_ptr<AsyncResp> aResp,
371 const std::string &purpose)
372 {
373 if (purpose == fw_util::bmcPurpose)
374 {
375 nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
376 members.push_back({{"@odata.id", "/redfish/v1/Managers/bmc"}});
377 aResp->res.jsonValue["Members@odata.count"] = members.size();
378 }
379 else if (purpose == fw_util::biosPurpose)
380 {
381 // TODO(geissonator) Need BIOS schema support added for this
382 // to be valid
383 // nlohmann::json &members = aResp->res.jsonValue["RelatedItem"];
384 // members.push_back(
385 // {{"@odata.id", "/redfish/v1/Systems/system/BIOS"}});
386 // aResp->res.jsonValue["Members@odata.count"] = members.size();
387 }
388 else
389 {
390 BMCWEB_LOG_ERROR << "Unknown software purpose " << purpose;
391 }
392 }
393
Ed Tanous1abe55e2018-09-05 08:30:59 -0700394 void doGet(crow::Response &res, const crow::Request &req,
395 const std::vector<std::string> &params) override
396 {
397 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous0f74e642018-11-12 15:17:05 -0800398 res.jsonValue["@odata.type"] =
399 "#SoftwareInventory.v1_1_0.SoftwareInventory";
400 res.jsonValue["@odata.context"] =
401 "/redfish/v1/$metadata#SoftwareInventory.SoftwareInventory";
402 res.jsonValue["Name"] = "Software Inventory";
403 res.jsonValue["Updateable"] = false;
404 res.jsonValue["Status"]["Health"] = "OK";
405 res.jsonValue["Status"]["HealthRollup"] = "OK";
406 res.jsonValue["Status"]["State"] = "Enabled";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700407
408 if (params.size() != 1)
409 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700410 messages::internalError(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700411 res.end();
412 return;
413 }
414
Ed Tanous3ae837c2018-08-07 14:41:19 -0700415 std::shared_ptr<std::string> swId =
Ed Tanous1abe55e2018-09-05 08:30:59 -0700416 std::make_shared<std::string>(params[0]);
417
418 res.jsonValue["@odata.id"] =
Ed Tanous3ae837c2018-08-07 14:41:19 -0700419 "/redfish/v1/UpdateService/FirmwareInventory/" + *swId;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700420
421 crow::connections::systemBus->async_method_call(
Ed Tanous3ae837c2018-08-07 14:41:19 -0700422 [asyncResp, swId](
Ed Tanous1abe55e2018-09-05 08:30:59 -0700423 const boost::system::error_code ec,
424 const std::vector<std::pair<
425 std::string, std::vector<std::pair<
426 std::string, std::vector<std::string>>>>>
427 &subtree) {
428 BMCWEB_LOG_DEBUG << "doGet callback...";
429 if (ec)
430 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700431 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700432 return;
433 }
434
435 for (const std::pair<
436 std::string,
437 std::vector<
438 std::pair<std::string, std::vector<std::string>>>>
439 &obj : subtree)
440 {
Ed Tanous3ae837c2018-08-07 14:41:19 -0700441 if (boost::ends_with(obj.first, *swId) != true)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700442 {
443 continue;
444 }
445
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700446 if (obj.second.size() < 1)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700447 {
448 continue;
449 }
450
451 crow::connections::systemBus->async_method_call(
452 [asyncResp,
Ed Tanous3ae837c2018-08-07 14:41:19 -0700453 swId](const boost::system::error_code error_code,
454 const boost::container::flat_map<
455 std::string, VariantType> &propertiesList) {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700456 if (error_code)
457 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700458 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700459 return;
460 }
461 boost::container::flat_map<
462 std::string, VariantType>::const_iterator it =
463 propertiesList.find("Purpose");
464 if (it == propertiesList.end())
465 {
466 BMCWEB_LOG_DEBUG
467 << "Can't find property \"Purpose\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700468 messages::propertyMissing(asyncResp->res,
469 "Purpose");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700470 return;
471 }
Ed Tanous3ae837c2018-08-07 14:41:19 -0700472 const std::string *swInvPurpose =
Ed Tanousabf2add2019-01-22 16:40:12 -0800473 std::get_if<std::string>(&it->second);
Ed Tanous3ae837c2018-08-07 14:41:19 -0700474 if (swInvPurpose == nullptr)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700475 {
476 BMCWEB_LOG_DEBUG
477 << "wrong types for property\"Purpose\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700478 messages::propertyValueTypeError(asyncResp->res,
479 "", "Purpose");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700480 return;
481 }
482
Ed Tanous3ae837c2018-08-07 14:41:19 -0700483 BMCWEB_LOG_DEBUG << "swInvPurpose = "
484 << *swInvPurpose;
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700485 it = propertiesList.find("Version");
486 if (it == propertiesList.end())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700487 {
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700488 BMCWEB_LOG_DEBUG
489 << "Can't find property \"Version\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700490 messages::propertyMissing(asyncResp->res,
491 "Version");
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700492 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700493 }
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700494
495 BMCWEB_LOG_DEBUG << "Version found!";
496
497 const std::string *version =
Ed Tanousabf2add2019-01-22 16:40:12 -0800498 std::get_if<std::string>(&it->second);
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700499
500 if (version == nullptr)
501 {
502 BMCWEB_LOG_DEBUG
503 << "Can't find property \"Version\"!";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700504
505 messages::propertyValueTypeError(asyncResp->res,
506 "", "Version");
Jennifer Leef4b65ab2018-09-18 12:00:13 -0700507 return;
508 }
509 asyncResp->res.jsonValue["Version"] = *version;
510 asyncResp->res.jsonValue["Id"] = *swId;
Andrew Geissler54daabe2019-02-13 13:54:15 -0600511
512 // swInvPurpose is of format:
513 // xyz.openbmc_project.Software.Version.VersionPurpose.ABC
514 // Translate this to "ABC update"
515 size_t endDesc = swInvPurpose->rfind(".");
516 if (endDesc == std::string::npos)
517 {
518 messages::internalError(asyncResp->res);
519 return;
520 }
521 endDesc++;
522 if (endDesc >= swInvPurpose->size())
523 {
524 messages::internalError(asyncResp->res);
525 return;
526 }
527
528 std::string formatDesc =
529 swInvPurpose->substr(endDesc);
530 asyncResp->res.jsonValue["Description"] =
531 formatDesc + " update";
Andrew Geissler87d84722019-02-28 14:28:39 -0600532 getRelatedItems(asyncResp, *swInvPurpose);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700533 },
534 obj.second[0].first, obj.first,
535 "org.freedesktop.DBus.Properties", "GetAll",
536 "xyz.openbmc_project.Software.Version");
537 }
538 },
539 "xyz.openbmc_project.ObjectMapper",
540 "/xyz/openbmc_project/object_mapper",
541 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
542 "/xyz/openbmc_project/software", int32_t(1),
543 std::array<const char *, 1>{
544 "xyz.openbmc_project.Software.Version"});
545 }
546};
547
548} // namespace redfish