| #include <memory> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
| |
| #include "boost/process.hpp" // NOLINT |
| #include "boost/system/error_code.hpp" // NOLINT |
| #include "async_resp.hpp" |
| #include "subprocess_utils.hpp" |
| #include <nlohmann/json.hpp> |
| |
| namespace redfish { |
| |
| static std::vector<std::string> resetCmdSystem(const int& delayTimeSecs, |
| std::string_view resetType, |
| std::string_view systemName) { |
| nlohmann::json resetOp; |
| resetOp["ResetType"] = resetType; |
| |
| std::string resetURI = "localhost:80/redfish/v1/Systems/" + |
| std::string(systemName) + |
| "/Actions/ComputerSystem.Reset"; |
| |
| std::vector<std::string> resetCmd = { |
| "systemd-run", |
| "--on-active=" + std::to_string(delayTimeSecs), |
| "--timer-property=AccuracySec=100ms", |
| "--", |
| "curl", |
| "-d", |
| resetOp.dump(), |
| "-H", |
| "Content-Type: application/json", |
| "-X", |
| "POST", |
| resetURI}; |
| return resetCmd; |
| } |
| |
| /* Have systemd run a curl command in a set amount of time |
| * resetURI: Chassis or Systems based on where you want to reset |
| * resetTimeSec: The amount of seconds to delay reset |
| * resetOp: same as resetType variable here |
| * asyncResp update the response |
| */ |
| |
| void delayResetSystem(std::string_view systemName, int delayTimeSecs, |
| std::string_view resetType, |
| const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| childProcessRun(asyncResp, |
| resetCmdSystem(delayTimeSecs, resetType, systemName)); |
| } |
| |
| } // namespace redfish |