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

Added ability to take snapshots on XenServer #55247

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 24 additions & 1 deletion lib/ansible/modules/cloud/xenserver/xenserver_guest.py
Expand Up @@ -93,6 +93,12 @@
- UUID of a template, an existing VM or a snapshot that should be used to create VM.
- It is required if template name is not unique.
type: str
is_snapshot:
description:
- Create a snapshot for a VM.
type: bool
default: no
version_added: "2.9"
is_template:
description:
- Convert VM to template.
Expand Down Expand Up @@ -223,6 +229,18 @@
delegate_to: localhost
register: deploy

- name: Create a snapshot for a VM
xenserver_guest:
hostname: "{{ xenserver_hostname }}"
username: "{{ xenserver_username }}"
password: "{{ xenserver_password }}"
validate_certs: no
folder: /testvms
name: testvm_6
is_snapshot: yes
delegate_to: localhost
register: deploy

- name: Create a VM template
xenserver_guest:
hostname: "{{ xenserver_hostname }}"
Expand Down Expand Up @@ -324,6 +342,7 @@
"num_cpus": 4
},
"home_server": "",
"is_snapshot": false,
"is_template": false,
"name": "testvm_11",
"name_desc": "",
Expand Down Expand Up @@ -1011,7 +1030,9 @@ def reconfigure(self):
custom_param_value = self.module.params['custom_params'][position]['value']
self.xapi_session.xenapi_request("VM.set_%s" % custom_param_key, (self.vm_ref, custom_param_value))

if self.module.params['is_template']:
if self.module.params['is_snapshot']:
self.xapi_session.xenapi.VM.set_is_a_snapshot(self.vm_ref, True)
elif self.module.params['is_template']:
self.xapi_session.xenapi.VM.set_is_a_template(self.vm_ref, True)
elif "need_poweredoff" in config_changes and self.module.params['force'] and vm_power_state_save != 'halted':
self.set_power_state("poweredon")
Expand Down Expand Up @@ -1766,6 +1787,7 @@ def main():
uuid=dict(type='str'),
template=dict(type='str', aliases=['template_src']),
template_uuid=dict(type='str'),
is_snapshot=dict(type='bool', default=False),
is_template=dict(type='bool', default=False),
folder=dict(type='str'),
hardware=dict(
Expand Down Expand Up @@ -1849,6 +1871,7 @@ def main():
],
mutually_exclusive=[
['template', 'template_uuid'],
['is_snapshot', 'is_template'],
],
)

Expand Down