mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* proxmox_kvm: undefined local variable status
* proxmox_kvm: Add a changelog fragment
* Update changelogs/fragments/1847-proxmox-kvm-fix-status.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
* proxmox_kvm: fix the RETURN document
* proxmox_kvm: fix name variable when state=current
The variable name is not always defined as the module can be called with
just a vmid.
Before:
> "msg": "VM None with vmid = 118 is stopped"
After:
> "msg": "VM test-instance with vmid = 118 is stopped"
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 5135587c16
)
Co-authored-by: Tristan Le Guern <tristan.leguern-presta@deveryware.com>
This commit is contained in:
parent
0aaa5e3d91
commit
58ae8c81ac
2 changed files with 25 additions and 13 deletions
2
changelogs/fragments/1847-proxmox-kvm-fix-status.yml
Normal file
2
changelogs/fragments/1847-proxmox-kvm-fix-status.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- proxmox_kvm - fix undefined local variable ``status`` when the parameter ``state`` is either ``stopped``, ``started``, ``restarted`` or ``absent`` (https://github.com/ansible-collections/community.general/pull/1847).
|
|
@ -778,20 +778,20 @@ EXAMPLES = '''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
vmid:
|
vmid:
|
||||||
description: The VM vmid.
|
description: The VM vmid.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
sample: 115
|
sample: 115
|
||||||
status:
|
status:
|
||||||
description:
|
description: The current virtual machine status.
|
||||||
- The current virtual machine status.
|
returned: success, not clone, not absent, not update
|
||||||
returned: success
|
type: str
|
||||||
type: dict
|
sample: running
|
||||||
sample: '{
|
msg:
|
||||||
"changed": false,
|
description: A short message
|
||||||
"msg": "VM kropta with vmid = 110 is running",
|
returned: always
|
||||||
"status": "running"
|
type: str
|
||||||
}'
|
sample: "VM kropta with vmid = 110 is running"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -1341,12 +1341,14 @@ def main():
|
||||||
module.fail_json(vmid=vmid, msg="creation of qemu VM %s with vmid %s failed with exception=%s" % (name, vmid, e))
|
module.fail_json(vmid=vmid, msg="creation of qemu VM %s with vmid %s failed with exception=%s" % (name, vmid, e))
|
||||||
|
|
||||||
elif state == 'started':
|
elif state == 'started':
|
||||||
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if -1 == vmid:
|
||||||
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
module.fail_json(vmid=vmid, msg='VM with vmid <%s> does not exist in cluster' % vmid)
|
module.fail_json(vmid=vmid, msg='VM with vmid <%s> does not exist in cluster' % vmid)
|
||||||
|
status['status'] = vm[0]['status']
|
||||||
if vm[0]['status'] == 'running':
|
if vm[0]['status'] == '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)
|
||||||
|
|
||||||
|
@ -1356,6 +1358,7 @@ def main():
|
||||||
module.fail_json(vmid=vmid, msg="starting of VM %s failed with exception: %s" % (vmid, e), **status)
|
module.fail_json(vmid=vmid, msg="starting of VM %s failed with exception: %s" % (vmid, e), **status)
|
||||||
|
|
||||||
elif state == 'stopped':
|
elif state == 'stopped':
|
||||||
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if -1 == vmid:
|
||||||
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
||||||
|
@ -1364,6 +1367,7 @@ def main():
|
||||||
if not vm:
|
if not vm:
|
||||||
module.fail_json(vmid=vmid, msg='VM with vmid = %s does not exist in cluster' % vmid)
|
module.fail_json(vmid=vmid, msg='VM with vmid = %s does not exist in cluster' % vmid)
|
||||||
|
|
||||||
|
status['status'] = vm[0]['status']
|
||||||
if vm[0]['status'] == 'stopped':
|
if vm[0]['status'] == '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)
|
||||||
|
|
||||||
|
@ -1373,6 +1377,7 @@ def main():
|
||||||
module.fail_json(vmid=vmid, msg="stopping of VM %s failed with exception: %s" % (vmid, e), **status)
|
module.fail_json(vmid=vmid, msg="stopping of VM %s failed with exception: %s" % (vmid, e), **status)
|
||||||
|
|
||||||
elif state == 'restarted':
|
elif state == 'restarted':
|
||||||
|
status = {}
|
||||||
try:
|
try:
|
||||||
if -1 == vmid:
|
if -1 == vmid:
|
||||||
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
module.fail_json(msg='VM with name = %s does not exist in cluster' % name)
|
||||||
|
@ -1380,6 +1385,7 @@ def main():
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
module.fail_json(vmid=vmid, msg='VM with vmid = %s does not exist in cluster' % vmid)
|
module.fail_json(vmid=vmid, msg='VM with vmid = %s does not exist in cluster' % vmid)
|
||||||
|
status['status'] = vm[0]['status']
|
||||||
if vm[0]['status'] == 'stopped':
|
if vm[0]['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)
|
||||||
|
|
||||||
|
@ -1389,12 +1395,14 @@ def main():
|
||||||
module.fail_json(vmid=vmid, msg="restarting of VM %s failed with exception: %s" % (vmid, e), **status)
|
module.fail_json(vmid=vmid, msg="restarting of VM %s failed with exception: %s" % (vmid, e), **status)
|
||||||
|
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
|
status = {}
|
||||||
try:
|
try:
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
module.exit_json(changed=False, vmid=vmid)
|
module.exit_json(changed=False, vmid=vmid)
|
||||||
|
|
||||||
proxmox_node = proxmox.nodes(vm[0]['node'])
|
proxmox_node = proxmox.nodes(vm[0]['node'])
|
||||||
|
status['status'] = vm[0]['status']
|
||||||
if vm[0]['status'] == 'running':
|
if vm[0]['status'] == 'running':
|
||||||
module.exit_json(changed=False, vmid=vmid, msg="VM %s is running. Stop it before deletion." % vmid)
|
module.exit_json(changed=False, vmid=vmid, msg="VM %s is running. Stop it before deletion." % vmid)
|
||||||
taskid = proxmox_node.qemu.delete(vmid)
|
taskid = proxmox_node.qemu.delete(vmid)
|
||||||
|
@ -1413,6 +1421,8 @@ def main():
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
if not vm:
|
if not vm:
|
||||||
module.fail_json(msg='VM with vmid = %s does not exist in cluster' % vmid)
|
module.fail_json(msg='VM with vmid = %s does not exist in cluster' % vmid)
|
||||||
|
if not name:
|
||||||
|
name = vm[0]['name']
|
||||||
current = proxmox.nodes(vm[0]['node']).qemu(vmid).status.current.get()['status']
|
current = proxmox.nodes(vm[0]['node']).qemu(vmid).status.current.get()['status']
|
||||||
status['status'] = current
|
status['status'] = current
|
||||||
if status:
|
if status:
|
||||||
|
|
Loading…
Reference in a new issue