@@ -36,7 +36,6 @@ bool HardwareActivateCmd::Exec(
3636 }
3737 }
3838
39- // TODO(sang) should use curl but it does not work (?)
4039 Json::Value body;
4140 Json::Value gpus_json = Json::arrayValue;
4241 std::vector<int > gpus;
@@ -51,36 +50,30 @@ bool HardwareActivateCmd::Exec(
5150 body[" gpus" ] = gpus_json;
5251 auto data_str = body.toStyledString ();
5352
54- httplib::Client cli (host + " :" + std::to_string (port));
53+ auto url = url_parser::Url{
54+ .protocol = " http" ,
55+ .host = host + " :" + std::to_string (port),
56+ .pathParams = {" v1" , " hardware" , " activate" },
57+ };
5558
56- auto res = cli.Post (" /v1/hardware/activate" , httplib::Headers (),
57- data_str.data (), data_str.size (), " application/json" );
58- if (res) {
59- if (res->status == httplib::StatusCode::OK_200) {
60- auto root = json_helper::ParseJsonString (res->body );
61- if (!root[" warning" ].isNull ()) {
62- CLI_LOG (root[" warning" ].asString ());
63- }
64- if (body[" gpus" ].empty ()) {
65- CLI_LOG (" Deactivated all GPUs!" );
66- } else {
67- std::string gpus_str;
68- for (auto i: gpus) {
69- gpus_str += " " + std::to_string (i);
70- }
71- CLI_LOG (" Activated GPUs:" << gpus_str);
72- }
73- return true ;
74- } else {
75- auto root = json_helper::ParseJsonString (res->body );
76- CLI_LOG (root[" message" ].asString ());
77- return false ;
78- }
79- } else {
80- auto err = res.error ();
81- CTL_ERR (" HTTP error: " << httplib::to_string (err));
59+ auto res = curl_utils::SimplePostJson (url.ToFullPath (), data_str);
60+ if (res.has_error ()) {
61+ auto root = json_helper::ParseJsonString (res.error ());
62+ CLI_LOG (root[" message" ].asString ());
8263 return false ;
8364 }
65+ if (!res.value ()[" warning" ].isNull ()) {
66+ CLI_LOG (res.value ()[" warning" ].asString ());
67+ }
68+ if (body[" gpus" ].empty ()) {
69+ CLI_LOG (" Deactivated all GPUs!" );
70+ } else {
71+ std::string gpus_str;
72+ for (auto i : gpus) {
73+ gpus_str += " " + std::to_string (i);
74+ }
75+ CLI_LOG (" Activated GPUs:" << gpus_str);
76+ }
8477 return true ;
8578}
86- } // namespace commands
79+ } // namespace commands
0 commit comments