mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
one_vm: add release action (#4036)
* one_vm: add release action Previously you could create VMs with the `vm_start_on_hold` parameter but then ansible couldn't release the VMs so they would be scheduled to run. This PR adds the ability to release VMs which are in the 'HOLD' state. * Add changelog fragment * Update changelogs/fragments/4036-onevm-add-release-action.yaml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cloud/opennebula/one_vm.py Co-authored-by: Felix Fontein <felix@fontein.de> * Make releasing a VM part of the running state When `state: running` is specified the code checks if the VM is in a 'HOLD' state and will release the VM when needed. Co-authored-by: Gerben Welter <gerben.welter@hcs-company.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
62d519de10
commit
a4983ce38a
2 changed files with 24 additions and 0 deletions
2
changelogs/fragments/4036-onevm-add-release-action.yaml
Normal file
2
changelogs/fragments/4036-onevm-add-release-action.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- opennebula - add the release action for VMs in the ``HOLD`` state (https://github.com/ansible-collections/community.general/pull/4036).
|
|
@ -1260,6 +1260,11 @@ def resume_vm(module, client, vm):
|
||||||
vm = client.vm.info(vm.ID)
|
vm = client.vm.info(vm.ID)
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
state = vm.STATE
|
||||||
|
if state in [VM_STATES.index('HOLD')]:
|
||||||
|
changed = release_vm(module, client, vm)
|
||||||
|
return changed
|
||||||
|
|
||||||
lcm_state = vm.LCM_STATE
|
lcm_state = vm.LCM_STATE
|
||||||
if lcm_state == LCM_STATES.index('SHUTDOWN_POWEROFF'):
|
if lcm_state == LCM_STATES.index('SHUTDOWN_POWEROFF'):
|
||||||
module.fail_json(msg="Cannot perform action 'resume' because this action is not available " +
|
module.fail_json(msg="Cannot perform action 'resume' because this action is not available " +
|
||||||
|
@ -1282,6 +1287,23 @@ def resume_vms(module, client, vms):
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
def release_vm(module, client, vm):
|
||||||
|
vm = client.vm.info(vm.ID)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
state = vm.STATE
|
||||||
|
if state != VM_STATES.index('HOLD'):
|
||||||
|
module.fail_json(msg="Cannot perform action 'release' because this action is not available " +
|
||||||
|
"because VM is not in state 'HOLD'.")
|
||||||
|
else:
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if changed and not module.check_mode:
|
||||||
|
client.vm.action('release', vm.ID)
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
|
|
||||||
def check_name_attribute(module, attributes):
|
def check_name_attribute(module, attributes):
|
||||||
if attributes.get("NAME"):
|
if attributes.get("NAME"):
|
||||||
import re
|
import re
|
||||||
|
|
Loading…
Reference in a new issue