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.
multi-ogserver
Jose M. Guisado 2021-02-22 12:12:36 +01:00 committed by Jose M. Guisado Gomez
parent 20f88065bb
commit 2b76106475
1 changed files with 31 additions and 13 deletions

View File

@ -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'])