Merge pull request #2196 from fennm/vmware_clone_to_folder

Support cloning VMs into a specific VM folder
This commit is contained in:
Chrrrles Paul 2015-12-11 09:52:42 -05:00
commit a56d652c7b

View file

@ -170,6 +170,7 @@ EXAMPLES = '''
vcpu.hotadd: yes vcpu.hotadd: yes
mem.hotadd: yes mem.hotadd: yes
notes: This is a test VM notes: This is a test VM
folder: MyFolder
vm_disk: vm_disk:
disk1: disk1:
size_gb: 10 size_gb: 10
@ -241,6 +242,8 @@ EXAMPLES = '''
template_src: centosTemplate template_src: centosTemplate
cluster: MainCluster cluster: MainCluster
resource_pool: "/Resources" resource_pool: "/Resources"
vm_extra_config:
folder: MyFolder
# Task to gather facts from a vSphere cluster only if the system is a VMWare guest # Task to gather facts from a vSphere cluster only if the system is a VMWare guest
@ -597,7 +600,7 @@ def vmdisk_id(vm, current_datastore_name):
return id_list return id_list
def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, module, cluster_name, snapshot_to_clone, power_on_after_clone): def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, module, cluster_name, snapshot_to_clone, power_on_after_clone, vm_extra_config):
vmTemplate = vsphere_client.get_vm_by_name(template_src) vmTemplate = vsphere_client.get_vm_by_name(template_src)
vmTarget = None vmTarget = None
@ -689,6 +692,10 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
cloneArgs["linked"] = True cloneArgs["linked"] = True
cloneArgs["snapshot"] = snapshot_to_clone cloneArgs["snapshot"] = snapshot_to_clone
if vm_extra_config.get("folder") is not None:
# if a folder is specified, clone the VM into it
cloneArgs["folder"] = vm_extra_config.get("folder")
vmTemplate.clone(guest, **cloneArgs) vmTemplate.clone(guest, **cloneArgs)
changed = True changed = True
else: else:
@ -1625,7 +1632,8 @@ def main():
module=module, module=module,
cluster_name=cluster, cluster_name=cluster,
snapshot_to_clone=snapshot_to_clone, snapshot_to_clone=snapshot_to_clone,
power_on_after_clone=power_on_after_clone power_on_after_clone=power_on_after_clone,
vm_extra_config=vm_extra_config
) )
if state in ['restarted', 'reconfigured']: if state in ['restarted', 'reconfigured']: