summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-10-28 10:38:24 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2021-11-02 16:24:18 +0100
commitcbeafea273906d55b01d37b2803af189d6813d2d (patch)
treebc96c8c6c8080ba36096735873f8bac6c3cd6c83 /ogcp
parent20a94dbc3e3e6e36655982a5569a6d7e4d0abedd (diff)
Support partition of computers with several disks
Add a new select input and button to choose which disk you want to partition. TODO: Current argument parsing function returns a list with all the arguments, except csrf_token. Future patches should add granular parsing of different types of arguments.
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/templates/actions/setup.html11
-rw-r--r--ogcp/views.py32
2 files changed, 33 insertions, 10 deletions
diff --git a/ogcp/templates/actions/setup.html b/ogcp/templates/actions/setup.html
index c1633c6..a2f71f9 100644
--- a/ogcp/templates/actions/setup.html
+++ b/ogcp/templates/actions/setup.html
@@ -53,6 +53,17 @@
</table>
</form>
+<select form="scopesForm" name="disk" >
+ {% for disk in disks %}
+ <option {% if disk == selected_disk %}selected{% endif %}
+ value="{{ disk }}">{{ disk }}</option>
+ {% endfor %}
+</select>
+<button class="btn btn-dark" form="scopesForm" formmethod="get"
+ formaction="{{ url_for('action_setup_show') }}">
+ {{ _('Change disk') }}
+</button>
+
<button class="btn btn-primary" data-target="#partitionsTable" onclick="AddPartition(this)">
{{ _('Add a new partition') }}
</button>
diff --git a/ogcp/views.py b/ogcp/views.py
index 525532f..5310376 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -256,33 +256,45 @@ def action_wol():
@app.route('/action/setup', methods=['GET'])
@login_required
-def action_setup_show(ips=None):
- if not ips:
- ips = parse_elements(request.args.to_dict())
+def action_setup_show():
+ args = request.args.copy()
+
+ default_disk = 1
+ selected_disk = int(args.pop('disk', default_disk))
+
+ ips = parse_elements(args.to_dict())
if not validate_elements(ips):
return redirect(url_for('commands'))
db_partitions = get_client_setup(ips)
- form = SetupForm()
+ filtered_partitions = [p for p in db_partitions
+ if p.get('disk') == selected_disk]
+
+ disk_partition = 0
+ disks = [d.get('disk') for d in db_partitions
+ if d.get('partition') == disk_partition]
+ form = SetupForm()
form.ips.data = " ".join(ips)
- form.disk.data = db_partitions[0]['disk']
+ form.disk.data = selected_disk
# If partition table is empty, set MSDOS
- form.disk_type.data = db_partitions[0]['code'] or 1
+ form.disk_type.data = filtered_partitions[0]['code'] or 1
- disk_size = db_partitions[0]['size']
+ disk_size = filtered_partitions[0]['size']
- # Make form.partition length equal to (db_partitions - 1) length
- diff = len(db_partitions) - 1 - len(form.partitions)
+ # Make form.partition length equal to (filtered_partitions - 1) length
+ diff = len(filtered_partitions) - 1 - len(form.partitions)
[form.partitions.append_entry() for _ in range(diff)]
- for partition, db_part in zip(form.partitions, db_partitions[1:]):
+ for partition, db_part in zip(form.partitions, filtered_partitions[1:]):
partition.partition.data = str(db_part['partition'])
partition.part_type.data = db_part['code']
partition.fs.data = db_part['filesystem']
partition.size.data = db_part['size']
scopes, _clients = get_scopes(ips)
return render_template('actions/setup.html',
+ selected_disk=selected_disk,
+ disks=disks,
form=form,
disk_size=disk_size,
scopes=scopes)