Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxmox_kvm - new param to support unsafe updates #7843

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/7843-proxmox_kvm-update_unsafe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- proxmox_kvm - Add parameter `update_unsafe` to avoid limitations when updating dangerous values. (https://github.com/ansible-collections/community.general/pull/7843).
nxet marked this conversation as resolved.
Show resolved Hide resolved
57 changes: 40 additions & 17 deletions plugins/modules/proxmox_kvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@
- Update of O(pool) is disabled. It needs an additional API endpoint not covered by this module.
type: bool
default: false
update_unsafe:
description:
- If V(true), does not enforce limitations on parameters O(net), O(virtio), O(ide), O(sata), O(scsi).
nxet marked this conversation as resolved.
Show resolved Hide resolved
type: bool
default: false
version_added: 8.3.0
vcpus:
description:
- Sets number of hotplugged vcpus.
Expand Down Expand Up @@ -846,6 +852,20 @@
memory: 16384
update: true

- name: Update VM configuration (incl. unsafe options)
community.general.proxmox_kvm:
api_user: root@pam
api_password: secret
api_host: helldorado
name: spynal
node: sabrewulf
cores: 8
memory: 16384
net:
net0: virtio,bridge=vmbr1
update: true
update_unsafe: true

- name: Delete QEMU parameters
community.general.proxmox_kvm:
api_user: root@pam
Expand Down Expand Up @@ -981,7 +1001,7 @@ def wait_for_task(self, node, taskid):
time.sleep(1)
return False

def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update, **kwargs):
def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update, update_unsafe, **kwargs):
# Available only in PVE 4
only_v4 = ['force', 'protection', 'skiplock']
only_v6 = ['ciuser', 'cipassword', 'sshkeys', 'ipconfig', 'tags']
Expand Down Expand Up @@ -1018,23 +1038,24 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update
urlencoded_ssh_keys = quote(kwargs['sshkeys'], safe='')
kwargs['sshkeys'] = str(urlencoded_ssh_keys)

# If update, don't update disk (virtio, efidisk0, tpmstate0, ide, sata, scsi) and network interface
# If update, don't update disk (virtio, efidisk0, tpmstate0, ide, sata, scsi) and network interface, unless update_unsafe=True
# pool parameter not supported by qemu/<vmid>/config endpoint on "update" (PVE 6.2) - only with "create"
if update:
if 'virtio' in kwargs:
del kwargs['virtio']
if 'sata' in kwargs:
del kwargs['sata']
if 'scsi' in kwargs:
del kwargs['scsi']
if 'ide' in kwargs:
del kwargs['ide']
if 'efidisk0' in kwargs:
del kwargs['efidisk0']
if 'tpmstate0' in kwargs:
del kwargs['tpmstate0']
if 'net' in kwargs:
del kwargs['net']
if update_unsafe is not True:
nxet marked this conversation as resolved.
Show resolved Hide resolved
if 'virtio' in kwargs:
del kwargs['virtio']
if 'sata' in kwargs:
del kwargs['sata']
if 'scsi' in kwargs:
del kwargs['scsi']
if 'ide' in kwargs:
del kwargs['ide']
if 'efidisk0' in kwargs:
del kwargs['efidisk0']
if 'tpmstate0' in kwargs:
del kwargs['tpmstate0']
if 'net' in kwargs:
del kwargs['net']
if 'force' in kwargs:
del kwargs['force']
if 'pool' in kwargs:
Expand Down Expand Up @@ -1286,6 +1307,7 @@ def main():
version=dict(type='str', choices=['2.0', '1.2'], default='2.0')
)),
update=dict(type='bool', default=False),
update_unsafe=dict(type='bool', default=False),
vcpus=dict(type='int'),
vga=dict(choices=['std', 'cirrus', 'vmware', 'qxl', 'serial0', 'serial1', 'serial2', 'serial3', 'qxl2', 'qxl3', 'qxl4']),
virtio=dict(type='dict'),
Expand Down Expand Up @@ -1320,6 +1342,7 @@ def main():
sockets = module.params['sockets']
state = module.params['state']
update = bool(module.params['update'])
update_unsafe = bool(module.params['update_unsafe'])
vmid = module.params['vmid']
validate_certs = module.params['validate_certs']

Expand Down Expand Up @@ -1429,7 +1452,7 @@ def main():
module.fail_json(msg="node '%s' does not exist in cluster" % node)

try:
proxmox.create_vm(vmid, newid, node, name, memory, cpu, cores, sockets, update,
proxmox.create_vm(vmid, newid, node, name, memory, cpu, cores, sockets, update, update_unsafe,
archive=module.params['archive'],
acpi=module.params['acpi'],
agent=module.params['agent'],
Expand Down