Skip to content

Commit

Permalink
automaticallly convert numcpus and memory when provided as string
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Mar 20, 2024
1 parent 5a5cf63 commit 823c38f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions kvirt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,14 +1533,16 @@ def create_vm(args):
for key in overrides:
if key in vars(config) and vars(config)[key] is not None and type(overrides[key]) != type(vars(config)[key]):
key_type = str(type(vars(config)[key]))
if key == 'memory' and isinstance(overrides[key], str) and\
(overrides[key].lower().endswith('gb') or overrides[key].lower().endswith('g')):
memory = overrides['memory'].lower().replace('gb', '').replace('g', '')
try:
key_value = overrides[key]
if key == 'memory' and isinstance(key_value, str):
memory = key_value.lower().replace('gb', '').replace('g', '')
if memory.isnumeric():
overrides['memory'] = int(memory) * 1024
except:
error("Couldnt convert memory")
else:
error("Wrong memory {memory}")
sys.exit(1)
elif key == 'numcpus' and isinstance(key_value, str) and key_value.isnumeric():
overrides['numcpus'] = int(key_value)
else:
error(f"The provided parameter {key} has a wrong type, it should be {key_type}")
sys.exit(1)
Expand Down

0 comments on commit 823c38f

Please sign in to comment.