diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-10-21 14:38:44 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-10-21 14:38:44 +0200 |
commit | e978c30b9ffd60b5c7a8e05cf193c1b11a6f87ba (patch) | |
tree | 3d62ee5b99fe731a47fdda136683f5020f3bf487 /ogcp/views.py | |
parent | 93ffa115fe9dc5efb928232f797fbcacdec494b1 (diff) |
Add client hardware action
This action lists all the hardware items in a client.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 21 |
1 files changed, 20 insertions, 1 deletions
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() |