diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2021-02-17 10:06:10 +0000 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2021-02-17 13:40:06 +0000 |
commit | 20f88065bb79d4c19611873c7b22d57387a32727 (patch) | |
tree | 2639488ef11cfdec95b69e2a51db87e365166523 /ogcp | |
parent | e68eb7a3da8b60b6af1bff0cce74b22fdae26095 (diff) |
Add boot mode to actions
This action is related to /mode in ogServer API. Allows changing
the netboot template for a set of given clients, previously selected
in the /scopes view.
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/forms/action_forms.py | 5 | ||||
-rw-r--r-- | ogcp/templates/actions/mode.html | 13 | ||||
-rw-r--r-- | ogcp/templates/scopes.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 30 |
4 files changed, 49 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index a73b4d1..44e2d58 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -76,6 +76,11 @@ class ClientDetailsForm(FlaskForm): boot = SelectField(label=_('Boot Mode')) create = SubmitField(label=_('Create')) +class BootModeForm(FlaskForm): + ips = HiddenField() + boot = SelectField(label=_('Boot mode')) + ok = SubmitField(label=_('Ok')) + class ImageCreateForm(FlaskForm): ip = HiddenField() os = SelectField(label=_('OS'), choices=[]) diff --git a/ogcp/templates/actions/mode.html b/ogcp/templates/actions/mode.html new file mode 100644 index 0000000..d93e8a7 --- /dev/null +++ b/ogcp/templates/actions/mode.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% block content %} + +{{ wtf.quick_form(form, + action=url_for('action_mode'), + method='post', + button_map={'ok': 'primary'}, + extra_classes="m-5") }} + +{% endblock %} + diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index 8eba78c..879f5f0 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -56,6 +56,8 @@ formaction="{{ url_for('action_client_add') }}" formmethod="get"> <input class="dropdown-item" type="submit" value="{{ _('Create image') }}" formaction="{{ url_for('action_image_create') }}" formmethod="get"> + <input class="dropdown-item" type="submit" value="{{ _('Set boot mode') }}" + formaction="{{ url_for('action_mode') }}" formmethod="get"> </div> </div> </form> diff --git a/ogcp/views.py b/ogcp/views.py index 2635195..37c59db 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -3,7 +3,7 @@ from flask import ( ) from ogcp.forms.action_forms import ( WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm, - ImageRestoreForm, ImageCreateForm, SoftwareForm + ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm ) from ogcp.og_server import OGServer from flask_babel import _ @@ -439,6 +439,34 @@ def action_client_add(): form.create.render_kw = {"formaction": url_for('action_client_add')} return render_template('actions/client_details.html', form=form) +@app.route('/action/mode', methods=['GET', 'POST']) +def action_mode(): + form = BootModeForm(request.form) + if request.method == 'POST': + ips = form.ips.data.split(' ') + payload = { 'clients': ips, 'mode': form.boot.data } + print(payload) + r = g.server.post('/mode', payload) + if r.status_code == requests.codes.ok: + flash(_('Client set boot mode request sent successfully'), category='info') + else: + flash(_('Ogserver replied with status code not ok'), category='error') + return redirect(url_for("scopes")) + + else: + r = g.server.get('/mode') + available_modes = [(mode, mode) for mode in r.json()['modes']] + form.boot.choices = list(available_modes) + + ips = parse_ips(request.args.to_dict()) + form.ips.data = " ".join(ips) + if not validate_ips(ips): + return redirect(url_for("scopes")) + + form.ok.render_kw = { 'formaction': url_for('action_mode') } + return render_template('actions/mode.html', form=form) + + @app.route('/action/image/create', methods=['GET', 'POST']) def action_image_create(): form = ImageCreateForm(request.form) |