diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-09-29 17:21:00 +0200 |
---|---|---|
committer | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-11-17 17:56:07 +0100 |
commit | 20935966efdae847023680217a4c109648698340 (patch) | |
tree | b36281271b133a141a1666d6039e4695128b9f3c /ogcp/views.py | |
parent | d029df8e842f8dce9d48f8ec9e11e336b0af46e9 (diff) |
WIP Make scopes tree async
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 0a65c17..5be8647 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -237,6 +237,27 @@ def get_server_from_ip_port(str_ip_port): raise Exception('Server with address ' + str_ip_port + 'is not configured') +def get_scopes_from_server(server): + r = server.get('/scopes') + server_scope = {} + server_scope['name'] = server.name + server_scope['type'] = "server" + server_scope['server_ip_port'] = (server.ip + ":" + str(server.port)) + server_scope.update(r.json()) + list_scopes = [] + list_scopes.append(server_scope) + scopes = {'scope': list_scopes} + if current_user.scopes: + allowed_scopes = [] + get_allowed_scopes(scopes, allowed_scopes) + scopes = {'scope': allowed_scopes} + r = server.get('/clients') + clients = r.json() + add_state_and_ips(scopes, clients['clients'], set()) + + return scopes + + def get_scopes(ips=set()): list_scopes = [] responses = multi_request('get', '/scopes') @@ -410,11 +431,28 @@ def get_client_mac(): return jsonify(pretty_mac) +@app.route('/ogservers', methods=['GET']) +@login_required +def get_ogservers(): + servers_list = [s.ip + ':' + str(s.port) for s in servers] + resp = jsonify(servers_list) + return resp + + +@app.route('/scopes-tree', methods=['GET']) +@login_required +def scopes_tree(): + params = request.args.to_dict() + server = get_server_from_ip_port(params['server']) + scopes = get_scopes_from_server(server) + return render_template('tree.html', scopes=scopes) + + @app.route('/scopes/') @login_required def scopes(): - scopes, clients = get_scopes() - return render_template('scopes.html', scopes=scopes, clients=clients) + return render_template('scopes.html') + @app.route('/action/poweroff', methods=['GET', 'POST']) @login_required |