mirror of https://git.48k.eu/ogcp
views: check cache presence in tiptorrent and unicast restore
Ensure a cache partition is present before trying to do a UNICAST or TIPTORRENT image restore. Inform the user about the lack of cache in such case.master
parent
81c4c73498
commit
95b2e20015
|
@ -747,7 +747,7 @@ def action_image_restore():
|
|||
form = ImageRestoreForm(request.form)
|
||||
if request.method == 'POST':
|
||||
ips = form.ips.data.split(' ')
|
||||
disk, partition, part_code, part_size = form.partition.data.split(' ')
|
||||
disk, partition, part_code, part_size, has_cache = form.partition.data.split(' ')
|
||||
|
||||
part_type = PART_TYPE_CODES.get(int(part_code), 'UNKNOWN')
|
||||
invalid_part_types = ['EMPTY', 'LINUX-SWAP', 'CACHE', 'EFI', 'WIN-RECOV']
|
||||
|
@ -755,6 +755,11 @@ def action_image_restore():
|
|||
flash(_(f'Cannot restore image on partition type {part_type}'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
requires_cache = form.method.data == 'TIPTORRENT' or form.method.data == 'UNICAST'
|
||||
if has_cache == 'False' and requires_cache:
|
||||
flash(_(f'Cannot restore image using {form.method.data} on a client without cache'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
image_id = form.image.data
|
||||
server = get_server_from_clients(ips)
|
||||
r = server.get('/images')
|
||||
|
@ -827,6 +832,7 @@ def action_image_restore():
|
|||
for image in images[repo_id]:
|
||||
form.image.choices.append((image['id'], image['name']))
|
||||
|
||||
has_cache = False
|
||||
part_choices = []
|
||||
for ip in ips:
|
||||
r = server.get('/client/setup', payload={'client': [ip]})
|
||||
|
@ -843,6 +849,8 @@ def action_image_restore():
|
|||
if part_id == 0: # This is the disk data, not a partition.
|
||||
continue
|
||||
part_code = partition['code']
|
||||
if part_code == 'CACHE':
|
||||
has_cache = True
|
||||
filesystem = partition['filesystem']
|
||||
part_size = partition['size']
|
||||
|
||||
|
@ -856,7 +864,7 @@ def action_image_restore():
|
|||
return redirect(url_for('commands'))
|
||||
|
||||
form.partition.choices = [
|
||||
(f"{disk_id} {part_id} {part_code} {part_size}",
|
||||
(f"{disk_id} {part_id} {part_code} {part_size} {has_cache}",
|
||||
f"Disk {disk_id} | Partition {part_id} "
|
||||
f"| {PART_TYPE_CODES.get(part_code, 'UNKNOWN')} "
|
||||
f"{FS_CODES.get(filesystem, 'UNKNOWN')}")
|
||||
|
|
Loading…
Reference in New Issue