summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/objects/disks.py37
1 files changed, 30 insertions, 7 deletions
diff --git a/cli/objects/disks.py b/cli/objects/disks.py
index f38f420..b832b56 100644
--- a/cli/objects/disks.py
+++ b/cli/objects/disks.py
@@ -37,8 +37,7 @@ class OgDisk():
if len(match.groups()) == 2:
number, unit = match.groups()
return str(int(float(number)*units[unit]))
- print(f'Error parsing size {size}. Aborting.')
- return None
+ raise ValueError(f'error parsing size {size}. Examples of valid sizes: 200M, 2G, 1T')
disk_type_map = {'dos': 'MSDOS', 'gpt': 'GPT'}
part_types = ['LINUX', 'EFI', 'WINDOWS', 'CACHE']
@@ -96,21 +95,45 @@ class OgDisk():
print("Missing --client-ip, or --room-id/--center-id. No clients provided.")
return None
+ if not parsed_args.num.isdigit():
+ print(f'Invalid disk number: must be an integer value')
+ return
+
payload = {'clients': parsed_args.client_ip, 'type': disk_type_map[parsed_args.type], 'disk': str(parsed_args.num),
'cache': '0', 'cache_size': '0', 'partition_setup': []}
+
+ defined_part_indices = set()
for i, p in enumerate(parsed_args.part, start=1):
+
p = p[0]
+
+ if len(p) != 4:
+ print(f'Invalid partition: requires "num,part_scheme,fs,size", "{','.join(p)}" provided')
+ return
part_num, code, fs, size = p[0], p[1].upper(), p[2].upper(), p[3]
+ if not part_num.isdigit():
+ print(f'Invalid partition: the first parameter must be a number, "{part_num}" provided')
+ return
+
+ if part_num in defined_part_indices:
+ print(f'Invalid partition: partition number "{part_num}" has multiple definitions')
+ return
+
+ defined_part_indices.add(part_num)
+
if code not in part_types:
- print(
- f'Specified partition type {code} is not supported. Aborting...')
+ print(f'Invalid partition {i}: specified partition type {code} is not supported. The supported formats are {part_types}')
return
+
if fs not in fs_types:
- print(
- f'Specified filesystem {code} is not supported. Aborting...')
+ print(f'Invalid partition {i}: specified filesystem {fs} is not supported. The supported formats are {fs_types}')
+ return
+ try:
+ size = parse_size(size)
+ except ValueError as error:
+ print(f'Invalid partition {i}: {str(error)}')
return
- size = parse_size(size)
for j in range(i, int(part_num)):
part = {'partition': str(j), 'code': 'EMPTY',