views: improve checks for space available in cache

Use the new "free_cache" field in GET /cache/list to check
against the real available space to check if an image fits in
cache.
master
Alejandro Sirgo Rica 2024-09-26 10:19:37 +02:00
parent ec209480ea
commit 340b7fde54
1 changed files with 2 additions and 5 deletions

View File

@ -956,20 +956,17 @@ def image_fits_in_cache(server, clients_info, image):
for client_info in clients_info:
ip = client_info['ip']
cache_size = int(client_info['cache_size'])
used_cache = 0
cache_size = client_info['cache_size'] * 1024
has_image = False;
for image_info in client_info['images']:
used_cache += int(image_info['size'])
if image_info['checksum'] == image_checksum:
has_image = True
if has_image:
continue
free_cache = cache_size - used_cache
free_cache = client_info['free_cache']
if free_cache < image_size:
missing_cache = image_size - free_cache
err_report += f'{ip} requires {(missing_cache / (1024 ** 3)):.3f} free GiB<br>'