summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py81
1 files changed, 53 insertions, 28 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 2a6c244..2c8f650 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -354,6 +354,34 @@ def hash_password(pwd):
return pwd_hash
+def get_cache_info(clients_info, storage_data, images_data, client_images):
+ 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']:
+ image_name = image_info['name']
+ checksum = image_info['checksum']
+ used_cache += int(image_info['size'])
+ img_identifier = f'{image_name}.{checksum}'
+
+ if ip in client_images:
+ client_images[ip].append(img_identifier)
+ else:
+ client_images[ip] = [img_identifier]
+
+ if img_identifier in images_data:
+ images_data[img_identifier]['clients'].append(ip)
+ else:
+ images_data[img_identifier] = {
+ 'clients': [ip],
+ 'size': int(image_info['size']),
+ 'name': image_name,
+ 'checksum': checksum
+ }
+
+ storage_data[ip] = {'used': used_cache,
+ 'total': cache_size}
def authenticate_user(username, pwd):
for user in app.config['USERS']:
@@ -1171,9 +1199,9 @@ def action_client_cache():
if not validate_elements(ips):
return redirect(url_for('commands'))
- server = get_server_from_clients(ips_list)
form.ips.data = ' '.join(ips_list)
+ server = get_server_from_clients(ips_list)
r = server.get('/cache/list', payload={'clients': ips_list})
if not r:
return ogserver_down('commands')
@@ -1189,33 +1217,8 @@ def action_client_cache():
storage_data = {}
images_data = {}
client_images = {}
- 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']:
- image_name = image_info['name']
- checksum = image_info['checksum']
- used_cache += int(image_info['size'])
- img_identifier = f'{image_name}.{checksum}'
-
- if ip in client_images:
- client_images[ip].append(img_identifier)
- else:
- client_images[ip] = [img_identifier]
- if img_identifier in images_data:
- images_data[img_identifier]['clients'].append(ip)
- else:
- images_data[img_identifier] = {
- 'clients': [ip],
- 'size': int(image_info['size']),
- 'name': image_name,
- 'checksum': checksum
- }
-
- storage_data[ip] = {'used': used_cache,
- 'total': cache_size}
+ get_cache_info(clients_info, storage_data, images_data, client_images)
for img_identifier in images_data:
image_data = images_data[img_identifier]
@@ -1321,10 +1324,31 @@ def action_client_info():
else:
entry['image'] = ""
+ r = server.get('/cache/list', payload={'clients': [ip]})
+ if not r:
+ return ogserver_down('commands')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error('commands')
+
+ clients_info = r.json()['clients']
+
+ if not clients_info:
+ flash(_('ogServer returned an empty client list'), category='error')
+ return redirect(url_for('commands'))
+
+ storage_data = {}
+ images_data = {}
+ client_images = {}
+
+ get_cache_info(clients_info, storage_data, images_data, client_images)
+
scopes, clients = get_scopes(set(ips))
return render_template('actions/client_details.html', form=form,
- parent="commands.html", scopes=scopes, setup=setup)
+ parent="commands.html", scopes=scopes, setup=setup,
+ images_data=images_data,
+ storage_data=storage_data,
+ client_images=client_images)
@app.route('/action/client/update', methods=['GET', 'POST'])
@login_required
@@ -1455,6 +1479,7 @@ def action_client_update():
entry['image'] = ""
form.submit.render_kw = {"formaction": url_for('action_client_update')}
+
return render_template('actions/client_details.html', form=form,
parent="scopes.html", scopes=scopes, setup=setup)