summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-18 15:08:07 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-18 16:08:24 +0200
commit521b7c81aca650256c10c105b213e75f9060c6c6 (patch)
treeb3d907bf487ce36edd5bc68ecab777c0ff4408d6 /ogcp
parent3c4b91728053e242eb13a04a3c13074033c493f5 (diff)
views: check if the image fits in cache before image/restore
Check if the image to be restored fits in the client's cache to provide a better feedback for a failed restore operation. Report the needed free space in clients where it does not fit. Only check if the reported image size is not 0, older images may not define the "size" attribute. Ignore the check if the restore type is UNICAST-DIRECT.
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/views.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index abcc0a7..ced0b0f 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -746,6 +746,35 @@ 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')
+
+ clients_info = r.json()['clients']
+
+ for client_info in clients_info:
+ ip = client_info['ip']
+ cache_size = int(client_info['cache_size'])
+ used_cache = 0
+
+ for image_info in client_info['images']:
+ used_cache += int(image_info['size'])
+
+ free_cache = cache_size - used_cache
+ if free_cache < image_size:
+ missing_cache = image_size - free_cache
+ err_report += f'{ip}: needs {(missing_cache / (1024 ** 3)):.3f} free GiB<br>'
+
+ if err_report:
+ flash(f'Client cache error:<br>{err_report}', category='error')
+ return False
+
+ return True
+
@app.route('/action/image/restore', methods=['GET', 'POST'])
@login_required
def action_image_restore():
@@ -785,6 +814,10 @@ 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):
+ return redirect(url_for('commands'))
+
try:
repository = get_repository(image['repo_id'], server)
except ServerError: