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

proxmox_kvm: enable 'force' restart of vm (as documented) (#6914)

* enable 'force' restart of vm

* added changelog fragment

* Update changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Jeff Turner 2023-07-23 17:29:51 -03:00 committed by GitHub
parent d7c1a814ea
commit 17b4219b8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- proxmox_kvm - enabled force restart of VM, bringing the ``force`` parameter functionality in line with what is described in the docs (https://github.com/ansible-collections/community.general/pull/6914).

View file

@ -1111,11 +1111,11 @@ class ProxmoxKvmAnsible(ProxmoxAnsible):
return False return False
return True return True
def restart_vm(self, vm, **status): def restart_vm(self, vm, force, **status):
vmid = vm['vmid'] vmid = vm['vmid']
try: try:
proxmox_node = self.proxmox_api.nodes(vm['node']) proxmox_node = self.proxmox_api.nodes(vm['node'])
taskid = proxmox_node.qemu(vmid).status.reboot.post() taskid = proxmox_node.qemu(vmid).status.reset.post() if force else proxmox_node.qemu(vmid).status.reboot.post()
if not self.wait_for_task(vm['node'], taskid): if not self.wait_for_task(vm['node'], taskid):
self.module.fail_json(msg='Reached timeout while waiting for rebooting VM. Last line in task before timeout: %s' % self.module.fail_json(msg='Reached timeout while waiting for rebooting VM. Last line in task before timeout: %s' %
proxmox_node.tasks(taskid).log.get()[:1]) proxmox_node.tasks(taskid).log.get()[:1])
@ -1493,7 +1493,7 @@ def main():
if vm['status'] == 'stopped': if vm['status'] == 'stopped':
module.exit_json(changed=False, vmid=vmid, msg="VM %s is not running" % vmid, **status) module.exit_json(changed=False, vmid=vmid, msg="VM %s is not running" % vmid, **status)
if proxmox.restart_vm(vm): if proxmox.restart_vm(vm, force=module.params['force']):
module.exit_json(changed=True, vmid=vmid, msg="VM %s is restarted" % vmid, **status) module.exit_json(changed=True, vmid=vmid, msg="VM %s is restarted" % vmid, **status)
elif state == 'absent': elif state == 'absent':