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