From ea5b22c35e170deff7321abaca5d81cb289c69f7 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Tue, 15 Sep 2020 13:42:28 +0200 Subject: Add delete partition view This view deletes and formats a partition from the selected machine. --- ogcp/views.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'ogcp/views.py') diff --git a/ogcp/views.py b/ogcp/views.py index 13ad3b6..8c14675 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -153,7 +153,38 @@ def action_setup_modify(): @app.route('/action/setup/delete', methods=['POST']) def action_setup_delete(): - return make_response("200 OK", 200) + form = PartitionForm(request.form) + if form.validate(): + ips = form.ips.data.split(' ') + db_partitions = get_client_setup(ips) + + payload = {'clients': ips, + 'disk': str(form.disk.data), + 'cache': str(0), + 'cache_size': str(0), + 'partition_setup': []} + + for db_part in db_partitions: + if db_part['partition'] == 0: + # Skip if this is disk setup. + continue + partition_setup = {'partition': str(db_part['partition']), + 'code': db_part['code'], + 'filesystem': db_part['filesystem'], + 'size': str(db_part['size']), + 'format': str(int(False))} + payload['partition_setup'].append(partition_setup) + + modified_part = payload['partition_setup'][int(form.partition.data) - 1] + modified_part['filesystem'] = FS_CODES[1] + modified_part['code'] = PART_TYPE_CODES[0] + modified_part['size'] = str(0) + modified_part['format'] = str(int(True)) + + 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/reboot', methods=['POST']) def action_reboot(): -- cgit v1.2.3-18-g5258