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