mirror of https://git.48k.eu/ogcp
Add partitions setup forms
This provides a menu to setup the internal partitions setup of each machine. Delete partitions is still just a placeholder.multi-ogserver
parent
9df3c538f3
commit
7815d1fac7
|
@ -1,4 +1,6 @@
|
|||
from wtforms import Form, SubmitField, HiddenField, SelectField
|
||||
from wtforms import (
|
||||
Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField
|
||||
)
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_babel import _
|
||||
|
||||
|
@ -8,3 +10,20 @@ class WOLForm(FlaskForm):
|
|||
choices=[('broadcast', 'Broadcast'),
|
||||
('unicast', 'Unicast')])
|
||||
submit = SubmitField(label=_('Submit'))
|
||||
|
||||
class PartitionForm(FlaskForm):
|
||||
ips = HiddenField()
|
||||
disk = HiddenField()
|
||||
partition = HiddenField()
|
||||
part_type = SelectField(label=_('Type'),
|
||||
choices=[('LINUX', 'Linux'),
|
||||
('NTFS', 'NTFS'),
|
||||
('EMPTY', 'Empty')])
|
||||
fs = SelectField(label=_('Filesystem'),
|
||||
choices=[('EXT4', 'EXT4'),
|
||||
('NTFS', 'NTFS'),
|
||||
('EMPTY', 'Empty')])
|
||||
size = IntegerField(label=_('Size (KB)'))
|
||||
format_partition = BooleanField(label=_('Format'))
|
||||
modify = SubmitField(label=_('Modify'))
|
||||
delete = SubmitField(label=_('Delete'))
|
||||
|
|
|
@ -40,7 +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="{{ _('Setup') }}"
|
||||
formaction="{{ url_for('action_setup_show') }}" formmethod="get">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue