diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-03 15:48:10 +0200 |
---|---|---|
committer | lupoDharkael <izhe@hotmail.es> | 2024-07-09 09:52:21 +0200 |
commit | 5cbb4a7562d126dd8eaa0a304f95274edf074582 (patch) | |
tree | 37e9bf6231f5366a663499698230031a20aa7c9e | |
parent | a88e5fed7dec1dd41b3feec0905f4c9925515665 (diff) |
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.
-rw-r--r-- | ogcp/views.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 3ceffdf..1f84621 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -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: |