VMware: Documentation update vmware_guest_snapshot (#38083)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/38369/head
Abhijeet Kasurde 7 years ago committed by ansibot
parent 1f3b480142
commit f355eb621a

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# # Copyright: (c) 2018, Ansible Project
# This module is also sponsored by E.T.A.I. (www.etai.fr) # This module is also sponsored by E.T.A.I. (www.etai.fr)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
@ -16,41 +16,50 @@ DOCUMENTATION = '''
module: vmware_guest_snapshot module: vmware_guest_snapshot
short_description: Manages virtual machines snapshots in vCenter short_description: Manages virtual machines snapshots in vCenter
description: description:
- Create virtual machines snapshots - This module can be used to create, delete and update snapshot(s) of the given virtual machine.
- All parameters and VMware object names are case sensitive.
version_added: 2.3 version_added: 2.3
author: author:
- James Tanner (@jctanner) <tanner.jc@gmail.com> - James Tanner (@jctanner) <tanner.jc@gmail.com>
- Loic Blot (@nerzhul) <loic.blot@unix-experience.fr> - Loic Blot (@nerzhul) <loic.blot@unix-experience.fr>
notes: notes:
- Tested on vSphere 5.5, 6.0 - Tested on vSphere 5.5, 6.0 and 6.5
requirements: requirements:
- "python >= 2.6" - "python >= 2.6"
- PyVmomi - PyVmomi
options: options:
state: state:
description: description:
- Manage snapshots attached to a specific virtual machine. - Manage snapshot(s) attached to a specific virtual machine.
- If set to C(present) and snapshot absent, then will create a new snapshot with the given name.
- If set to C(present) and snapshot present, then no changes are made.
- If set to C(absent) and snapshot present, then snapshot with the given name is removed.
- If set to C(absent) and snapshot absent, then no changes are made.
- If set to C(revert) and snapshot present, then virtual machine state is reverted to the given snapshot.
- If set to C(revert) and snapshot absent, then no changes are made.
- If set to C(remove_all) and snapshot(s) present, then all snapshot(s) will be removed.
- If set to C(remove_all) and snapshot(s) absent, then no changes are made.
required: True required: True
choices: ['present', 'absent', 'revert', 'remove_all'] choices: ['present', 'absent', 'revert', 'remove_all']
default: 'present' default: 'present'
name: name:
description: description:
- Name of the VM to work with - Name of the virtual machine to work with.
- This is required if uuid is not supplied. - This is required parameter, if C(uuid) is not supplied.
name_match: name_match:
description: description:
- If multiple VMs matching the name, use the first or last found - If multiple VMs matching the name, use the first or last found.
default: 'first' default: 'first'
choices: ['first', 'last'] choices: ['first', 'last']
uuid: uuid:
description: description:
- UUID of the instance to manage if known, this is VMware's unique identifier. - UUID of the instance to manage if known, this is VMware's unique identifier.
- This is required if name is not supplied. - This is required parameter, if C(name) is not supplied.
folder: folder:
description: description:
- Destination folder, absolute or relative path to find an existing guest. - Destination folder, absolute or relative path to find an existing guest.
- This is required if name is supplied. - This is required parameter, if C(name) is supplied.
- The folder should include the datacenter. ESX's datacenter is ha-datacenter - The folder should include the datacenter. ESX's datacenter is ha-datacenter.
- 'Examples:' - 'Examples:'
- ' folder: /ha-datacenter/vm' - ' folder: /ha-datacenter/vm'
- ' folder: ha-datacenter/vm' - ' folder: ha-datacenter/vm'
@ -65,7 +74,7 @@ options:
- ' folder: folder2' - ' folder: folder2'
datacenter: datacenter:
description: description:
- Destination datacenter for the deploy operation - Destination datacenter for the deploy operation.
required: True required: True
snapshot_name: snapshot_name:
description: description:
@ -77,13 +86,10 @@ options:
default: '' default: ''
quiesce: quiesce:
description: description:
- If set to C(true) and virtual machine is powered on, it will quiesce the - If set to C(true) and virtual machine is powered on, it will quiesce the file system in virtual machine.
file system in virtual machine.
- Note that VMWare Tools are required for this flag. - Note that VMWare Tools are required for this flag.
- If virtual machine is powered off or VMware Tools are not available, then - If virtual machine is powered off or VMware Tools are not available, then this flag is set to C(false).
this flag is set to C(false). - If virtual machine does not provide capability to take quiesce snapshot, then this flag is set to C(false).
- If virtual machine does not provide capability to take quiesce snapshot, then
this flag is set to C(false).
required: False required: False
version_added: "2.4" version_added: "2.4"
type: bool type: bool
@ -92,33 +98,31 @@ options:
description: description:
- If set to C(true), memory dump of virtual machine is also included in snapshot. - If set to C(true), memory dump of virtual machine is also included in snapshot.
- Note that memory snapshots take time and resources, this will take longer time to create. - Note that memory snapshots take time and resources, this will take longer time to create.
- If virtual machine does not provide capability to take memory snapshot, then - If virtual machine does not provide capability to take memory snapshot, then this flag is set to C(false).
this flag is set to C(false).
required: False required: False
version_added: "2.4" version_added: "2.4"
type: bool type: bool
default: False default: False
remove_children: remove_children:
description: description:
- If set to C(true) and state is set to C(absent), then entire snapshot subtree is set - If set to C(true) and state is set to C(absent), then entire snapshot subtree is set for removal.
for removal.
required: False required: False
version_added: "2.4" version_added: "2.4"
type: bool type: bool
default: False default: False
new_snapshot_name: new_snapshot_name:
description: description:
- Value to rename the existing snapshot to - Value to rename the existing snapshot to.
version_added: 2.5 version_added: "2.5"
new_description: new_description:
description: description:
- Value to change the description of an existing snapshot to - Value to change the description of an existing snapshot to.
version_added: 2.5 version_added: "2.5"
extends_documentation_fragment: vmware.documentation extends_documentation_fragment: vmware.documentation
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: Create snapshot - name: Create a snapshot
vmware_guest_snapshot: vmware_guest_snapshot:
hostname: 192.168.1.209 hostname: 192.168.1.209
username: administrator@vsphere.local username: administrator@vsphere.local
@ -139,7 +143,7 @@ EXAMPLES = '''
name: dummy_vm name: dummy_vm
datacenter: datacenter_name datacenter: datacenter_name
folder: /myfolder folder: /myfolder
state: remove state: absent
snapshot_name: snap1 snapshot_name: snap1
delegate_to: localhost delegate_to: localhost
@ -184,7 +188,7 @@ EXAMPLES = '''
username: administrator@vsphere.local username: administrator@vsphere.local
password: vmware password: vmware
name: dummy_vm name: dummy_vm
state: remove state: absent
remove_children: True remove_children: True
snapshot_name: snap1 snapshot_name: snap1
delegate_to: localhost delegate_to: localhost
@ -204,7 +208,7 @@ EXAMPLES = '''
RETURN = """ RETURN = """
instance: instance:
description: metadata about the new virtualmachine description: metadata about the new virtual machine snapshot
returned: always returned: always
type: dict type: dict
sample: None sample: None
@ -267,15 +271,17 @@ class PyVmomiHelper(PyVmomi):
memory_dump, memory_dump,
quiesce) quiesce)
except vim.fault.RestrictedVersion as exc: except vim.fault.RestrictedVersion as exc:
self.module.fail_json(msg="Failed to take snapshot due to VMware Licence: %s" % to_native(exc.msg)) self.module.fail_json(msg="Failed to take snapshot due to VMware Licence"
" restriction : %s" % to_native(exc.msg))
except Exception as exc: except Exception as exc:
self.module.fail_json(msg="Failed to create snapshot of VM %s due to %s" % (self.module.params['name'], to_native(exc))) self.module.fail_json(msg="Failed to create snapshot of virtual machine"
" %s due to %s" % (self.module.params['name'], to_native(exc)))
return task return task
def rename_snapshot(self, vm): def rename_snapshot(self, vm):
if vm.snapshot is None: if vm.snapshot is None:
self.module.exit_json(msg="VM - %s doesn't have any snapshots" % self.module.exit_json(msg="virtual machine - %s doesn't have any"
self.module.params.get('uuid') or self.module.params.get('name')) " snapshots" % (self.module.params.get('uuid') or self.module.params.get('name')))
snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList, snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList,
self.module.params["snapshot_name"]) self.module.params["snapshot_name"])
@ -298,8 +304,8 @@ class PyVmomiHelper(PyVmomi):
def remove_or_revert_snapshot(self, vm): def remove_or_revert_snapshot(self, vm):
if vm.snapshot is None: if vm.snapshot is None:
self.module.exit_json(msg="VM - %s doesn't have any snapshots" % self.module.exit_json(msg="virtual machine - %s doesn't have any"
self.module.params.get('uuid') or self.module.params.get('name')) " snapshots" % (self.module.params.get('uuid') or self.module.params.get('name')))
snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList, snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList,
self.module.params["snapshot_name"]) self.module.params["snapshot_name"])
@ -313,9 +319,8 @@ class PyVmomiHelper(PyVmomi):
elif self.module.params["state"] == "revert": elif self.module.params["state"] == "revert":
task = snap_obj.RevertToSnapshot_Task() task = snap_obj.RevertToSnapshot_Task()
else: else:
self.module.exit_json( self.module.exit_json(msg="Couldn't find any snapshots with"
msg="Couldn't find any snapshots with specified name: %s on VM: %s" % " specified name: %s on VM: %s" % (self.module.params["snapshot_name"],
(self.module.params["snapshot_name"],
self.module.params.get('uuid') or self.module.params.get('name'))) self.module.params.get('uuid') or self.module.params.get('name')))
return task return task

Loading…
Cancel
Save