mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7953/248e2ff3 backport][stable-7] [FIX] proxmox_kvm: fetch vm status from node-specific API endpoint to ensure fresh state (#8044)
[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:
parent
567b573971
commit
9bf146a67a
2 changed files with 14 additions and 9 deletions
|
@ -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).
|
|
@ -1466,8 +1466,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):
|
||||||
|
@ -1482,9 +1483,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)
|
||||||
|
|
||||||
if proxmox.stop_vm(vm, force=module.params['force'], timeout=module.params['timeout']):
|
if proxmox.stop_vm(vm, force=module.params['force'], timeout=module.params['timeout']):
|
||||||
|
@ -1498,8 +1499,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']):
|
||||||
|
@ -1516,8 +1518,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:
|
||||||
|
|
Loading…
Reference in a new issue