Created option snapshot_to_clone. When specified, snapshot_to_clone will create a linked clone copy of the VM.
This commit is contained in:
parent
1f35e578b4
commit
b95cb3f4e9
1 changed files with 10 additions and 20 deletions
|
@ -79,16 +79,10 @@ options:
|
||||||
description:
|
description:
|
||||||
- Name of the source template to deploy from
|
- Name of the source template to deploy from
|
||||||
default: None
|
default: None
|
||||||
linked_clone:
|
snapshot_to_clone:
|
||||||
version_added: "2.0"
|
version_added 2.0
|
||||||
description:
|
description:
|
||||||
- Boolean. Creates a linked clone copy of the specified vm requires snapshot
|
- 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: false
|
|
||||||
snapshot:
|
|
||||||
version_added: "2.0"
|
|
||||||
description:
|
|
||||||
- Name of the snapshot you want to link clone from
|
|
||||||
required: false
|
required: false
|
||||||
default: none
|
default: none
|
||||||
vm_disk:
|
vm_disk:
|
||||||
|
@ -535,7 +529,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, 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)
|
vmTemplate = vsphere_client.get_vm_by_name(template_src)
|
||||||
vmTarget = None
|
vmTarget = None
|
||||||
|
|
||||||
|
@ -619,9 +613,9 @@ def deploy_template(vsphere_client, guest, resource_pool, template_src, esxi, mo
|
||||||
try:
|
try:
|
||||||
if vmTarget:
|
if vmTarget:
|
||||||
changed = False
|
changed = False
|
||||||
elif linked_clone and snapshot != None:
|
elif snapshot_to_clone != None:
|
||||||
#Check linked_clone and snapshot value
|
#check if snapshot_to_clone is specified, Create a Linked Clone instead of a full clone.
|
||||||
vmTemplate.clone(guest, resourcepool=rpmor, linked=linked_clone, snapshot=snapshot)
|
vmTemplate.clone(guest, resourcepool=rpmor, linked=True, snapshot=snapshot_to_clone)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
vmTemplate.clone(guest, resourcepool=rpmor)
|
vmTemplate.clone(guest, resourcepool=rpmor)
|
||||||
|
@ -1231,8 +1225,7 @@ def main():
|
||||||
vmware_guest_facts=dict(required=False, type='bool'),
|
vmware_guest_facts=dict(required=False, type='bool'),
|
||||||
from_template=dict(required=False, type='bool'),
|
from_template=dict(required=False, type='bool'),
|
||||||
template_src=dict(required=False, type='str'),
|
template_src=dict(required=False, type='str'),
|
||||||
linked_clone=dict(required=False, default=False, type='bool'),
|
snapshot_to_clone=dict(required=False, default=None, type='str'),
|
||||||
snapshot=dict(required=False, default=None, type='str'),
|
|
||||||
guest=dict(required=True, type='str'),
|
guest=dict(required=True, type='str'),
|
||||||
vm_disk=dict(required=False, type='dict', default={}),
|
vm_disk=dict(required=False, type='dict', default={}),
|
||||||
vm_nic=dict(required=False, type='dict', default={}),
|
vm_nic=dict(required=False, type='dict', default={}),
|
||||||
|
@ -1260,7 +1253,6 @@ def main():
|
||||||
['resource_pool', 'cluster'],
|
['resource_pool', 'cluster'],
|
||||||
['from_template', 'resource_pool', 'template_src'],
|
['from_template', 'resource_pool', 'template_src'],
|
||||||
],
|
],
|
||||||
required_if=[('linked_clone', True, ['snapshot'])],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_PYSPHERE:
|
if not HAS_PYSPHERE:
|
||||||
|
@ -1283,8 +1275,7 @@ def main():
|
||||||
cluster = module.params['cluster']
|
cluster = module.params['cluster']
|
||||||
template_src = module.params['template_src']
|
template_src = module.params['template_src']
|
||||||
from_template = module.params['from_template']
|
from_template = module.params['from_template']
|
||||||
linked_clone = module.params['linked_clone']
|
snapshot_to_clone = module.params['snapshot_to_clone']
|
||||||
snapshot = module.params['snapshot']
|
|
||||||
|
|
||||||
|
|
||||||
# CONNECT TO THE SERVER
|
# CONNECT TO THE SERVER
|
||||||
|
@ -1366,8 +1357,7 @@ def main():
|
||||||
template_src=template_src,
|
template_src=template_src,
|
||||||
module=module,
|
module=module,
|
||||||
cluster_name=cluster,
|
cluster_name=cluster,
|
||||||
linked_clone=linked_clone,
|
snapshot_to_clone=snapshot_to_clone
|
||||||
snapshot=snapshot
|
|
||||||
)
|
)
|
||||||
if state in ['restarted', 'reconfigured']:
|
if state in ['restarted', 'reconfigured']:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
|
|
Loading…
Reference in a new issue