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

[PR #7953/248e2ff3 backport][stable-8] [FIX] proxmox_kvm: fetch vm status from node-specific API endpoint to ensure fresh state (#8043)

[FIX] proxmox_kvm: fetch vm status from node-specific API endpoint to ensure fresh state (#7953)

* proxmox_kvm: fetch vm status from node-specific API endpoint to ensure fresh state, fixes #7817

* changelog fragments

* Fix changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 248e2ff321)

Co-authored-by: nxet <nxet821@protonmail.com>
This commit is contained in:
patchback[bot] 2024-02-28 22:23:32 +01:00 committed by GitHub
parent f379dac394
commit 76d8e2d577
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 9 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- proxmox_kvm - fixed status check getting from node-specific API endpoint (https://github.com/ansible-collections/community.general/issues/7817).

View file

@ -1547,8 +1547,9 @@ def main():
status = {} status = {}
try: try:
vm = proxmox.get_vm(vmid) vm = proxmox.get_vm(vmid)
status['status'] = vm['status'] current = proxmox.proxmox_api.nodes(vm['node']).qemu(vmid).status.current.get()['status']
if vm['status'] == 'running': status['status'] = current
if current == 'running':
module.exit_json(changed=False, vmid=vmid, msg="VM %s is already running" % vmid, **status) module.exit_json(changed=False, vmid=vmid, msg="VM %s is already running" % vmid, **status)
if proxmox.start_vm(vm): if proxmox.start_vm(vm):
@ -1563,9 +1564,9 @@ def main():
status = {} status = {}
try: try:
vm = proxmox.get_vm(vmid) vm = proxmox.get_vm(vmid)
current = proxmox.proxmox_api.nodes(vm['node']).qemu(vmid).status.current.get()['status']
status['status'] = vm['status'] status['status'] = current
if vm['status'] == 'stopped': if current == 'stopped':
module.exit_json(changed=False, vmid=vmid, msg="VM %s is already stopped" % vmid, **status) module.exit_json(changed=False, vmid=vmid, msg="VM %s is already stopped" % vmid, **status)
proxmox.stop_vm(vm, force=module.params['force'], timeout=module.params['timeout']) proxmox.stop_vm(vm, force=module.params['force'], timeout=module.params['timeout'])
@ -1595,8 +1596,9 @@ def main():
status = {} status = {}
vm = proxmox.get_vm(vmid) vm = proxmox.get_vm(vmid)
status['status'] = vm['status'] current = proxmox.proxmox_api.nodes(vm['node']).qemu(vmid).status.current.get()['status']
if vm['status'] == 'stopped': status['status'] = current
if current == '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, force=module.params['force']): if proxmox.restart_vm(vm, force=module.params['force']):
@ -1613,8 +1615,9 @@ def main():
module.exit_json(changed=False, vmid=vmid) module.exit_json(changed=False, vmid=vmid)
proxmox_node = proxmox.proxmox_api.nodes(vm['node']) proxmox_node = proxmox.proxmox_api.nodes(vm['node'])
status['status'] = vm['status'] current = proxmox_node.qemu(vmid).status.current.get()['status']
if vm['status'] == 'running': status['status'] = current
if current == 'running':
if module.params['force']: if module.params['force']:
proxmox.stop_vm(vm, True, timeout=module.params['timeout']) proxmox.stop_vm(vm, True, timeout=module.params['timeout'])
else: else: