Skip to content

Commit

Permalink
VMware: Handle exception gracefully (ansible#36619)
Browse files Browse the repository at this point in the history
This fix adds logic to handle exception raised from conversion of
user parameter 'memory_mb'.

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored and ansibot committed Mar 21, 2018
1 parent 7a4c3e5 commit aadbb6c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/ansible/modules/cloud/vmware/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,12 @@ def configure_cpu_and_memory(self, vm_obj, vm_creation=False):
self.module.fail_json(msg="hardware.num_cpus attribute is mandatory for VM creation")

if 'memory_mb' in self.params['hardware']:
self.configspec.memoryMB = int(self.params['hardware']['memory_mb'])
try:
self.configspec.memoryMB = int(self.params['hardware']['memory_mb'])
except ValueError:
self.module.fail_json(msg="Failed to parse hardware.memory_mb value."
" Please refer the documentation and provide"
" correct value.")
if vm_obj is None or self.configspec.memoryMB != vm_obj.config.hardware.memoryMB:
self.change_detected = True
# memory_mb is mandatory for VM creation
Expand Down

0 comments on commit aadbb6c

Please sign in to comment.