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