summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-05-19 17:18:52 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-05-26 15:15:52 +0200
commitb86b6e1443a6dfd21fa1520f7c4421a44d3595f3 (patch)
tree3a9032043cd29619eced8fab346f5c8d4ca4ebc7 /src
parentd5e6dc0990cb22efc05dda405dfa1e49f60359f5 (diff)
#915 Extend GET /images function with the repository IP
This extension adds the field 'repo_ip', indicating which repository has the image. This new field is useful when restoring an image. Request: GET /images Response: 200 OK { "disk": { "free": 37091418112, "total": 52573995008 }, "images": [ { "datasize": 5939200000, "id": 25, "modified": "Wed Oct 14 11:49:00 2020", "name": "archlinux", "permissions": "744", "size": 1844222333, "software_id": 19, "type": 1 "repo_ip": "192.168.56.10" } ] }
Diffstat (limited to 'src')
-rw-r--r--src/dbi.h1
-rw-r--r--src/rest.c10
2 files changed, 9 insertions, 2 deletions
diff --git a/src/dbi.h b/src/dbi.h
index cffb458..2423503 100644
--- a/src/dbi.h
+++ b/src/dbi.h
@@ -53,6 +53,7 @@ struct og_image_legacy {
struct og_image {
char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1];
+ char repo_ip[OG_DB_IP_MAXLEN + 1];
uint64_t software_id;
uint64_t center_id;
uint64_t datasize;
diff --git a/src/rest.c b/src/rest.c
index 05492e6..b5fcda7 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -2008,6 +2008,8 @@ static json_t *og_json_image_alloc(struct og_image *image)
json_integer(image->type));
json_object_set_new(image_json, "id",
json_integer(image->id));
+ json_object_set_new(image_json, "repo_ip",
+ json_string(image->repo_ip));
return image_json;
}
@@ -2047,10 +2049,12 @@ static int og_cmd_images(char *buffer_reply)
" i.clonator, i.compressor, "
" i.filesystem, i.datasize, "
" i.idperfilsoft, i.tipo, "
- " i.idimagen "
+ " i.idimagen, r.ip "
"FROM imagenes i "
"LEFT JOIN ordenadores o "
- "ON i.idordenador = o.idordenador");
+ "ON i.idordenador = o.idordenador "
+ "JOIN repositorios r "
+ "ON i.idrepositorio = r.idrepositorio");
while (dbi_result_next_row(result)) {
image = (struct og_image){0};
@@ -2058,6 +2062,8 @@ static int og_cmd_images(char *buffer_reply)
image.software_id = dbi_result_get_ulonglong(result, "idperfilsoft");
image.type = dbi_result_get_ulonglong(result, "tipo");
image.id = dbi_result_get_ulonglong(result, "idimagen");
+ snprintf(image.repo_ip, sizeof(image.repo_ip), "%s",
+ dbi_result_get_string(result, "ip"));
snprintf(image.name, sizeof(image.name), "%s",
dbi_result_get_string(result, "nombreca"));