diff --git a/changelogs/fragments/4036-onevm-add-release-action.yaml b/changelogs/fragments/4036-onevm-add-release-action.yaml new file mode 100644 index 0000000000..bc61278b4a --- /dev/null +++ b/changelogs/fragments/4036-onevm-add-release-action.yaml @@ -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). diff --git a/plugins/modules/cloud/opennebula/one_vm.py b/plugins/modules/cloud/opennebula/one_vm.py index fa3d4abaab..86061f73cb 100644 --- a/plugins/modules/cloud/opennebula/one_vm.py +++ b/plugins/modules/cloud/opennebula/one_vm.py @@ -1260,6 +1260,11 @@ def resume_vm(module, client, vm): vm = client.vm.info(vm.ID) 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 if lcm_state == LCM_STATES.index('SHUTDOWN_POWEROFF'): 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 +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): if attributes.get("NAME"): import re