Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | #include "led.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 20 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 21 | #include <app.hpp> |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 22 | #include <dbus_utility.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 23 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 24 | #include <registries/privilege_registry.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/property.hpp> |
Gunnar Mills | 02f6ff1 | 2020-10-14 15:59:58 -0500 | [diff] [blame] | 26 | #include <utils/collection.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 27 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | namespace redfish |
| 29 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 32 | * @brief Retrieves chassis state properties over dbus |
| 33 | * |
| 34 | * @param[in] aResp - Shared pointer for completing asynchronous calls. |
| 35 | * |
| 36 | * @return None. |
| 37 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 38 | inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 39 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 40 | // crow::connections::systemBus->async_method_call( |
| 41 | sdbusplus::asio::getProperty<std::string>( |
| 42 | *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", |
| 43 | "/xyz/openbmc_project/state/chassis0", |
| 44 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState", |
| 45 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
| 46 | const std::string& chassisState) { |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 47 | if (ec) |
| 48 | { |
Carson Labrado | a6e5e0a | 2022-02-15 00:26:03 +0000 | [diff] [blame] | 49 | if (ec == boost::system::errc::host_unreachable) |
| 50 | { |
| 51 | // Service not available, no error, just don't return |
| 52 | // chassis state info |
| 53 | BMCWEB_LOG_DEBUG << "Service not available " << ec; |
| 54 | return; |
| 55 | } |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 56 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 57 | messages::internalError(aResp->res); |
| 58 | return; |
| 59 | } |
| 60 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 61 | BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState; |
| 62 | // Verify Chassis State |
| 63 | if (chassisState == |
| 64 | "xyz.openbmc_project.State.Chassis.PowerState.On") |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 65 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 66 | aResp->res.jsonValue["PowerState"] = "On"; |
| 67 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 68 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 69 | else if (chassisState == |
| 70 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 71 | { |
| 72 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 73 | aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
| 74 | } |
| 75 | }); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 76 | } |
| 77 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 78 | inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 79 | const std::string& service, |
| 80 | const std::string& objPath) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 81 | { |
| 82 | BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; |
| 83 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 84 | sdbusplus::asio::getProperty<std::string>( |
| 85 | *crow::connections::systemBus, service, objPath, |
| 86 | "xyz.openbmc_project.Chassis.Intrusion", "Status", |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 87 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 88 | const std::string& value) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 89 | if (ec) |
| 90 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 91 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 92 | // mandatory property |
| 93 | BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; |
| 94 | return; |
| 95 | } |
| 96 | |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 97 | aResp->res.jsonValue["PhysicalSecurity"] = { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 98 | {"IntrusionSensorNumber", 1}, {"IntrusionSensor", value}}; |
| 99 | }); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Retrieves physical security properties over dbus |
| 104 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 105 | inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 106 | { |
| 107 | crow::connections::systemBus->async_method_call( |
| 108 | [aResp{std::move(aResp)}]( |
| 109 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 110 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 111 | if (ec) |
| 112 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 113 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 114 | // mandatory property |
Andrew Geissler | 54fbf17 | 2021-11-11 15:59:30 -0600 | [diff] [blame] | 115 | BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec |
| 116 | << "\n"; |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | // Iterate over all retrieved ObjectPaths. |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 120 | for (const auto& object : subtree) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 121 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 122 | for (const auto& service : object.second) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 123 | { |
| 124 | getIntrusionByService(aResp, service.first, object.first); |
| 125 | return; |
| 126 | } |
| 127 | } |
| 128 | }, |
| 129 | "xyz.openbmc_project.ObjectMapper", |
| 130 | "/xyz/openbmc_project/object_mapper", |
| 131 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 132 | "/xyz/openbmc_project/Intrusion", 1, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 133 | std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 134 | } |
| 135 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 136 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 137 | * ChassisCollection derived class for delivering Chassis Collection Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 138 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 139 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 140 | inline void requestRoutesChassisCollection(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 141 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 142 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 143 | .privileges(redfish::privileges::getChassisCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 144 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 145 | [&app](const crow::Request& req, |
| 146 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| 147 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 148 | { |
| 149 | return; |
| 150 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 151 | asyncResp->res.jsonValue["@odata.type"] = |
| 152 | "#ChassisCollection.ChassisCollection"; |
| 153 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
| 154 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 155 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 156 | collection_util::getCollectionMembers( |
| 157 | asyncResp, "/redfish/v1/Chassis", |
| 158 | {"xyz.openbmc_project.Inventory.Item.Board", |
| 159 | "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| 160 | }); |
| 161 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 162 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 163 | inline void |
| 164 | getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 165 | const std::string& connectionName, |
| 166 | const std::string& path) |
| 167 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 168 | sdbusplus::asio::getProperty<std::string>( |
| 169 | *crow::connections::systemBus, connectionName, path, |
| 170 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 171 | [asyncResp](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 172 | const std::string& property) { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 173 | if (ec) |
| 174 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 175 | BMCWEB_LOG_DEBUG << "DBUS response error for Location"; |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 176 | messages::internalError(asyncResp->res); |
| 177 | return; |
| 178 | } |
| 179 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 180 | asyncResp->res |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 181 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 182 | property; |
| 183 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 187 | const std::string& connectionName, |
| 188 | const std::string& path) |
| 189 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 190 | sdbusplus::asio::getProperty<std::string>( |
| 191 | *crow::connections::systemBus, connectionName, path, |
| 192 | "xyz.openbmc_project.Common.UUID", "UUID", |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 193 | [asyncResp](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 194 | const std::string& chassisUUID) { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 195 | if (ec) |
| 196 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 197 | BMCWEB_LOG_DEBUG << "DBUS response error for UUID"; |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 198 | messages::internalError(asyncResp->res); |
| 199 | return; |
| 200 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 201 | asyncResp->res.jsonValue["UUID"] = chassisUUID; |
| 202 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 205 | /** |
| 206 | * Chassis override class for delivering Chassis Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 207 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 208 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 209 | inline void requestRoutesChassis(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 210 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 211 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 212 | .privileges(redfish::privileges::getChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 213 | .methods( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 214 | boost::beast::http::verb:: |
| 215 | get)([&app](const crow::Request& req, |
| 216 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 217 | const std::string& chassisId) { |
| 218 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 219 | { |
| 220 | return; |
| 221 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 222 | const std::array<const char*, 2> interfaces = { |
| 223 | "xyz.openbmc_project.Inventory.Item.Board", |
| 224 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 225 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 226 | crow::connections::systemBus->async_method_call( |
| 227 | [asyncResp, chassisId(std::string(chassisId))]( |
| 228 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 229 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 230 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 231 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 232 | messages::internalError(asyncResp->res); |
| 233 | return; |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 234 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 235 | // Iterate over all retrieved ObjectPaths. |
| 236 | for (const std::pair< |
| 237 | std::string, |
| 238 | std::vector<std::pair<std::string, |
| 239 | std::vector<std::string>>>>& |
| 240 | object : subtree) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 241 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 242 | const std::string& path = object.first; |
| 243 | const std::vector< |
| 244 | std::pair<std::string, std::vector<std::string>>>& |
| 245 | connectionNames = object.second; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 246 | |
George Liu | 997093e | 2021-11-17 17:43:45 +0800 | [diff] [blame] | 247 | sdbusplus::message::object_path objPath(path); |
| 248 | if (objPath.filename() != chassisId) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 249 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 250 | continue; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 251 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 252 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 253 | auto health = |
| 254 | std::make_shared<HealthPopulate>(asyncResp); |
| 255 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 256 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 257 | *crow::connections::systemBus, |
| 258 | "xyz.openbmc_project.ObjectMapper", |
| 259 | path + "/all_sensors", |
| 260 | "xyz.openbmc_project.Association", "endpoints", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 261 | [health](const boost::system::error_code ec2, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 262 | const std::vector<std::string>& resp) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 263 | if (ec2) |
| 264 | { |
| 265 | return; // no sensors = no failures |
| 266 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 267 | health->inventory = resp; |
| 268 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 269 | |
| 270 | health->populate(); |
| 271 | |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 272 | if (connectionNames.empty()) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 273 | { |
| 274 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | asyncResp->res.jsonValue["@odata.type"] = |
Gunnar Mills | 5ac5a2f | 2022-01-04 12:26:41 -0600 | [diff] [blame] | 279 | "#Chassis.v1_16_0.Chassis"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 280 | asyncResp->res.jsonValue["@odata.id"] = |
| 281 | "/redfish/v1/Chassis/" + chassisId; |
| 282 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 283 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
| 284 | asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = |
| 285 | {{"target", "/redfish/v1/Chassis/" + chassisId + |
| 286 | "/Actions/Chassis.Reset"}, |
| 287 | {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + |
| 288 | chassisId + |
| 289 | "/ResetActionInfo"}}; |
| 290 | asyncResp->res.jsonValue["PCIeDevices"] = { |
| 291 | {"@odata.id", |
| 292 | "/redfish/v1/Systems/system/PCIeDevices"}}; |
| 293 | |
| 294 | const std::string& connectionName = |
| 295 | connectionNames[0].first; |
| 296 | |
| 297 | const std::vector<std::string>& interfaces2 = |
| 298 | connectionNames[0].second; |
| 299 | const std::array<const char*, 2> hasIndicatorLed = { |
| 300 | "xyz.openbmc_project.Inventory.Item.Panel", |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 301 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 302 | |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 303 | const std::string assetTagInterface = |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 304 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 305 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 306 | assetTagInterface) != interfaces2.end()) |
| 307 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 308 | sdbusplus::asio::getProperty<std::string>( |
| 309 | *crow::connections::systemBus, connectionName, |
| 310 | path, assetTagInterface, "AssetTag", |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 311 | [asyncResp, chassisId(std::string(chassisId))]( |
| 312 | const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 313 | const std::string& property) { |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 314 | if (ec) |
| 315 | { |
| 316 | BMCWEB_LOG_DEBUG |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 317 | << "DBus response error for AssetTag"; |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 318 | messages::internalError(asyncResp->res); |
| 319 | return; |
| 320 | } |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 321 | asyncResp->res.jsonValue["AssetTag"] = |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 322 | property; |
| 323 | }); |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 324 | } |
| 325 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 326 | for (const char* interface : hasIndicatorLed) |
| 327 | { |
| 328 | if (std::find(interfaces2.begin(), |
| 329 | interfaces2.end(), |
| 330 | interface) != interfaces2.end()) |
| 331 | { |
| 332 | getIndicatorLedState(asyncResp); |
| 333 | getLocationIndicatorActive(asyncResp); |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 338 | crow::connections::systemBus->async_method_call( |
| 339 | [asyncResp, chassisId(std::string(chassisId))]( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 340 | const boost::system::error_code /*ec2*/, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 341 | const dbus::utility::DBusPropertiesMap& |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 342 | propertiesList) { |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 343 | for (const std::pair< |
| 344 | std::string, |
| 345 | dbus::utility::DbusVariantType>& |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 346 | property : propertiesList) |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 347 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 348 | // Store DBus properties that are also |
| 349 | // Redfish properties with same name and a |
| 350 | // string value |
| 351 | const std::string& propertyName = |
| 352 | property.first; |
| 353 | if ((propertyName == "PartNumber") || |
| 354 | (propertyName == "SerialNumber") || |
| 355 | (propertyName == "Manufacturer") || |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 356 | (propertyName == "Model") || |
| 357 | (propertyName == "SparePartNumber")) |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 358 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 359 | const std::string* value = |
| 360 | std::get_if<std::string>( |
| 361 | &property.second); |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 362 | if (value == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 363 | { |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 364 | BMCWEB_LOG_ERROR |
| 365 | << "Null value returned for " |
| 366 | << propertyName; |
| 367 | messages::internalError( |
| 368 | asyncResp->res); |
| 369 | return; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 370 | } |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 371 | // SparePartNumber is optional on D-Bus |
| 372 | // so skip if it is empty |
| 373 | if (propertyName == "SparePartNumber") |
| 374 | { |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 375 | if (value->empty()) |
Alpana Kumari | caa11f7 | 2021-11-09 12:16:18 -0600 | [diff] [blame] | 376 | { |
| 377 | continue; |
| 378 | } |
| 379 | } |
| 380 | asyncResp->res.jsonValue[propertyName] = |
| 381 | *value; |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 382 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 383 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 384 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 385 | asyncResp->res.jsonValue["Id"] = chassisId; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 386 | #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 387 | asyncResp->res.jsonValue["Thermal"] = { |
| 388 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 389 | chassisId + "/Thermal"}}; |
| 390 | // Power object |
| 391 | asyncResp->res.jsonValue["Power"] = { |
| 392 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 393 | chassisId + "/Power"}}; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 394 | #endif |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 395 | // SensorCollection |
| 396 | asyncResp->res.jsonValue["Sensors"] = { |
| 397 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 398 | chassisId + "/Sensors"}}; |
| 399 | asyncResp->res.jsonValue["Status"] = { |
| 400 | {"State", "Enabled"}, |
| 401 | }; |
| 402 | |
| 403 | asyncResp->res |
| 404 | .jsonValue["Links"]["ComputerSystems"] = { |
| 405 | {{"@odata.id", |
| 406 | "/redfish/v1/Systems/system"}}}; |
| 407 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = |
| 408 | {{{"@odata.id", |
| 409 | "/redfish/v1/Managers/bmc"}}}; |
| 410 | getChassisState(asyncResp); |
| 411 | }, |
| 412 | connectionName, path, |
| 413 | "org.freedesktop.DBus.Properties", "GetAll", |
| 414 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 415 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 416 | for (const auto& interface : interfaces2) |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 417 | { |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 418 | if (interface == "xyz.openbmc_project.Common.UUID") |
| 419 | { |
| 420 | getChassisUUID(asyncResp, connectionName, path); |
| 421 | } |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 422 | else if ( |
| 423 | interface == |
| 424 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 425 | { |
| 426 | getChassisLocationCode(asyncResp, |
| 427 | connectionName, path); |
| 428 | } |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 429 | } |
| 430 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | // Couldn't find an object with that name. return an error |
| 435 | messages::resourceNotFound( |
Gunnar Mills | 5ac5a2f | 2022-01-04 12:26:41 -0600 | [diff] [blame] | 436 | asyncResp->res, "#Chassis.v1_16_0.Chassis", chassisId); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 437 | }, |
| 438 | "xyz.openbmc_project.ObjectMapper", |
| 439 | "/xyz/openbmc_project/object_mapper", |
| 440 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 441 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 442 | |
| 443 | getPhysicalSecurityData(asyncResp); |
| 444 | }); |
| 445 | |
| 446 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 447 | .privileges(redfish::privileges::patchChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 448 | .methods( |
| 449 | boost::beast::http::verb:: |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 450 | patch)([&app]( |
| 451 | const crow::Request& req, |
| 452 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 453 | const std::string& param) { |
| 454 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 455 | { |
| 456 | return; |
| 457 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 458 | std::optional<bool> locationIndicatorActive; |
| 459 | std::optional<std::string> indicatorLed; |
| 460 | |
| 461 | if (param.empty()) |
| 462 | { |
| 463 | return; |
| 464 | } |
| 465 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 466 | if (!json_util::readJsonPatch( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 467 | req, asyncResp->res, "LocationIndicatorActive", |
| 468 | locationIndicatorActive, "IndicatorLED", indicatorLed)) |
| 469 | { |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
| 474 | if (!locationIndicatorActive && !indicatorLed) |
| 475 | { |
| 476 | return; // delete this when we support more patch properties |
| 477 | } |
| 478 | if (indicatorLed) |
| 479 | { |
| 480 | asyncResp->res.addHeader( |
| 481 | boost::beast::http::field::warning, |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 482 | "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | const std::array<const char*, 2> interfaces = { |
| 486 | "xyz.openbmc_project.Inventory.Item.Board", |
| 487 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 488 | |
| 489 | const std::string& chassisId = param; |
| 490 | |
| 491 | crow::connections::systemBus->async_method_call( |
| 492 | [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( |
| 493 | const boost::system::error_code ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 494 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 495 | if (ec) |
| 496 | { |
| 497 | messages::internalError(asyncResp->res); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | // Iterate over all retrieved ObjectPaths. |
| 502 | for (const std::pair< |
| 503 | std::string, |
| 504 | std::vector<std::pair<std::string, |
| 505 | std::vector<std::string>>>>& |
| 506 | object : subtree) |
| 507 | { |
| 508 | const std::string& path = object.first; |
| 509 | const std::vector< |
| 510 | std::pair<std::string, std::vector<std::string>>>& |
| 511 | connectionNames = object.second; |
| 512 | |
George Liu | 997093e | 2021-11-17 17:43:45 +0800 | [diff] [blame] | 513 | sdbusplus::message::object_path objPath(path); |
| 514 | if (objPath.filename() != chassisId) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 515 | { |
| 516 | continue; |
| 517 | } |
| 518 | |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 519 | if (connectionNames.empty()) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 520 | { |
| 521 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 522 | continue; |
| 523 | } |
| 524 | |
| 525 | const std::vector<std::string>& interfaces3 = |
| 526 | connectionNames[0].second; |
| 527 | |
| 528 | const std::array<const char*, 2> hasIndicatorLed = { |
| 529 | "xyz.openbmc_project.Inventory.Item.Panel", |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 530 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 531 | bool indicatorChassis = false; |
| 532 | for (const char* interface : hasIndicatorLed) |
| 533 | { |
| 534 | if (std::find(interfaces3.begin(), |
| 535 | interfaces3.end(), |
| 536 | interface) != interfaces3.end()) |
| 537 | { |
| 538 | indicatorChassis = true; |
| 539 | break; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 540 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 541 | } |
| 542 | if (locationIndicatorActive) |
| 543 | { |
| 544 | if (indicatorChassis) |
| 545 | { |
| 546 | setLocationIndicatorActive( |
| 547 | asyncResp, *locationIndicatorActive); |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | messages::propertyUnknown( |
| 552 | asyncResp->res, "LocationIndicatorActive"); |
| 553 | } |
| 554 | } |
| 555 | if (indicatorLed) |
| 556 | { |
| 557 | if (indicatorChassis) |
| 558 | { |
| 559 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | messages::propertyUnknown(asyncResp->res, |
| 564 | "IndicatorLED"); |
| 565 | } |
| 566 | } |
| 567 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 568 | } |
| 569 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 570 | messages::resourceNotFound( |
| 571 | asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); |
| 572 | }, |
| 573 | "xyz.openbmc_project.ObjectMapper", |
| 574 | "/xyz/openbmc_project/object_mapper", |
| 575 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 576 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 577 | }); |
| 578 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 579 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 580 | inline void |
| 581 | doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 582 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 583 | const char* busName = "xyz.openbmc_project.ObjectMapper"; |
| 584 | const char* path = "/xyz/openbmc_project/object_mapper"; |
| 585 | const char* interface = "xyz.openbmc_project.ObjectMapper"; |
| 586 | const char* method = "GetSubTreePaths"; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 587 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 588 | const std::array<const char*, 1> interfaces = { |
| 589 | "xyz.openbmc_project.State.Chassis"}; |
| 590 | |
| 591 | // Use mapper to get subtree paths. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 592 | crow::connections::systemBus->async_method_call( |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 593 | [asyncResp]( |
| 594 | const boost::system::error_code ec, |
| 595 | const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 596 | if (ec) |
| 597 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 598 | BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 599 | messages::internalError(asyncResp->res); |
| 600 | return; |
| 601 | } |
| 602 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 603 | const char* processName = "xyz.openbmc_project.State.Chassis"; |
| 604 | const char* interfaceName = "xyz.openbmc_project.State.Chassis"; |
| 605 | const char* destProperty = "RequestedPowerTransition"; |
| 606 | const std::string propertyValue = |
| 607 | "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; |
| 608 | std::string objectPath = |
| 609 | "/xyz/openbmc_project/state/chassis_system0"; |
| 610 | |
| 611 | /* Look for system reset chassis path */ |
| 612 | if ((std::find(chassisList.begin(), chassisList.end(), |
| 613 | objectPath)) == chassisList.end()) |
| 614 | { |
| 615 | /* We prefer to reset the full chassis_system, but if it doesn't |
| 616 | * exist on some platforms, fall back to a host-only power reset |
| 617 | */ |
| 618 | objectPath = "/xyz/openbmc_project/state/chassis0"; |
| 619 | } |
| 620 | |
| 621 | crow::connections::systemBus->async_method_call( |
| 622 | [asyncResp](const boost::system::error_code ec) { |
| 623 | // Use "Set" method to set the property value. |
| 624 | if (ec) |
| 625 | { |
| 626 | BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " |
| 627 | << ec; |
| 628 | messages::internalError(asyncResp->res); |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | messages::success(asyncResp->res); |
| 633 | }, |
| 634 | processName, objectPath, "org.freedesktop.DBus.Properties", |
| 635 | "Set", interfaceName, destProperty, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 636 | dbus::utility::DbusVariantType{propertyValue}); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 637 | }, |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 638 | busName, path, interface, method, "/", 0, interfaces); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /** |
| 642 | * ChassisResetAction class supports the POST method for the Reset |
| 643 | * action. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 644 | * Function handles POST method request. |
| 645 | * Analyzes POST body before sending Reset request data to D-Bus. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 646 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 647 | |
| 648 | inline void requestRoutesChassisResetAction(App& app) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 649 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 650 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 651 | .privileges(redfish::privileges::postChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 652 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 653 | [&app](const crow::Request& req, |
| 654 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 655 | const std::string&) { |
| 656 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 657 | { |
| 658 | return; |
| 659 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 660 | BMCWEB_LOG_DEBUG << "Post Chassis Reset."; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 661 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 662 | std::string resetType; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 663 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 664 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", |
| 665 | resetType)) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 666 | { |
| 667 | return; |
| 668 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 669 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 670 | if (resetType != "PowerCycle") |
| 671 | { |
| 672 | BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " |
| 673 | << resetType; |
| 674 | messages::actionParameterNotSupported( |
| 675 | asyncResp->res, resetType, "ResetType"); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 676 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | doChassisPowerCycle(asyncResp); |
| 680 | }); |
| 681 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 682 | |
| 683 | /** |
| 684 | * ChassisResetActionInfo derived class for delivering Chassis |
| 685 | * ResetType AllowableValues using ResetInfo schema. |
| 686 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 687 | inline void requestRoutesChassisResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 688 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 689 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 690 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 691 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 692 | [&app](const crow::Request& req, |
| 693 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 694 | const std::string& chassisId) { |
| 695 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 696 | { |
| 697 | return; |
| 698 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 699 | asyncResp->res.jsonValue = { |
| 700 | {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, |
| 701 | {"@odata.id", |
| 702 | "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"}, |
| 703 | {"Name", "Reset Action Info"}, |
| 704 | {"Id", "ResetActionInfo"}, |
| 705 | {"Parameters", |
| 706 | {{{"Name", "ResetType"}, |
| 707 | {"Required", true}, |
| 708 | {"DataType", "String"}, |
| 709 | {"AllowableValues", {"PowerCycle"}}}}}}; |
| 710 | }); |
| 711 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 712 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 713 | } // namespace redfish |