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

ovirt_vm add reboot state #62785

Merged
merged 4 commits into from
Sep 30, 2019
Merged
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
16 changes: 13 additions & 3 deletions lib/ansible/modules/cloud/ovirt/ovirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- 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.
Expand All @@ -38,7 +38,8 @@
- 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:
Expand Down Expand Up @@ -2309,7 +2310,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'),
Expand Down Expand Up @@ -2633,6 +2636,13 @@ def kernel_persist_check():
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:
Expand Down