diff options
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/forms/action_forms.py | 4 | ||||
-rw-r--r-- | ogcp/templates/scopes.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 21 |
3 files changed, 26 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index ac761f5..39dae81 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -29,6 +29,10 @@ class PartitionForm(FlaskForm): modify = SubmitField(label=_('Modify')) delete = SubmitField(label=_('Delete')) +class HardwareForm(FlaskForm): + ips = HiddenField() + refresh = SubmitField(label=_('Refresh')) + class ClientDetailsForm(FlaskForm): name = StringField(label=_('Name')) ip = StringField(label=_('IP')) diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index 5b506a6..460fc3e 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -40,6 +40,8 @@ formaction="{{ url_for('action_reboot') }}" formmethod="post"> <input class="dropdown-item" type="submit" value="{{ _('Refresh') }}" formaction="{{ url_for('action_refresh') }}" formmethod="post"> + <input class="dropdown-item" type="submit" value="{{ _('Hardware') }}" + formaction="{{ url_for('action_hardware') }}" formmethod="get"> <input class="dropdown-item" type="submit" value="{{ _('Setup') }}" formaction="{{ url_for('action_setup_show') }}" formmethod="get"> <input class="dropdown-item" type="submit" value="{{ _('Details') }}" diff --git a/ogcp/views.py b/ogcp/views.py index 268eea4..a8add41 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,5 +1,7 @@ from flask import g, render_template, url_for, request, jsonify, make_response -from ogcp.forms.action_forms import WOLForm, PartitionForm, ClientDetailsForm +from ogcp.forms.action_forms import ( + WOLForm, PartitionForm, ClientDetailsForm, HardwareForm +) from ogcp.og_server import OGServer from flask_babel import _ from ogcp import app @@ -195,6 +197,23 @@ def action_setup_delete(): return make_response("200 OK", 200) return make_response("400 Bad Request", 400) +@app.route('/action/hardware', methods=['GET', 'POST']) +def action_hardware(): + form = HardwareForm(request.form) + if request.method == 'POST': + ips = form.ips.data.split(' ') + r = g.server.post('/hardware', payload={'clients': ips}) + 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('/hardware', payload={'client': list(ips)}) + hardware = r.json()['hardware'] + return render_template('actions/hardware.html', form=form, + hardware=hardware) + @app.route('/action/client/info', methods=['GET']) def action_client_info(): form = ClientDetailsForm() |