summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-02-22 12:12:36 +0100
committerJose M. Guisado Gomez <guigom@riseup.net>2021-02-22 14:25:29 +0100
commit2b761064753d03f26593efe33797e9d2e9c676b3 (patch)
tree0a1cb63043ce55a5b092d089be079bc79821ebd8 /ogcp/views.py
parent20f88065bb79d4c19611873c7b22d57387a32727 (diff)
Add multiple ip handling to image restore form
This patch enables a set of ips to be specified as a target of an image restore action. The set of selected computers must have the same partition setup in order for the form to be rendered sucessfully, if different partition setups are detected a redirection is made and an error flash message is shown.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 37c59db..339e335 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -273,25 +273,43 @@ def action_image_restore():
return make_response("400 Bad Request", 400)
else:
ips = parse_ips(request.args.to_dict())
+ if not validate_ips(ips):
+ return redirect(url_for('scopes'))
form.ips.data = ' '.join(ips)
+
+ part_choices = []
+
r = g.server.get('/images')
for image in r.json()['images']:
form.image.choices.append((image['id'], image['name']))
- r = g.server.get('/client/setup', payload={'client': list(ips)})
- for partition in r.json()['partitions']:
- disk_id = partition['disk']
- part_id = partition['partition']
- fs_id = partition['filesystem']
- if part_id == 0:
- # This is the disk data, not a partition.
- continue
+ for ip in ips:
+ r = g.server.get('/client/setup', payload={'client': [ip]})
+ if r.status_code == requests.codes.ok:
+ partitions = r.json()['partitions']
+ parts = []
+ for partition in partitions:
+ disk_id = partition['disk']
+ part_id = partition['partition']
+ if part_id == 0: # This is the disk data, not a partition.
+ continue
+
+ choice_value = (disk_id, part_id)
+ parts.append(choice_value)
+
+ if not part_choices: # Use first computer as reference part setup conf
+ part_choices = [part for part in parts]
+ elif part_choices != parts:
+ flash(_(f'Computers have different partition setup'), category='error')
+ return redirect(url_for("scopes"))
+
+ else:
+ flash(_(f'ogServer was unable to obtain setup of selected computer {ip}'), category='error')
+ return redirect(url_for("scopes"))
+
+ form.partition.choices = [ (f'{disk_id} {part_id}', _(f'Disk: {disk_id} | Part: {part_id}'))
+ for disk_id, part_id in part_choices ]
- choice_value = f"{disk_id} {part_id}"
- choice_name = (f"{_('Disk')} {disk_id} - "
- f"{_('Partition')} {part_id} - "
- f"{_('FS')} {FS_CODES[fs_id]}")
- form.partition.choices.append((choice_value, choice_name))
return render_template('actions/image_restore.html', form=form)
@app.route('/action/hardware', methods=['GET', 'POST'])