rest: send image/update to ogClient for update operations

Send image/update instead of only image/create for both update
and create operations. A failed update operation using the
error handler of OG_CMD_IMAGE_CREATE results in the deletion
of the image from database.

Fail if the image already exists for an image create operation.
master v1.2.5-29
Alejandro Sirgo Rica 2025-01-31 14:37:56 +01:00
parent 4db69ad054
commit acf9c07236
2 changed files with 17 additions and 1 deletions

View File

@ -1404,6 +1404,9 @@ int og_agent_state_process_response(struct og_client *cli)
if (err < 0)
og_resp_image_create_error(cli);
break;
case OG_CMD_IMAGE_UPDATE:
err = og_resp_image_create(root, cli);
break;
case OG_CMD_IMAGE_RESTORE:
err = og_resp_image_restore(root, cli);
if (!err)

View File

@ -3836,6 +3836,7 @@ static int og_cmd_add_image(struct og_rest_ctx *ctx, bool update)
char repository_ip[OG_DB_IP_MAXLEN + 1];
char new_image_id[OG_DB_INT_MAXLEN + 1];
struct og_cmd_ctx cmd_ctx = {};
enum og_cmd_type cmd_type;
struct og_dbi *dbi;
json_t *body;
int err = 0;
@ -3888,6 +3889,13 @@ static int og_cmd_add_image(struct og_rest_ctx *ctx, bool update)
snprintf(new_image_id, sizeof(new_image_id), "%lu", params->image.id);
params->id = new_image_id;
} else {
if (!update) {
syslog(LOG_ERR, "cannot create image file `%s', it already exists\n",
params->image.name);
ctx->http_error = OG_HTTP_409_CONFLICT;
og_dbi_close(dbi);
return -1;
}
syslog(LOG_INFO, "updating existing image `%s'\n", params->image.name);
snprintf(new_image_id, sizeof(new_image_id), "%lu", params->image.id);
params->id = new_image_id;
@ -3907,7 +3915,12 @@ static int og_cmd_add_image(struct og_rest_ctx *ctx, bool update)
cmd_ctx.image.id = params->image.id;
return og_send_request(OG_METHOD_POST, OG_CMD_IMAGE_CREATE, params,
if (update)
cmd_type = OG_CMD_IMAGE_UPDATE;
else
cmd_type = OG_CMD_IMAGE_CREATE;
return og_send_request(OG_METHOD_POST, cmd_type, params,
body, &cmd_ctx);
}