diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-08-30 12:49:22 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-08-30 13:01:54 +0200 |
commit | d8af32cbcb1f576e799a6efaaeb3843e7e957d14 (patch) | |
tree | cf84bb7350058f103e81c4b3fd43e0d59fda59a9 /src/rest.c | |
parent | cd9650108af1eb882ca11858249dc428087667ff (diff) |
rest: adapt restore/image to support repository with multiple IP adddress
take repository_id as json attributo, then infer repository IP from client.
Diffstat (limited to 'src/rest.c')
-rw-r--r-- | src/rest.c | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -3811,8 +3811,8 @@ int og_json_parse_restore_image(json_t *element, struct og_msg_params *params) } else if (!strcmp(key, "name")) { err = og_json_parse_string(value, ¶ms->name); params->flags |= OG_REST_PARAM_NAME; - } else if (!strcmp(key, "repository")) { - err = og_json_parse_string(value, ¶ms->repository); + } else if (!strcmp(key, "repository_id")) { + err = og_json_parse_uint64(value, ¶ms->image.repo_id); params->flags |= OG_REST_PARAM_REPO; } else if (!strcmp(key, "clients")) { err = og_json_parse_clients(value, params); @@ -3836,8 +3836,10 @@ int og_json_parse_restore_image(json_t *element, struct og_msg_params *params) static int og_cmd_restore_image(json_t *element, struct og_msg_params *params) { - json_t *clients; - int err = 0; + char repository_ip[OG_DB_IP_MAXLEN + 1] = {}; + struct og_dbi *dbi; + json_t *body; + int err; err = og_json_parse_restore_image(element, params); if (err < 0) @@ -3853,11 +3855,26 @@ static int og_cmd_restore_image(json_t *element, struct og_msg_params *params) OG_REST_PARAM_ID)) return -1; - clients = json_copy(element); - json_object_del(clients, "clients"); + dbi = og_dbi_open(&ogconfig.db); + if (!dbi) { + syslog(LOG_ERR, + "cannot open connection database (%s:%d)\n", + __func__, __LINE__); + return -1; + } + + err = og_dbi_get_repository_ip(dbi, params->image.repo_id, + params->ips_array[0], repository_ip); + og_dbi_close(dbi); + if (err < 0) + return err; + + body = json_copy(element); + json_object_del(body, "clients"); + json_object_set_new(body, "repository", json_string(repository_ip)); return og_send_request(OG_METHOD_POST, OG_CMD_IMAGE_RESTORE, params, - clients); + body); } static int og_delete_image(struct og_dbi *dbi, const uint32_t image_id) |