mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
VMware: vmware_guest template find (#35088)
This fix adds logic to find unique virtual machine template using name. Fixes: #26669 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -1000,6 +1000,37 @@ class PyVmomi(object):
|
||||
folder_name = '/' + folder_name
|
||||
return folder_name
|
||||
|
||||
def get_vm_or_template(self, template_name=None):
|
||||
"""
|
||||
Function to find the virtual machine or virtual machine template using name
|
||||
used for cloning purpose.
|
||||
Args:
|
||||
template_name: Name of virtual machine or virtual machine template
|
||||
|
||||
Returns: virtual machine or virtual machine template object
|
||||
|
||||
"""
|
||||
template_obj = None
|
||||
|
||||
if template_name:
|
||||
objects = self.get_managed_objects_properties(vim_type=vim.VirtualMachine, properties=['name'])
|
||||
templates = []
|
||||
|
||||
for temp_vm_object in objects:
|
||||
if len(temp_vm_object.propSet) != 1:
|
||||
continue
|
||||
for temp_vm_object_property in temp_vm_object.propSet:
|
||||
if temp_vm_object_property.val == template_name:
|
||||
templates.append(temp_vm_object.obj)
|
||||
break
|
||||
|
||||
if len(templates) > 1:
|
||||
# We have found multiple virtual machine templates
|
||||
self.module.fail_json(msg="Multiple virtual machines or templates with same name [%s] found." % template_name)
|
||||
elif templates:
|
||||
template_obj = templates[0]
|
||||
return template_obj
|
||||
|
||||
# Cluster related functions
|
||||
def find_cluster_by_name(self, cluster_name, datacenter_name=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user