summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-02-10 11:22:22 +0100
committerJose M. Guisado <jguisado@soleta.eu>2021-02-10 10:48:01 +0000
commit95b28c9403dc33d64b5aa5ee3f41b98da184c1a1 (patch)
tree788cc496eb71a6b31f937d4379dcf3d0c300ac58 /ogcp/views.py
parentb8ac0b7963faf8c26bf116516f7f8f097cd5e30a (diff)
Add setup modif part scheme param and autofill partition_setup
A new parameter for the setup/ was added: type. Regarding the disk partition scheme. It must be either "MSDOS" or "GPT". ogServer expects a 4 partition setup in order to succesfully execute a setup/ command. Ogcp is currently getting the partition to modify one partition at a time. This patch enables ogcp to "autofill" with empty partitions the partition_setup payload parameter. TODO: In the future, the setup/ logic should not need to query the database once again in order to create the 'partition_setup' payload parameter with the form modifications.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 0b6b320..191d496 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1,4 +1,4 @@
-from flask import g, render_template, url_for, request, jsonify, make_response
+from flask import g, render_template, url_for, redirect, request, jsonify, make_response
from ogcp.forms.action_forms import (
WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm,
ImageRestoreForm, ImageCreateForm, SoftwareForm
@@ -21,9 +21,15 @@ PART_TYPE_CODES = {
1: 'DISK',
7: 'NTFS',
131: 'LINUX',
+ 202: 'CACHE',
218: 'DATA'
}
+PART_SCHEME_CODES = {
+ 1: 'MSDOS',
+ 2: 'GPT'
+}
+
def parse_ips(checkboxes_dict):
ips = set()
for key, ips_list in checkboxes_dict.items():
@@ -36,7 +42,11 @@ def get_client_setup(ip):
r = g.server.get('/client/setup', payload)
db_partitions = r.json()['partitions']
for partition in db_partitions:
- partition['code'] = PART_TYPE_CODES[partition['code']]
+ if partition['partition'] == 0:
+ partition['code'] = PART_SCHEME_CODES[partition['code']]
+ else:
+ partition['code'] = PART_TYPE_CODES[partition['code']]
+
partition['filesystem'] = FS_CODES[partition['filesystem']]
return db_partitions
@@ -116,10 +126,14 @@ def action_setup_show():
db_partitions = get_client_setup(ips)
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']
+ # XXX: Should separate whole disk form from partition setup form
+ if db_part['code'] in PART_SCHEME_CODES.values():
+ form.part_type.choices = list(PART_SCHEME_CODES.values())
form.part_type.data = db_part['code']
form.fs.data = db_part['filesystem']
form.size.data = db_part['size']
@@ -142,7 +156,8 @@ def action_setup_modify():
for db_part in db_partitions:
if db_part['partition'] == 0:
- # Skip if this is disk setup.
+ # Set partition scheme
+ payload['type'] = db_part['code']
continue
partition_setup = {'partition': str(db_part['partition']),
'code': db_part['code'],
@@ -151,6 +166,17 @@ def action_setup_modify():
'format': str(int(False))}
payload['partition_setup'].append(partition_setup)
+ # Ensure a 4 partition setup
+ for i in range(len(db_partitions), 5):
+ empty_part = {
+ 'partition': str(i),
+ 'code': 'EMPTY',
+ 'filesystem': 'EMPTY',
+ 'size': '0',
+ 'format': '0',
+ }
+ payload['partition_setup'].append(empty_part)
+
modified_part = payload['partition_setup'][int(form.partition.data) - 1]
modified_part['filesystem'] = str(form.fs.data)
modified_part['code'] = str(form.part_type.data)
@@ -159,7 +185,7 @@ def action_setup_modify():
r = g.server.post('/setup', payload=payload)
if r.status_code == requests.codes.ok:
- return make_response("200 OK", 200)
+ return redirect(url_for("scopes"))
return make_response("400 Bad Request", 400)
@app.route('/action/setup/delete', methods=['POST'])