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 2e00731
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sno-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ env:
PULLSECRET: ${{github.event.inputs.PULLSECRET}}
VERSION: ${{github.event.inputs.VERSION}}
TAG: ${{github.event.inputs.TAG}}
MEMORY: ${{github.event.inputs.MEMORY}}
NUMCPUS: ${{github.event.inputs.NUMCPUS}}

jobs:
requirements:
Expand Down
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 2e00731

Please sign in to comment.