views: skip cache space checks if already contains the image

Skip checks of image_fits_in_cache() if the image data contains
not 'size' or 'checksum' information.

Skip checks for the clients with the image already in cache.
master
Alejandro Sirgo Rica 2024-07-03 15:48:10 +02:00 committed by lupoDharkael
parent a88e5fed7d
commit 5cbb4a7562
1 changed files with 23 additions and 10 deletions

View File

@ -782,24 +782,30 @@ def get_clients_repo(server, ips):
return None
return repo_id
def image_fits_in_cache(server, ips, image_size):
err_report = ""
r = server.get('/cache/list', payload={'clients': ips})
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
return ogserver_error('commands')
def image_fits_in_cache(server, clients_info, image):
image_size = int(image.get('size', '0'))
image_checksum = image.get('checksum', '')
clients_info = r.json()['clients']
if not (image_size and image_checksum):
return True
err_report = ""
for client_info in clients_info:
ip = client_info['ip']
cache_size = int(client_info['cache_size'])
used_cache = 0
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
if free_cache < image_size:
missing_cache = image_size - free_cache
@ -844,8 +850,15 @@ def action_image_restore():
flash(_(f'The image size is bigger than the target partition'), category='error')
return redirect(url_for('commands'))
image_size = int(image['size'])
if requires_cache and image_size and not image_fits_in_cache(server, ips, image_size):
r = server.get('/cache/list', payload={'clients': ips})
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
return ogserver_error('commands')
clients_info = r.json()['clients']
if requires_cache and not image_fits_in_cache(server, clients_info, image):
return redirect(url_for('commands'))
try: