summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c31
1 files changed, 24 insertions, 7 deletions
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, &params->name);
params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "repository")) {
- err = og_json_parse_string(value, &params->repository);
+ } else if (!strcmp(key, "repository_id")) {
+ err = og_json_parse_uint64(value, &params->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)