diff options
Diffstat (limited to 'src/rest.c')
-rw-r--r-- | src/rest.c | 33 |
1 files changed, 19 insertions, 14 deletions
@@ -254,7 +254,7 @@ static bool og_client_is_busy(const struct og_client *cli, int og_send_request(enum og_rest_method method, enum og_cmd_type type, const struct og_msg_params *params, - const json_t *data) + const json_t *data, const struct og_cmd_ctx *ctx) { const char *content_type = "Content-Type: application/json"; char content [OG_MSG_REQUEST_MAXLEN - 700] = {}; @@ -320,6 +320,8 @@ int og_send_request(enum og_rest_method method, enum og_cmd_type type, continue; cli->last_cmd.type = type; + if (ctx) + cli->last_cmd.ctx = *ctx; } json_decref((json_t *)data); @@ -691,7 +693,7 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params) clients = json_copy(element); json_object_del(clients, "clients"); - return og_send_request(OG_METHOD_POST, OG_CMD_SHELL_RUN, params, clients); + return og_send_request(OG_METHOD_POST, OG_CMD_SHELL_RUN, params, clients, NULL); } static int og_cmd_run_get(json_t *element, struct og_msg_params *params, @@ -911,7 +913,7 @@ static int og_cmd_session(json_t *element, struct og_msg_params *params) clients = json_copy(element); json_object_del(clients, "clients"); - return og_send_request(OG_METHOD_POST, OG_CMD_SESSION, params, clients); + return og_send_request(OG_METHOD_POST, OG_CMD_SESSION, params, clients, NULL); } static int og_json_os_array_get(struct og_dbi *dbi, json_t *array, const char *ip) @@ -1065,7 +1067,7 @@ static int og_cmd_poweroff(json_t *element, struct og_msg_params *params) if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) return -1; - return og_send_request(OG_METHOD_POST, OG_CMD_POWEROFF, params, NULL); + return og_send_request(OG_METHOD_POST, OG_CMD_POWEROFF, params, NULL, NULL); } static int og_cmd_refresh(json_t *element, struct og_msg_params *params) @@ -1088,7 +1090,7 @@ static int og_cmd_refresh(json_t *element, struct og_msg_params *params) if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) return -1; - return og_send_request(OG_METHOD_GET, OG_CMD_REFRESH, params, NULL); + return og_send_request(OG_METHOD_GET, OG_CMD_REFRESH, params, NULL, NULL); } static int og_cmd_reboot(json_t *element, struct og_msg_params *params) @@ -1111,7 +1113,7 @@ static int og_cmd_reboot(json_t *element, struct og_msg_params *params) if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) return -1; - return og_send_request(OG_METHOD_POST, OG_CMD_REBOOT, params, NULL); + return og_send_request(OG_METHOD_POST, OG_CMD_REBOOT, params, NULL, NULL); } #define OG_TFTP_TMPL_PATH_UEFI "/opt/opengnsys/tftpboot/grub/templates" @@ -3146,7 +3148,7 @@ static int og_cmd_stop(json_t *element, struct og_msg_params *params) if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) return -1; - return og_send_request(OG_METHOD_POST, OG_CMD_STOP, params, NULL); + return og_send_request(OG_METHOD_POST, OG_CMD_STOP, params, NULL, NULL); } static int og_cmd_hardware(json_t *element, struct og_msg_params *params) @@ -3169,7 +3171,7 @@ static int og_cmd_hardware(json_t *element, struct og_msg_params *params) if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) return -1; - return og_send_request(OG_METHOD_GET, OG_CMD_HARDWARE, params, NULL); + return og_send_request(OG_METHOD_GET, OG_CMD_HARDWARE, params, NULL, NULL); } static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params, @@ -3300,7 +3302,7 @@ static int og_cmd_software(json_t *element, struct og_msg_params *params) clients = json_copy(element); json_object_del(clients, "clients"); - return og_send_request(OG_METHOD_GET, OG_CMD_SOFTWARE, params, clients); + return og_send_request(OG_METHOD_GET, OG_CMD_SOFTWARE, params, clients, NULL); } static int og_cmd_get_software(json_t *element, struct og_msg_params *params, @@ -3682,6 +3684,7 @@ static int og_cmd_add_image(json_t *element, struct og_msg_params *params, { char repository_ip[OG_DB_IP_MAXLEN + 1]; char new_image_id[OG_DB_INT_MAXLEN + 1]; + struct og_cmd_ctx ctx = {}; struct og_dbi *dbi; json_t *body; int err = 0; @@ -3750,8 +3753,10 @@ static int og_cmd_add_image(json_t *element, struct og_msg_params *params, json_object_set_new(body, "repository", json_string(repository_ip)); json_object_set_new(body, "backup", json_boolean(params->backup)); + ctx.image.id = params->image.id; + return og_send_request(OG_METHOD_POST, OG_CMD_IMAGE_CREATE, params, - body); + body, &ctx); } static int og_cmd_create_image(json_t *element, struct og_msg_params *params) @@ -3846,7 +3851,7 @@ static int og_cmd_restore_image(json_t *element, struct og_msg_params *params) json_object_set_new(body, "repository", json_string(repository_ip)); return og_send_request(OG_METHOD_POST, OG_CMD_IMAGE_RESTORE, params, - body); + body, NULL); } static int og_cmd_delete_image(json_t *element, struct og_msg_params *params) @@ -4443,7 +4448,7 @@ static int og_cmd_cache_delete(json_t *element, struct og_msg_params *params, body = json_copy(element); json_object_del(body, "clients"); - return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_DELETE, params, body); + return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_DELETE, params, body, NULL); } static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params, @@ -4497,7 +4502,7 @@ static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params, json_object_del(body, "clients"); json_object_set_new(body, "repository", json_string(repository_ip)); - return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_FETCH, params, body); + return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_FETCH, params, body, NULL); } static int og_cmd_setup(json_t *element, struct og_msg_params *params) @@ -4546,7 +4551,7 @@ static int og_cmd_setup(json_t *element, struct og_msg_params *params) clients = json_copy(element); json_object_del(clients, "clients"); - return og_send_request(OG_METHOD_POST, OG_CMD_SETUP, params, clients); + return og_send_request(OG_METHOD_POST, OG_CMD_SETUP, params, clients, NULL); } static int og_cmd_scope_get(json_t *element, struct og_msg_params *params, |