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