From 9aff5f600733b485da71ba520641493e5f182cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Mon, 30 Sep 2019 16:46:19 +0200 Subject: [PATCH] ovirt_vm add reboot state (#62785) * ovirt_vm add reboot state * update pep8 syntax * update docs * correct whitespace --- lib/ansible/modules/cloud/ovirt/ovirt_vm.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py index 91e47557e5a..d7f9aa2d9c8 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py @@ -28,7 +28,7 @@ options: - ID of the Virtual Machine to manage. state: description: - - Should the Virtual Machine be running/stopped/present/absent/suspended/next_run/registered/exported. + - Should the Virtual Machine be running/stopped/present/absent/suspended/next_run/registered/exported/reboot. When C(state) is I(registered) and the unregistered VM's name belongs to an already registered in engine VM in the same DC then we fail to register the unregistered template. @@ -38,7 +38,8 @@ options: - Please check I(notes) to more detailed description of states. - I(exported) state will export the VM to export domain or as OVA. - I(registered) is supported since 2.4. - choices: [ absent, next_run, present, registered, running, stopped, suspended, exported ] + - I(reboot) is supported since 2.10, virtual machine is rebooted only if it's in up state. + choices: [ absent, next_run, present, registered, running, stopped, suspended, exported, reboot ] default: present cluster: description: @@ -2315,7 +2316,9 @@ def control_state(vm, vms_service, module): def main(): argument_spec = ovirt_full_argument_spec( - state=dict(type='str', default='present', choices=['absent', 'next_run', 'present', 'registered', 'running', 'stopped', 'suspended', 'exported']), + state=dict(type='str', default='present', choices=[ + 'absent', 'next_run', 'present', 'registered', 'running', 'stopped', 'suspended', 'exported', 'reboot' + ]), name=dict(type='str'), id=dict(type='str'), cluster=dict(type='str'), @@ -2640,6 +2643,13 @@ def main(): directory=export_vm.get('directory'), filename=export_vm.get('filename'), ) + elif state == 'reboot': + ret = vms_module.action( + action='reboot', + entity=vm, + action_condition=lambda vm: vm.status == otypes.VmStatus.UP, + wait_condition=lambda vm: vm.status == otypes.VmStatus.UP, + ) module.exit_json(**ret) except Exception as e: