blob: e5175b59953bec25a5d773ea1e34ed597f683ada [file] [log] [blame]
#include "chassis.hpp"
#include "error_messages.hpp"
#include "utils/subprocess_utils.hpp"
#include <boost/process.hpp>
#include <boost/system/error_code.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