summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-21 14:38:44 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-21 14:38:44 +0200
commite978c30b9ffd60b5c7a8e05cf193c1b11a6f87ba (patch)
tree3d62ee5b99fe731a47fdda136683f5020f3bf487 /ogcp
parent93ffa115fe9dc5efb928232f797fbcacdec494b1 (diff)
Add client hardware action
This action lists all the hardware items in a client.
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/forms/action_forms.py4
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py21
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()