Correct usage of FindByUuid in vmware module util (#26040)

This fix corrects the usage of function FindByUuid by
specifying correct parameter 'uuid' and 'instanceUuid'
as documentation of VMWare's API.

Fixes: #24398, #24835, #25713

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-07-18 17:18:21 +05:30 committed by jctanner
parent c6d012a2eb
commit f5e9d19af7
2 changed files with 10 additions and 4 deletions

View file

@ -182,7 +182,8 @@ def find_vm_by_id(content, vm_id, vm_id_type="vm_name", datacenter=None, cluster
if isinstance(vm, vim.VirtualMachine):
vm = None
elif vm_id_type == 'uuid':
vm = si.FindByUuid(datacenter=datacenter, instanceUuid=vm_id, vmSearch=True)
# Search By BIOS UUID rather than instance UUID
vm = si.FindByUuid(datacenter=datacenter, instanceUuid=False, uuid=vm_id, vmSearch=True)
elif vm_id_type == 'ip':
vm = si.FindByIp(datacenter=datacenter, ip=vm_id, vmSearch=True)
elif vm_id_type == 'vm_name':

View file

@ -41,7 +41,6 @@ options:
name:
description:
- Name of the VM to work with
required: True
name_match:
description:
- If multiple VMs matching the name, use the first or last found
@ -168,13 +167,14 @@ def main():
default=os.environ.get('VMWARE_PASSWORD')
),
validate_certs=dict(required=False, type='bool', default=True),
name=dict(required=True, type='str'),
name=dict(required=False, type='str'),
name_match=dict(required=False, type='str', default='first'),
uuid=dict(required=False, type='str'),
folder=dict(required=False, type='str', default='/vm'),
datacenter=dict(required=True, type='str'),
),
required_together=[('name', 'folder')],
required_one_of=[['name', 'uuid']],
)
# FindByInventoryPath() does not require an absolute path
@ -194,7 +194,12 @@ def main():
except Exception as exc:
module.fail_json(msg="Fact gather failed with exception %s" % to_text(exc))
else:
module.fail_json(msg="Unable to gather facts for non-existing VM %(name)s" % module.params)
msg = "Unable to gather facts for non-existing VM "
if module.params['name']:
msg += "%(name)s" % module.params
elif module.params['uuid']:
msg += "%(uuid)s" % module.params
module.fail_json(msg=msg)
if __name__ == '__main__':
main()