From 3e35997131f51e892b93157c6d18a3a0ba759318 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 30 Jul 2024 13:10:29 +0200 Subject: ogcp: add connected clients list view Add view to show the connected clients with access to the client details of each one. The view is accessible through the main dashboard. --- ogcp/templates/client_list.html | 55 +++++++++++++++++++++++++++++++++++++++++ ogcp/templates/dashboard.html | 2 +- ogcp/views.py | 22 +++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 ogcp/templates/client_list.html diff --git a/ogcp/templates/client_list.html b/ogcp/templates/client_list.html new file mode 100644 index 0000000..188cc2a --- /dev/null +++ b/ogcp/templates/client_list.html @@ -0,0 +1,55 @@ +{% extends 'commands.html' %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block content %} + +

{{_('Connected clients')}}

+ +
+ +{% for server_id, server_data in servers_data.items() %} +
+
+

+ +

+
+
+
+ + + + + + + + + + + {% for client_data in server_data.clients %} + + + + + + {% endfor %} + +
{{ _('IP') }}{{ _('Link speed') }}{{ _('Details') }}
{{ client_data.addr }} + {% if client_data.speed >= 1000 %} + {{ (client_data.speed / 1000) | int }} Gb/s + {% else %} + {{ client_data.speed }} Mb/s + {% endif %} + {{ _('View details') }}
+
+
+
+{% endfor %} + +
+ +{% endblock %} diff --git a/ogcp/templates/dashboard.html b/ogcp/templates/dashboard.html index 7cd300b..3ec2cd8 100644 --- a/ogcp/templates/dashboard.html +++ b/ogcp/templates/dashboard.html @@ -26,7 +26,7 @@ {{ server.name }} {{ server.time_dict.boot }} {{ server.time_dict.start }} - {{ server.clients | length }} + {{ server.clients | length }} {{ server.images | length }} {% set disk = server.disk %} diff --git a/ogcp/views.py b/ogcp/views.py index 1beaa5b..2a89d01 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -551,6 +551,28 @@ def get_client_mac(): return jsonify(pretty_mac) +@app.route('/client/list', methods=['GET']) +@login_required +def client_list(): + clients_response = multi_request('get', '/clients') + servers_data = {} + for i in clients_response: + server_id = i['server'].id + if server_id not in servers_data: + servers_data[server_id] = {} + servers_data[server_id]['clients'] = i['json']['clients'] + for server in servers: + if server.id == server_id: + servers_data[server_id]['name'] = server.name + + scopes, clients = get_scopes() + selected_clients = list(get_selected_clients(scopes['scope']).items()) + + return render_template('client_list.html', servers_data=servers_data, + selected_clients=selected_clients, + scopes=scopes) + + @app.route('/scopes/') @login_required def scopes(): -- cgit v1.2.3-18-g5258