rest: add free and used cache to GET /cache/list

Add "used_cache" and "free_cache" fields to the payload of GET
/cache/list.
master
Alejandro Sirgo Rica 2024-09-26 09:40:24 +02:00
parent 3c395ecea2
commit 491bf6f5e9
1 changed files with 7 additions and 2 deletions

View File

@ -4130,13 +4130,14 @@ static int og_cmd_image_scope_list(json_t *element,
static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const char *ip)
{
uint64_t img_size, cache_size = 0, used_cache = 0, free_cache = 0;
const char *img_name, *msglog, *img_checksum;
json_t *client_data, *cache_arr, *img_info;
uint64_t img_size, cache_size = 0;
dbi_result result;
result = dbi_conn_queryf(dbi->conn,
"SELECT ordenadores_particiones.tamano "
"SELECT ordenadores_particiones.tamano, "
"ordenadores_particiones.used_size, ordenadores_particiones.free_size "
"FROM ordenadores_particiones JOIN ordenadores "
"ON ordenadores.idordenador = ordenadores_particiones.idordenador "
"WHERE ordenadores.ip = '%s' AND codpar = 202", ip);
@ -4149,6 +4150,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch
if (dbi_result_next_row(result)) {
cache_size = dbi_result_get_longlong(result, "tamano") * 1024;
used_cache = dbi_result_get_longlong(result, "used_size");
free_cache = dbi_result_get_longlong(result, "free_size");
}
dbi_result_free(result);
@ -4200,6 +4203,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch
json_object_set_new(client_data, "ip", json_string(ip));
json_object_set_new(client_data, "cache_size", json_integer(cache_size));
json_object_set_new(client_data, "used_cache", json_integer(used_cache));
json_object_set_new(client_data, "free_cache", json_integer(free_cache));
json_object_set_new(client_data, "images", cache_arr);
json_array_append_new(clients, client_data);
dbi_result_free(result);