summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-07 10:52:54 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-07 14:35:41 +0200
commit95b2e2001541a9cf655cab07b0c9062ce26214c0 (patch)
treedac94628d16e9c4cc1282a60940f117f1dc303bd /ogcp/views.py
parent81c4c73498053c8d3c1673b2cbdf153c97cf1dc7 (diff)
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.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 60afbd3..bd74515 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -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')}")