Compare commits

..

No commits in common. "v3.0.0" and "v2.3.0" have entirely different histories.

3 changed files with 71 additions and 59 deletions

View File

@ -1,4 +1,4 @@
local PythonVersion(pyversion='3.8') = {
local PythonVersion(pyversion='3.6') = {
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
image: 'python:' + pyversion,
environment: {
@ -24,7 +24,7 @@ local PipelineLint = {
steps: [
{
name: 'flake8',
image: 'python:3.10',
image: 'python:3.9',
environment: {
PY_COLORS: 1,
},
@ -47,9 +47,10 @@ 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.10
image: python:3.9
commands:
- pip install -r dev-requirements.txt -qq
- flake8
@ -30,6 +30,28 @@ 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:
@ -52,17 +74,6 @@ 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
@ -195,6 +206,6 @@ depends_on:
---
kind: signature
hmac: ab27526306385333095136e854eb03172f211ee4322181c63fd2b2d282e79c2e
hmac: caf424e7fa2ffcf45e2eebf15a840d2c8a256e4032d3cf8fb2a6f1cef59b42a4
...

View File

@ -439,6 +439,8 @@ 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'
@ -732,12 +734,10 @@ 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,6 +778,7 @@ 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:
@ -795,10 +796,25 @@ 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"] = _extract_devices(vm)
results["devices"] = devices
results["vmid"] = int(vmid)
results["_raw"] = vm
def settings(module, proxmox, vmid, node, name, **kwargs):
@ -866,17 +882,18 @@ def create_vm(
urlencoded_ssh_keys = quote(kwargs["sshkeys"], safe="")
kwargs["sshkeys"] = str(urlencoded_ssh_keys)
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, 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"
if update:
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"])
)
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"]
# Convert all dict in kwargs to elements.
for k in list(kwargs.keys()):
@ -1264,19 +1281,6 @@ 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,
@ -1349,6 +1353,18 @@ 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)
@ -1528,21 +1544,5 @@ 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()