mirror of https://git.48k.eu/ogserver
#915: Add POST /image/restore command to REST API in ogAdmServer
This patch implements the command "image/create" that creates an image in a client. Request: POST /image/restore { "clients" : [ "192.168.56.11" ], "disk" : "1", "partition" : "1", "name" : "test", "repository" : "192.168.56.10", "type" : "UNICAST", "filesystem": "1", "image_id": "1"} Reply: 200 OKmaster
parent
c87a1dbdfb
commit
1dde02e1ab
|
@ -3363,6 +3363,8 @@ struct og_msg_params {
|
|||
const char *name;
|
||||
const char *id;
|
||||
const char *code;
|
||||
const char *type;
|
||||
const char *profile;
|
||||
};
|
||||
|
||||
static int og_json_parse_clients(json_t *element, struct og_msg_params *params)
|
||||
|
@ -3959,6 +3961,58 @@ static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int og_cmd_restore_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, "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, "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, "clients"))
|
||||
err = og_json_parse_clients(value, params);
|
||||
else if (!strcmp(key, "type"))
|
||||
err = og_json_parse_string(value, ¶ms->type);
|
||||
else if (!strcmp(key, "profile"))
|
||||
err = og_json_parse_string(value, ¶ms->profile);
|
||||
else if (!strcmp(key, "id"))
|
||||
err = og_json_parse_string(value, ¶ms->id);
|
||||
|
||||
if (err < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
len = snprintf(buf, sizeof(buf),
|
||||
"nfn=RestaurarImagen\ridi=%s\rdsk=%s\rpar=%s\rifs=%s\r"
|
||||
"nci=%s\ripr=%s\rptc=%s\r",
|
||||
params->id, params->disk, params->partition,
|
||||
params->profile, params->name,
|
||||
params->repository, params->type);
|
||||
|
||||
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
|
||||
|
@ -4190,6 +4244,15 @@ 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", strlen("image/restore"))) {
|
||||
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_image(root, ¶ms);
|
||||
} else {
|
||||
syslog(LOG_ERR, "unknown command: %.32s ...\n", cmd);
|
||||
err = og_client_not_found(cli);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "clients" : [ "192.168.56.11" ], "disk" : "1", "partition" : "1", "name" : "test", "repository" : "192.168.56.10", "type" : "UNICAST", "filesystem": "1", "image_id": "1"}
|
|
@ -13,3 +13,4 @@ curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/refresh -d @refr
|
|||
curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/hardware -d @post_clients.json
|
||||
curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/software -d @post_clients.json
|
||||
curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create -d @create_image.json
|
||||
curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore -d @restore_image.json
|
||||
|
|
Loading…
Reference in New Issue