diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-08-04 18:27:21 +0200 |
---|---|---|
committer | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-09-27 09:48:35 +0200 |
commit | 74e9ff99070e2ad2335ae9dadf3c02f2a5969ace (patch) | |
tree | 5f909aab0f1350fe9ee050b36abb8de6a859ebe9 /ogcp/views.py | |
parent | ddea404c5bf8deab620bc0b9f44eeebea6790f24 (diff) |
Initial support of ogServer requests "routing"
This commit adds a helper function ("get_server_from_clients()") to get
the adequate ogServer according to the targeted clients.
It also makes "Client details" command use this function.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 44c395a..ffa890d 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -197,13 +197,30 @@ def multi_request(method, uri, payload=None): else: raise Exception('Invalid method, use get or post') - response['server'] = server.name - response['status_code'] = r.status_code + response['server'] = server response['json'] = r.json() responses.append(response) return responses + +def get_server_from_clients(selected_clients): + server = None + + responses = multi_request('get', '/scopes') + for r in responses: + server_clients = [c['ip'] for c in parse_scopes_from_tree(r['json'], + 'computer')] + if all(client in server_clients for client in selected_clients): + server = r['server'] + break + + if not server: + raise Exception('Selected clients not found in any server') + + return server + + def get_scopes(ips=set()): list_scopes = [] responses = multi_request('get', '/scopes') @@ -732,8 +749,10 @@ def action_client_info(): if not validate_elements(ips, max_len=1): return redirect(url_for('commands')) + server = get_server_from_clients(list(ips)) + payload = {'client': list(ips)} - r = g.server.get('/client/info', payload) + r = server.get('/client/info', payload) db_client = r.json() form.name.data = db_client['name'] @@ -750,24 +769,24 @@ def action_client_info(): form.room.data = db_client['room'] form.boot.data = db_client['boot'] - r = g.server.get('/oglive/list') + r = server.get('/oglive/list') available_oglives = r.json()['oglive'] for oglive in available_oglives: choice = (oglive.get('directory'), oglive.get('directory')) form.livedir.choices.append(choice) - r = g.server.get('/mode') + r = server.get('/mode') available_modes = [(mode, mode) for mode in r.json()['modes']] form.boot.choices = list(available_modes) - r = g.server.get('/scopes') + r = server.get('/scopes') rooms = parse_scopes_from_tree(r.json(), 'room') rooms = [(room['id'], room['name']) for room in rooms] form.room.choices = list(rooms) form.create.render_kw = {"style": "visibility:hidden;"} - r = g.server.get('/images') + r = server.get('/images') images = r.json()['images'] ip = list(ips)[0] |