diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-10-22 11:04:57 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-10-22 11:04:57 +0200 |
commit | c5a4ccff550ad69c72f4f8aedba4c4a8457e1dfc (patch) | |
tree | cd716807634ff5798c49a8cfad0bf50253117c0d /ogcp/views.py | |
parent | e978c30b9ffd60b5c7a8e05cf193c1b11a6f87ba (diff) |
Add session action
This action provides the functionality to run one of the installed OSs
in a client.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index a8add41..e3f559d 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,6 +1,6 @@ from flask import g, render_template, url_for, request, jsonify, make_response from ogcp.forms.action_forms import ( - WOLForm, PartitionForm, ClientDetailsForm, HardwareForm + WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm ) from ogcp.og_server import OGServer from flask_babel import _ @@ -214,6 +214,29 @@ def action_hardware(): return render_template('actions/hardware.html', form=form, hardware=hardware) +@app.route('/action/session', methods=['GET', 'POST']) +def action_session(): + form = SessionForm(request.form) + if request.method == 'POST': + ips = form.ips.data.split(' ') + disk, partition = form.os.data.split(' ') + r = g.server.post('/session', payload={'clients': ips, + 'disk': str(disk), + 'partition': str(partition)}) + if r.status_code == requests.codes.ok: + return make_response("200 OK", 200) + return make_response("400 Bad Request", 400) + else: + ips = parse_ips(request.args.to_dict()) + form.ips.data = ' '.join(ips) + r = g.server.get('/session', payload={'client': list(ips)}) + sessions = r.json()['sessions'] + for os in sessions: + choice = (f"{os['disk']} {os['partition']}", + f"{os['name']} ({os['disk']},{os['partition']})") + form.os.choices.append(choice) + return render_template('actions/session.html', form=form) + @app.route('/action/client/info', methods=['GET']) def action_client_info(): form = ClientDetailsForm() |