Compare commits

...

2 Commits

Author SHA1 Message Date
Robert Kaussow d1f6175719
BREAKING CHANGE: drop support for python 3.6 and 3.7
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2021-12-06 16:42:26 +01:00
Robert Kaussow 22e6546396
fix: avoid recreation of storage devices during VM update
continuous-integration/drone/push Build is passing Details
2021-12-05 21:47:23 +01:00
3 changed files with 59 additions and 71 deletions

View File

@ -1,4 +1,4 @@
local PythonVersion(pyversion='3.6') = {
local PythonVersion(pyversion='3.8') = {
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
image: 'python:' + pyversion,
environment: {
@ -24,7 +24,7 @@ local PipelineLint = {
steps: [
{
name: 'flake8',
image: 'python:3.9',
image: 'python:3.10',
environment: {
PY_COLORS: 1,
},
@ -47,10 +47,9 @@ local PipelineTest = {
arch: 'amd64',
},
steps: [
PythonVersion(pyversion='3.6'),
PythonVersion(pyversion='3.7'),
PythonVersion(pyversion='3.8'),
PythonVersion(pyversion='3.9'),
PythonVersion(pyversion='3.10'),
],
depends_on: [
'lint',

View File

@ -8,7 +8,7 @@ platform:
steps:
- name: flake8
image: python:3.9
image: python:3.10
commands:
- pip install -r dev-requirements.txt -qq
- flake8
@ -30,28 +30,6 @@ platform:
arch: amd64
steps:
- name: python36-pytest
image: python:3.6
commands:
- pip install -r dev-requirements.txt -qq
- pip install -r test/unit/requirements.txt -qq
- python -m pytest --cov --cov-append --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python37-pytest
image: python:3.7
commands:
- pip install -r dev-requirements.txt -qq
- pip install -r test/unit/requirements.txt -qq
- python -m pytest --cov --cov-append --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
- clone
- name: python38-pytest
image: python:3.8
commands:
@ -74,6 +52,17 @@ steps:
depends_on:
- clone
- name: python310-pytest
image: python:3.10
commands:
- pip install -r dev-requirements.txt -qq
- pip install -r test/unit/requirements.txt -qq
- python -m pytest --cov --cov-append --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
- clone
trigger:
ref:
- refs/heads/master
@ -206,6 +195,6 @@ depends_on:
---
kind: signature
hmac: caf424e7fa2ffcf45e2eebf15a840d2c8a256e4032d3cf8fb2a6f1cef59b42a4
hmac: ab27526306385333095136e854eb03172f211ee4322181c63fd2b2d282e79c2e
...

View File

@ -439,8 +439,6 @@ options:
update:
description:
- If C(yes), the VM will be updated with new value.
- Cause of the operations of the API and security reasons, I have disabled the update of the following parameters
- C(net, virtio, ide, sata, scsi). Per example updating C(net) update the MAC address and C(virtio) create always new disk...
- Update of C(pool) is disabled. It needs an additional API endpoint not covered by this module.
type: bool
default: 'no'
@ -734,10 +732,12 @@ msg:
"""
import re
import string
import time
import traceback
from distutils.version import LooseVersion
from ansible.module_utils.six.moves.urllib.parse import quote
from collections import defaultdict
try:
from proxmoxer import ProxmoxAPI
@ -778,7 +778,6 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs):
global results # noqa
results = {}
mac = {}
devices = {}
try:
vm = proxmox.nodes(node).qemu(vmid).config.get()
except Exception as e:
@ -796,25 +795,10 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs):
kwargs.update(kwargs[k])
del kwargs[k]
# Split information by type
for k, v in kwargs.items():
if re.match(r"net[0-9]", k) is not None:
interface = k
k = vm[k]
k = re.search("=(.*?),", k).group(1)
mac[interface] = k
if (
re.match(r"virtio[0-9]", k) is not None or re.match(r"ide[0-9]", k) is not None
or re.match(r"scsi[0-9]", k) is not None or re.match(r"sata[0-9]", k) is not None
):
device = k
k = vm[k]
k = re.search("(.*?),", k).group(1)
devices[device] = k
results["mac"] = mac
results["devices"] = devices
results["devices"] = _extract_devices(vm)
results["vmid"] = int(vmid)
results["_raw"] = vm
def settings(module, proxmox, vmid, node, name, **kwargs):
@ -882,18 +866,17 @@ def create_vm(
urlencoded_ssh_keys = quote(kwargs["sshkeys"], safe="")
kwargs["sshkeys"] = str(urlencoded_ssh_keys)
# If update, don't update disk (virtio, ide, sata, scsi) and network interface.
# Pool parameter not supported by qemu/<vmid>/config endpoint on "update" (PVE 6.2),
# only with "create"
for item in [kwargs[i] for i in ["scsi", "virtio", "ide", "sata"] if i in kwargs]:
devices = _extract_devices(item)
# If update, ensure existing disks are not recreated.
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"]
for k, v in devices.items():
if results["devices"].get(k):
kwargs[k.rstrip(string.digits)][k] = "{0}:{1},{2}".format(
results["devices"][k]["storage_id"], results["devices"][k]["storage_opts"],
",".join(devices[k]["opts"])
)
# Convert all dict in kwargs to elements.
for k in list(kwargs.keys()):
@ -1281,6 +1264,19 @@ def main():
elif not node_check(proxmox, node):
module.fail_json(msg="node '{}' does not exist in cluster".format(node))
if not clone:
get_vminfo(
module,
proxmox,
node,
vmid,
ide=module.params["ide"],
net=module.params["net"],
sata=module.params["sata"],
scsi=module.params["scsi"],
virtio=module.params["virtio"]
)
create_vm(
module,
proxmox,
@ -1353,18 +1349,6 @@ def main():
watchdog=module.params["watchdog"]
)
if not clone:
get_vminfo(
module,
proxmox,
node,
vmid,
ide=module.params["ide"],
net=module.params["net"],
sata=module.params["sata"],
scsi=module.params["scsi"],
virtio=module.params["virtio"]
)
if update:
module.exit_json(
changed=True, vmid=vmid, msg="VM {} with vmid {} updated".format(name, vmid)
@ -1544,5 +1528,21 @@ def main():
)
def _extract_devices(item):
devices = defaultdict(dict)
for k, v in item.items():
if re.match(r"(scsi|virtio|ide|sata)[0-9]", k):
devices[k]["opts"] = []
for val in v.split(","):
if len(val.split(":")) == 2:
storage = val.split(":")
devices[k]["storage_id"] = storage[0]
devices[k]["storage_opts"] = storage[1]
else:
devices[k]["opts"].append(val)
return devices
if __name__ == "__main__":
main()