From d8af32cbcb1f576e799a6efaaeb3843e7e957d14 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Fri, 30 Aug 2024 12:49:22 +0200 Subject: rest: adapt restore/image to support repository with multiple IP adddress take repository_id as json attributo, then infer repository IP from client. --- src/rest.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index 9c5cbb5..1a243e4 100644 --- a/src/rest.c +++ b/src/rest.c @@ -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) -- cgit v1.2.3-18-g5258