VMware: Provide facility to specify path for template (#38031)

When multiple virtual machines or templates are found in environment,
module needs folder path. This fix adds facility to specify folder path
for template or virtual machine if multiples are found.

Fixes: #37087

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/47049/head
Abhijeet Kasurde 6 years ago committed by GitHub
parent 6a1aa51a74
commit ebeb788117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -984,8 +984,16 @@ class PyVmomi(object):
""" """
template_obj = None template_obj = None
if not template_name:
return template_obj
if template_name: if "/" in template_name:
vm_obj_path = os.path.dirname(template_name)
vm_obj_name = os.path.basename(template_name)
template_obj = find_vm_by_id(self.content, vm_obj_name, vm_id_type="inventory_path", folder=vm_obj_path)
if template_obj:
return template_obj
else:
template_obj = find_vm_by_id(self.content, vm_id=template_name, vm_id_type="uuid") template_obj = find_vm_by_id(self.content, vm_id=template_name, vm_id_type="uuid")
if template_obj: if template_obj:
return template_obj return template_obj
@ -1006,6 +1014,7 @@ class PyVmomi(object):
self.module.fail_json(msg="Multiple virtual machines or templates with same name [%s] found." % template_name) self.module.fail_json(msg="Multiple virtual machines or templates with same name [%s] found." % template_name)
elif templates: elif templates:
template_obj = templates[0] template_obj = templates[0]
return template_obj return template_obj
# Cluster related functions # Cluster related functions

@ -89,6 +89,7 @@ options:
- If the virtual machine already exists, this parameter will be ignored. - If the virtual machine already exists, this parameter will be ignored.
- This parameter is case sensitive. - This parameter is case sensitive.
- You can also specify template or VM UUID for identifying source. version_added 2.8. Use C(hw_product_uuid) from M(vmware_guest_facts) as UUID value. - You can also specify template or VM UUID for identifying source. version_added 2.8. Use C(hw_product_uuid) from M(vmware_guest_facts) as UUID value.
- From version 2.8 onwards, absolute path to virtual machine or template can be used.
aliases: [ 'template_src' ] aliases: [ 'template_src' ]
is_template: is_template:
description: description:

Loading…
Cancel
Save