mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Handle errors gracefully in vmware_guest_snapshot (#25727)
CreateSnapshot may fail with several exceptions. This fix generically handles these exceptions. Fixes #21121 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
29f5fe3ddd
commit
ec6e3b0e32
1 changed files with 13 additions and 6 deletions
|
@ -160,9 +160,8 @@ import time
|
|||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.vmware import connect_to_api
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
try:
|
||||
import json
|
||||
|
@ -247,10 +246,18 @@ class PyVmomiHelper(object):
|
|||
if vm.capability.memorySnapshotsSupported:
|
||||
memory_dump = self.module.params['memory_dump']
|
||||
|
||||
return vm.CreateSnapshot(self.module.params["snapshot_name"],
|
||||
self.module.params["description"],
|
||||
memory_dump,
|
||||
quiesce)
|
||||
task = None
|
||||
try:
|
||||
task = vm.CreateSnapshot(self.module.params["snapshot_name"],
|
||||
self.module.params["description"],
|
||||
memory_dump,
|
||||
quiesce)
|
||||
except vim.fault.RestrictedVersion as exc:
|
||||
self.module.fail_json(msg="Failed to take snapshot due to VMware Licence: %s" % to_native(exc.msg))
|
||||
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.msg)))
|
||||
|
||||
return task
|
||||
|
||||
def remove_or_revert_snapshot(self, vm):
|
||||
if vm.snapshot is None:
|
||||
|
|
Loading…
Reference in a new issue