summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorDaniel García Moreno <danigm@soleta.eu>2022-09-14 14:01:18 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-09-27 09:48:36 +0200
commit0c66443db89fec72c5fb2af0588a02695683613c (patch)
treebfdf3da7d960b1a17943e689d5b92c0f1b72337b /ogcp/views.py
parentea182079989407e382917d95cc86c77dbee7bff8 (diff)
Add multiple servers to the dashboard view
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py61
1 files changed, 39 insertions, 22 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index dc2a3c2..7b6c7ae 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -333,28 +333,45 @@ def index():
if not current_user.is_authenticated:
return redirect(url_for('login'))
- try:
- clients = get_clients()
- except requests.exceptions.RequestException as err:
- flash(_('ogServer connection failed: {}.').format(err),
- category='error')
- logout_user()
- return redirect(url_for('index'))
- images_response = g.server.get('/images')
- images = images_response.json()['images']
- images.sort(key=image_modified_date_from_str, reverse=True)
- disk = images_response.json()['disk']
- oglive_list = g.server.get('/oglive/list').json()
- stats = g.server.get('/stats').json()
- timestamp = datetime.datetime.fromtimestamp(stats.get('time').get('now'))
- now = timestamp.strftime('%Y-%m-%d %H:%M:%S')
- boot = display_time(stats.get('time').get('boot'))
- start = display_time(stats.get('time').get('start'))
- time_dict = {'now': now, 'boot': boot, 'start': start}
- return render_template('dashboard.html', clients=clients,
- images=images, disk=disk, colsize="6",
- oglive_list=oglive_list, stats=stats,
- time_dict=time_dict)
+ images_response = multi_request('get', '/images')
+ dashboard_servers = {}
+ for i in images_response:
+ server_name = i['server'].name
+ server_id = i['server'].id
+ images = i['json']['images']
+ images.sort(key=image_modified_date_from_str, reverse=True)
+ disk = i['json']['disk']
+
+ if server_name not in dashboard_servers:
+ dashboard_servers[server_id] = {'name': server_name}
+
+ dashboard_servers[server_id]['images'] = images
+ dashboard_servers[server_id]['disk'] = disk
+
+ oglive_list = multi_request('get', '/oglive/list')
+ for i in oglive_list:
+ server_id = i['server'].id
+ dashboard_servers[server_id]['oglive_list'] = i['json']
+
+ all_stats = multi_request('get', '/stats')
+ for i in all_stats:
+ server_id = i['server'].id
+ stats = i['json']
+ dashboard_servers[server_id]['stats'] = stats
+
+ timestamp = datetime.datetime.fromtimestamp(stats.get('time').get('now'))
+ now = timestamp.strftime('%Y-%m-%d %H:%M:%S')
+ boot = display_time(stats.get('time').get('boot'))
+ start = display_time(stats.get('time').get('start'))
+ time_dict = {'now': now, 'boot': boot, 'start': start}
+ dashboard_servers[server_id]['time_dict'] = time_dict
+
+ clients_response = multi_request('get', '/clients')
+ for i in clients_response:
+ server_id = i['server'].id
+ dashboard_servers[server_id]['clients'] = i['json']['clients']
+
+ return render_template('dashboard.html', servers=dashboard_servers, colsize="6")
@app.route('/login', methods=['GET', 'POST'])
def login():