summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-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: