mirror of https://git.48k.eu/ogcp
views: cleanup action_setup_modify()
Check form.validate() for errors at the begining of the view handler for an early return in case of error.master
parent
edd44da64c
commit
17644e584e
119
ogcp/views.py
119
ogcp/views.py
|
@ -830,69 +830,72 @@ def action_setup_show():
|
|||
def action_setup_modify():
|
||||
form = SetupForm(request.form)
|
||||
MIN_EFI_SIZE = 500
|
||||
if form.validate():
|
||||
cache_count = 0
|
||||
for partition in form.partitions:
|
||||
if partition.part_type.data == 'CACHE':
|
||||
cache_count += 1
|
||||
if not form.validate():
|
||||
flash(_(f'Invalid setup form'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
if partition.part_type.data == 'EFI' and partition.fs.data != 'FAT32':
|
||||
flash(_('The EFI partition requires a FAT32 filesystem'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
cache_count = 0
|
||||
for partition in form.partitions:
|
||||
if partition.part_type.data == 'CACHE':
|
||||
cache_count += 1
|
||||
|
||||
if partition.part_type.data == 'EFI' and partition.size.data < MIN_EFI_SIZE:
|
||||
flash(_(f'The EFI partition requires a size of {MIN_EFI_SIZE}MiB or higher'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
if partition.size.data <= 0:
|
||||
flash(_('Partitions can\'t have a size of zero or lower'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
if cache_count > 1:
|
||||
flash(_(f'More than one cache partition is not supported'), category='error')
|
||||
if partition.part_type.data == 'EFI' and partition.fs.data != 'FAT32':
|
||||
flash(_('The EFI partition requires a FAT32 filesystem'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
ips = form.ips.data.split(' ')
|
||||
|
||||
payload = {'clients': ips,
|
||||
'disk': str(form.disk.data),
|
||||
'type': str(form.disk_type.data),
|
||||
'cache': str(0),
|
||||
'cache_size': str(0),
|
||||
'partition_setup': []}
|
||||
|
||||
partition_index = 0
|
||||
|
||||
for partition in form.partitions:
|
||||
partition_index += 1
|
||||
partition_setup = {'partition': str(partition_index),
|
||||
'code': str(partition.part_type.data),
|
||||
'filesystem': str(partition.fs.data),
|
||||
'size': str(partition.size.data * 1024),
|
||||
'format': '1'}
|
||||
payload['partition_setup'].append(partition_setup)
|
||||
|
||||
if partition.part_type.data == 'CACHE':
|
||||
payload['cache'] = '1'
|
||||
payload['cache_size'] = str(partition.size.data * 1024)
|
||||
|
||||
for partition_index in range(len(form.partitions) + 1, 5):
|
||||
empty_part = {
|
||||
'partition': str(partition_index),
|
||||
'code': 'EMPTY',
|
||||
'filesystem': 'EMPTY',
|
||||
'size': '0',
|
||||
'format': '1',
|
||||
}
|
||||
payload['partition_setup'].append(empty_part)
|
||||
|
||||
server = get_server_from_clients(list(ips))
|
||||
r = server.post('/setup', payload=payload)
|
||||
if not r:
|
||||
return ogserver_down('commands')
|
||||
if r.status_code == requests.codes.ok:
|
||||
if partition.part_type.data == 'EFI' and partition.size.data < MIN_EFI_SIZE:
|
||||
flash(_(f'The EFI partition requires a size of {MIN_EFI_SIZE}MiB or higher'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
flash(_(f'Invalid setup form'), category='error')
|
||||
|
||||
if partition.size.data <= 0:
|
||||
flash(_('Partitions can\'t have a size of zero or lower'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
if cache_count > 1:
|
||||
flash(_(f'More than one cache partition is not supported'), category='error')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
ips = form.ips.data.split(' ')
|
||||
|
||||
payload = {'clients': ips,
|
||||
'disk': str(form.disk.data),
|
||||
'type': str(form.disk_type.data),
|
||||
'cache': str(0),
|
||||
'cache_size': str(0),
|
||||
'partition_setup': []}
|
||||
|
||||
partition_index = 0
|
||||
|
||||
for partition in form.partitions:
|
||||
partition_index += 1
|
||||
partition_setup = {'partition': str(partition_index),
|
||||
'code': str(partition.part_type.data),
|
||||
'filesystem': str(partition.fs.data),
|
||||
'size': str(partition.size.data * 1024),
|
||||
'format': '1'}
|
||||
payload['partition_setup'].append(partition_setup)
|
||||
|
||||
if partition.part_type.data == 'CACHE':
|
||||
payload['cache'] = '1'
|
||||
payload['cache_size'] = str(partition.size.data * 1024)
|
||||
|
||||
for partition_index in range(len(form.partitions) + 1, 5):
|
||||
empty_part = {
|
||||
'partition': str(partition_index),
|
||||
'code': 'EMPTY',
|
||||
'filesystem': 'EMPTY',
|
||||
'size': '0',
|
||||
'format': '1',
|
||||
}
|
||||
payload['partition_setup'].append(empty_part)
|
||||
|
||||
server = get_server_from_clients(list(ips))
|
||||
r = server.post('/setup', payload=payload)
|
||||
if not r:
|
||||
return ogserver_down('commands')
|
||||
if r.status_code != requests.codes.ok:
|
||||
return ogserver_error(r, 'commands')
|
||||
flash(_(f'Setup command sent sucessfully'), category='info')
|
||||
return redirect(url_for('commands'))
|
||||
|
||||
def search_image(images_list, image_id):
|
||||
|
|
Loading…
Reference in New Issue