diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2019-10-25 11:44:55 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-10-25 14:12:09 +0200 |
commit | 3ca392fce34206ce2d8f82bd23c53664c57c9e46 (patch) | |
tree | 91cae7bf6c20c5f5f86b1117ef8ae55a29cfc672 | |
parent | 32abc01e2301264a0d327ad88ce27b61247298cb (diff) |
#915 Add POST "run/schedule" command to REST API in ogAdmServer
This patch implements the command "run/schedule" that kicks in pending commands
execution.
Request:
POST /run/schedule
{
"clients": ["192.168.56.11"]
}
Reply:
200 OK
This patch also adds a simple test to cover correction of the command.
3 files changed, 42 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index 53f46a81..c75acf16 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp @@ -4082,6 +4082,36 @@ static int og_cmd_setup_image(json_t *element, struct og_msg_params *params) return 0; } +static int og_cmd_run_schedule(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) + err = og_json_parse_clients(value, params); + + if (err < 0) + break; + } + + len = snprintf(buf, sizeof(buf), "nfn=EjecutaComandosPendientes"); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + static int og_cmd_create_basic_image(json_t *element, struct og_msg_params *params) { char buf[4096] = {}; @@ -4602,6 +4632,16 @@ static int og_client_state_process_payload_rest(struct og_client *cli) return og_client_bad_request(cli); } err = og_cmd_setup_image(root, ¶ms); + } else if (!strncmp(cmd, "run/schedule", strlen("run/schedule"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + + err = og_cmd_run_schedule(root, ¶ms); } else { syslog(LOG_ERR, "unknown command: %.32s ...\n", cmd); err = og_client_not_found(cli); diff --git a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh index 409c8767..519366fb 100755 --- a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh +++ b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh @@ -19,3 +19,4 @@ curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create/bas curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create/incremental -d @create_incremental_image.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore/basic -d @restore_basic_image.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore/incremental -d @restore_incremental_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/run/schedule -d @run_schedule.json diff --git a/admin/Sources/Services/ogAdmServer/tests/run_schedule.json b/admin/Sources/Services/ogAdmServer/tests/run_schedule.json new file mode 100644 index 00000000..60a10349 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/run_schedule.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"]} |