summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-14 10:56:58 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-14 10:56:58 +0200
commit7815d1fac7392757f057efa25ceee2047403c86c (patch)
treecfa3cac58bd8b2ddc33481482ee491ce5fa56a9c /ogcp/views.py
parent9df3c538f337d9c01b735e141fd2ab040724d73c (diff)
Add partitions setup forms
This provides a menu to setup the internal partitions setup of each machine. Delete partitions is still just a placeholder.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 2bb4713..22ce379 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1,8 +1,9 @@
from flask import g, render_template, url_for, request, jsonify, make_response
-from ogcp.forms.action_forms import WOLForm
+from ogcp.forms.action_forms import WOLForm, PartitionForm
from ogcp.og_server import OGServer
from flask_babel import _
from ogcp import app
+import requests
def parse_ips(checkboxes_dict):
ips = set()
@@ -73,6 +74,60 @@ def action_wol():
form.ips.data = " ".join(ips)
return render_template('actions/wol.html', form=form)
+@app.route('/action/setup', methods=['GET'])
+def action_setup_show():
+ ips = parse_ips(request.args.to_dict())
+ payload = {'client': list(ips)}
+ r = g.server.get('/client/setup', payload)
+ db_partitions = r.json()['partitions']
+ forms = [PartitionForm() for _ in db_partitions]
+ forms = list(forms)
+ for form, db_part in zip(forms, db_partitions):
+ form.ips.data = " ".join(ips)
+ form.disk.data = db_part['disk']
+ form.partition.data = db_part['partition']
+ form.size.data = db_part['size']
+ form.modify.render_kw = {"formaction": url_for('action_setup_modify')}
+ form.delete.render_kw = {"formaction": url_for('action_setup_delete')}
+ return render_template('actions/setup.html', forms=forms)
+
+@app.route('/action/setup/modify', methods=['POST'])
+def action_setup_modify():
+ form = PartitionForm(request.form)
+ if form.validate():
+ ips = form.ips.data.split(' ')
+ r = g.server.get('/client/setup', payload={'client': ips})
+
+ payload = {'clients': ips,
+ 'disk': str(form.disk.data),
+ 'cache': str(0),
+ 'cache_size': str(0),
+ 'partition_setup': []}
+
+ for i in range(1,5):
+ partition_placeholder = {'partition': str(i),
+ 'filesystem': 'EMPTY',
+ 'code': 'EMPTY',
+ 'size': str(0),
+ 'format': str(int(False))}
+ payload['partition_setup'].append(partition_placeholder)
+
+ modified_part = payload['partition_setup'][int(form.partition.data) - 1]
+ modified_part['partition'] = str(form.partition.data)
+ modified_part['filesystem'] = str(form.fs.data)
+ modified_part['code'] = str(form.part_type.data)
+ modified_part['size'] = str(form.size.data)
+ modified_part['format'] = str(int(form.format_partition.data))
+
+ r = g.server.post('/setup', payload=payload)
+ if r.status_code == requests.codes.ok:
+ return make_response("200 OK", 200)
+ return make_response("400 Bad Request", 400)
+
+@app.route('/action/setup/delete', methods=['POST'])
+def action_setup_delete():
+ return make_response("200 OK", 200)
+
@app.route('/action/reboot', methods=['POST'])
def action_reboot():
ips = parse_ips(request.form.to_dict())