VMware: handle KeyError in get_vm API (#60204)
Fixed if conditions for all VM params
This commit is contained in:
parent
8cbfa75038
commit
0a90ec90c0
2 changed files with 16 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- Fix Key Error in get_vm() api in vmware.py module util (https://github.com/ansible/ansible/issues/60129).
|
|
@ -912,13 +912,14 @@ class PyVmomi(object):
|
|||
vm_obj = None
|
||||
user_desired_path = None
|
||||
use_instance_uuid = self.params.get('use_instance_uuid') or False
|
||||
if self.params['uuid'] and not use_instance_uuid:
|
||||
if 'uuid' in self.params and self.params['uuid']:
|
||||
if not use_instance_uuid:
|
||||
vm_obj = find_vm_by_id(self.content, vm_id=self.params['uuid'], vm_id_type="uuid")
|
||||
elif self.params['uuid'] and use_instance_uuid:
|
||||
elif use_instance_uuid:
|
||||
vm_obj = find_vm_by_id(self.content,
|
||||
vm_id=self.params['uuid'],
|
||||
vm_id_type="instance_uuid")
|
||||
elif self.params['name']:
|
||||
elif 'name' in self.params and self.params['name']:
|
||||
objects = self.get_managed_objects_properties(vim_type=vim.VirtualMachine, properties=['name'])
|
||||
vms = []
|
||||
|
||||
|
@ -984,7 +985,7 @@ class PyVmomi(object):
|
|||
elif vms:
|
||||
# Unique virtual machine found.
|
||||
vm_obj = vms[0]
|
||||
elif self.params['moid']:
|
||||
elif 'moid' in self.params and self.params['moid']:
|
||||
vm_obj = VmomiSupport.templateOf('VirtualMachine')(self.params['moid'], self.si._stub)
|
||||
|
||||
if vm_obj:
|
||||
|
|
Loading…
Reference in a new issue