Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details about snapshot in result #32730

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,15 @@

import time

HAS_PYVMOMI = False
try:
import pyVmomi
from pyVmomi import vim

HAS_PYVMOMI = True
except ImportError:
pass

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.vmware import connect_to_api, vmware_argument_spec, find_vm_by_id
from ansible.module_utils.vmware import connect_to_api, find_vm_by_id, HAS_PYVMOMI, list_snapshots, vmware_argument_spec


class PyVmomiHelper(object):
Expand Down Expand Up @@ -277,7 +274,7 @@ def snapshot_vm(self, vm):
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)))
self.module.fail_json(msg="Failed to create snapshot of VM %s due to %s" % (self.module.params['name'], to_native(exc)))

return task

Expand Down Expand Up @@ -352,7 +349,7 @@ def apply_snapshot_op(self, vm):
if task.info.state == 'error':
result = {'changed': False, 'failed': True, 'msg': task.info.error.msg}
else:
result = {'changed': True, 'failed': False}
result = {'changed': True, 'failed': False, 'results': list_snapshots(vm)}

return result

Expand Down Expand Up @@ -388,10 +385,8 @@ def main():

if not vm:
# If UUID is set, getvm select UUID, show error message accordingly.
if module.params['uuid'] is not None:
module.fail_json(msg="Unable to manage snapshots for non-existing VM %(uuid)s" % module.params)
else:
module.fail_json(msg="Unable to manage snapshots for non-existing VM %(name)s" % module.params)
module.fail_json(msg="Unable to manage snapshots for non-existing VM %s" % (module.params.get('uuid') or
module.params.get('name')))

if not module.params['snapshot_name'] and module.params['state'] != 'remove_all':
module.fail_json(msg="snapshot_name param is required when state is '%(state)s'" % module.params)
Expand Down
20 changes: 20 additions & 0 deletions test/integration/targets/vmware_guest_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,23 @@
# name: "{{ vm1 | basename }}"
# state: revert
# snapshot_name: snap_a

# # Test0009: Create snap_a and check in result
# - name: 0009 - create snapshot a
# vmware_guest_snapshot:
# validate_certs: False
# hostname: "{{ vcsim }}"
# username: "{{ vcsim_instance['json']['username'] }}"
# password: "{{ vcsim_instance['json']['password'] }}"
# datacenter: "{{ dc1 | basename }}"
# folder: "{{ vm1 | dirname }}"
# name: "{{ vm1 | basename }}"
# state: present
# snapshot_name: snap_a
# description: "snap named a"
# register: snapshot_details

# - name: Check if snapshot details available or not
# assert:
# that:
# - "snapshot_details.results['current_snapshot']['name'] == 'snap_a'