Created option snapshot_to_clone. When specified, snapshot_to_clone will create a linked clone copy of the VM.

reviewable/pr18780/r1
Nicholas O'Connor 9 years ago
parent 706f5e25cc
commit 9144785c42

@ -79,16 +79,10 @@ options:
description:
- Name of the source template to deploy from
default: None
linked_clone:
version_added: "2.0"
snapshot_to_clone:
version_added 2.0
description:
- Boolean. Creates a linked clone copy of the specified vm requires snapshot
required: false
default: false
snapshot:
version_added: "2.0"
description:
- Name of the snapshot you want to link clone from
- String. When specified, snapshot_to_clone will create a linked clone copy of the VM, Snapshot must already be taken in vCenter.
required: false
default: none
vm_disk:
@ -525,7 +519,7 @@ def vmdisk_id(vm, current_datastore_name):
return id_list
def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, module, cluster_name, linked_clone, snapshot):
def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, module, cluster_name, snapshot_to_clone):
vmTemplate = vsphere_client.get_vm_by_name(template_src)
vmTarget = None
@ -557,9 +551,9 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
try:
if vmTarget:
changed = False
elif linked_clone and snapshot != None:
#Check linked_clone and snapshot value
vmTemplate.clone(guest, resourcepool=rpmor, linked=linked_clone, snapshot=snapshot)
elif snapshot_to_clone != None:
#check if snapshot_to_clone is specified, Create a Linked Clone instead of a full clone.
vmTemplate.clone(guest, resourcepool=rpmor, linked=True, snapshot=snapshot_to_clone)
changed = True
else:
vmTemplate.clone(guest, resourcepool=rpmor)
@ -1168,8 +1162,7 @@ def main():
vmware_guest_facts=dict(required=False, type='bool'),
from_template=dict(required=False, type='bool'),
template_src=dict(required=False, type='str'),
linked_clone=dict(required=False, default=False, type='bool'),
snapshot=dict(required=False, default=None, type='str'),
snapshot_to_clone=dict(required=False, default=None, type='str'),
guest=dict(required=True, type='str'),
vm_disk=dict(required=False, type='dict', default={}),
vm_nic=dict(required=False, type='dict', default={}),
@ -1197,7 +1190,6 @@ def main():
['resource_pool', 'cluster'],
['from_template', 'resource_pool', 'template_src'],
],
required_if=[('linked_clone', True, ['snapshot'])],
)
if not HAS_PYSPHERE:
@ -1220,8 +1212,7 @@ def main():
cluster = module.params['cluster']
template_src = module.params['template_src']
from_template = module.params['from_template']
linked_clone = module.params['linked_clone']
snapshot = module.params['snapshot']
snapshot_to_clone = module.params['snapshot_to_clone']
# CONNECT TO THE SERVER
@ -1303,8 +1294,7 @@ def main():
template_src=template_src,
module=module,
cluster_name=cluster,
linked_clone=linked_clone,
snapshot=snapshot
snapshot_to_clone=snapshot_to_clone
)
if state in ['restarted', 'reconfigured']:
module.fail_json(

Loading…
Cancel
Save