1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Additional idempotent states for virt module: "destroyed" and "paused"

This commit is contained in:
Brian Candler 2013-11-27 16:58:34 +00:00
parent 30948ae0dc
commit 3b07f848a2

View file

@ -36,7 +36,7 @@ options:
since these refer only to VM states. After starting a guest, it may not since these refer only to VM states. After starting a guest, it may not
be immediately accessible. be immediately accessible.
required: false required: false
choices: [ "running", "shutdown" ] choices: [ "running", "shutdown", "destroyed", "paused" ]
default: "no" default: "no"
command: command:
description: description:
@ -414,13 +414,24 @@ def core(module):
res['changed'] = False res['changed'] = False
if state == 'running': if state == 'running':
if v.status(guest) is not 'running': if v.status(guest) is 'paused':
res['changed'] = True
res['msg'] = v.unpause(guest)
elif v.status(guest) is not 'running':
res['changed'] = True res['changed'] = True
res['msg'] = v.start(guest) res['msg'] = v.start(guest)
elif state == 'shutdown': elif state == 'shutdown':
if v.status(guest) is not 'shutdown': if v.status(guest) is not 'shutdown':
res['changed'] = True res['changed'] = True
res['msg'] = v.shutdown(guest) res['msg'] = v.shutdown(guest)
elif state == 'destroyed':
if v.status(guest) is not 'shutdown':
res['changed'] = True
res['msg'] = v.destroy(guest)
elif state == 'paused':
if v.status(guest) is 'running':
res['changed'] = True
res['msg'] = v.pause(guest)
else: else:
module.fail_json(msg="unexpected state") module.fail_json(msg="unexpected state")
@ -459,7 +470,7 @@ def main():
module = AnsibleModule(argument_spec=dict( module = AnsibleModule(argument_spec=dict(
name = dict(aliases=['guest']), name = dict(aliases=['guest']),
state = dict(choices=['running', 'shutdown']), state = dict(choices=['running', 'shutdown', 'destroyed', 'paused']),
command = dict(choices=ALL_COMMANDS), command = dict(choices=ALL_COMMANDS),
uri = dict(default='qemu:///system'), uri = dict(default='qemu:///system'),
xml = dict(), xml = dict(),