mirror of https://git.48k.eu/ogserver
#915 Add POST "image/restore/basic" command to REST API in ogAdmServer
This patch implements the command "image/restore/basic" that provides partitioning and formatting functionality. Request: POST /image/restore/basic { "clients":[ "192.168.56.11" ], "disk":"1", "partition":"1", "id":"9", "name":"test", "repository":"192.168.56.10", "profile":"17", "type":"UNICAST", "sync_params":{ "path":"", "method":"1", "sync":"1", "diff":"0", "remove":"1", "compress":"0", "cleanup":"0", "cache":"0", "cleanup_cache":"0", "remove_dst":"0" } } Reply: 200 OKmaster
parent
74061887ee
commit
f61fd9a488
|
@ -3259,6 +3259,8 @@ struct og_sync_params {
|
|||
const char *cache;
|
||||
const char *cleanup_cache;
|
||||
const char *remove_dst;
|
||||
const char *path;
|
||||
const char *method;
|
||||
};
|
||||
|
||||
struct og_msg_params {
|
||||
|
@ -3332,6 +3334,10 @@ static int og_json_parse_sync_params(json_t *element, og_sync_params *params)
|
|||
err = og_json_parse_string(value, ¶ms->cleanup_cache);
|
||||
else if (!strcmp(key, "remove_dst"))
|
||||
err = og_json_parse_string(value, ¶ms->remove_dst);
|
||||
else if (!strcmp(key, "path"))
|
||||
err = og_json_parse_string(value, ¶ms->path);
|
||||
else if (!strcmp(key, "method"))
|
||||
err = og_json_parse_string(value, ¶ms->method);
|
||||
|
||||
if (err != 0)
|
||||
return err;
|
||||
|
@ -4108,6 +4114,65 @@ static int og_cmd_create_basic_image(json_t *element, struct og_msg_params *para
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int og_cmd_restore_basic_image(json_t *element, struct og_msg_params *params)
|
||||
{
|
||||
char buf[4096] = {};
|
||||
int err = 0, len;
|
||||
const char *key;
|
||||
json_t *value;
|
||||
TRAMA *msg;
|
||||
|
||||
if (json_typeof(element) != JSON_OBJECT)
|
||||
return -1;
|
||||
|
||||
json_object_foreach(element, key, value) {
|
||||
if (!strcmp(key, "clients"))
|
||||
err = og_json_parse_clients(value, params);
|
||||
else if (!strcmp(key, "disk"))
|
||||
err = og_json_parse_string(value, ¶ms->disk);
|
||||
else if (!strcmp(key, "partition"))
|
||||
err = og_json_parse_string(value, ¶ms->partition);
|
||||
else if (!strcmp(key, "id"))
|
||||
err = og_json_parse_string(value, ¶ms->id);
|
||||
else if (!strcmp(key, "name"))
|
||||
err = og_json_parse_string(value, ¶ms->name);
|
||||
else if (!strcmp(key, "repository"))
|
||||
err = og_json_parse_string(value, ¶ms->repository);
|
||||
else if (!strcmp(key, "profile"))
|
||||
err = og_json_parse_string(value, ¶ms->profile);
|
||||
else if (!strcmp(key, "type"))
|
||||
err = og_json_parse_string(value, ¶ms->type);
|
||||
else if (!strcmp(key, "sync_params"))
|
||||
err = og_json_parse_sync_params(value, &(params->sync_setup));
|
||||
|
||||
if (err < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
len = snprintf(buf, sizeof(buf),
|
||||
"nfn=RestaurarImagenBasica\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r"
|
||||
"ipr=%s\rifs=%s\rrti=%s\rmet=%s\rmsy=%s\rtpt=%s\rwhl=%s\r"
|
||||
"eli=%s\rcmp=%s\rbpi=%s\rcpc=%s\rbpc=%s\rnba=%s\r",
|
||||
params->disk, params->partition, params->id, params->name,
|
||||
params->repository, params->profile, params->sync_setup.path,
|
||||
params->sync_setup.method, params->sync_setup.sync, params->type,
|
||||
params->sync_setup.diff, params->sync_setup.remove,
|
||||
params->sync_setup.compress, params->sync_setup.cleanup,
|
||||
params->sync_setup.cache, params->sync_setup.cleanup_cache,
|
||||
params->sync_setup.remove_dst);
|
||||
|
||||
msg = og_msg_alloc(buf, len);
|
||||
if (!msg)
|
||||
return -1;
|
||||
|
||||
og_send_cmd((char **)params->ips_array, params->ips_array_len,
|
||||
CLIENTE_OCUPADO, msg);
|
||||
|
||||
og_msg_free(msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int og_client_method_not_found(struct og_client *cli)
|
||||
{
|
||||
/* To meet RFC 7231, this function MUST generate an Allow header field
|
||||
|
@ -4349,6 +4414,16 @@ static int og_client_state_process_payload_rest(struct og_client *cli)
|
|||
return og_client_bad_request(cli);
|
||||
}
|
||||
err = og_cmd_create_image(root, ¶ms);
|
||||
} else if (!strncmp(cmd, "image/restore/basic",
|
||||
strlen("image/restore/basic"))) {
|
||||
if (method != OG_METHOD_POST)
|
||||
return og_client_method_not_found(cli);
|
||||
|
||||
if (!root) {
|
||||
syslog(LOG_ERR, "command create with no payload\n");
|
||||
return og_client_bad_request(cli);
|
||||
}
|
||||
err = og_cmd_restore_basic_image(root, ¶ms);
|
||||
} else if (!strncmp(cmd, "image/restore", strlen("image/restore"))) {
|
||||
if (method != OG_METHOD_POST)
|
||||
return og_client_method_not_found(cli);
|
||||
|
|
Loading…
Reference in New Issue