Compare commits
No commits in common. "v3.0.0" and "v2.3.0" have entirely different histories.
@ -1,4 +1,4 @@
|
|||||||
local PythonVersion(pyversion='3.8') = {
|
local PythonVersion(pyversion='3.6') = {
|
||||||
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
|
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
|
||||||
image: 'python:' + pyversion,
|
image: 'python:' + pyversion,
|
||||||
environment: {
|
environment: {
|
||||||
@ -24,7 +24,7 @@ local PipelineLint = {
|
|||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: 'flake8',
|
name: 'flake8',
|
||||||
image: 'python:3.10',
|
image: 'python:3.9',
|
||||||
environment: {
|
environment: {
|
||||||
PY_COLORS: 1,
|
PY_COLORS: 1,
|
||||||
},
|
},
|
||||||
@ -47,9 +47,10 @@ local PipelineTest = {
|
|||||||
arch: 'amd64',
|
arch: 'amd64',
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
|
PythonVersion(pyversion='3.6'),
|
||||||
|
PythonVersion(pyversion='3.7'),
|
||||||
PythonVersion(pyversion='3.8'),
|
PythonVersion(pyversion='3.8'),
|
||||||
PythonVersion(pyversion='3.9'),
|
PythonVersion(pyversion='3.9'),
|
||||||
PythonVersion(pyversion='3.10'),
|
|
||||||
],
|
],
|
||||||
depends_on: [
|
depends_on: [
|
||||||
'lint',
|
'lint',
|
||||||
|
37
.drone.yml
37
.drone.yml
@ -8,7 +8,7 @@ platform:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: flake8
|
- name: flake8
|
||||||
image: python:3.10
|
image: python:3.9
|
||||||
commands:
|
commands:
|
||||||
- pip install -r dev-requirements.txt -qq
|
- pip install -r dev-requirements.txt -qq
|
||||||
- flake8
|
- flake8
|
||||||
@ -30,6 +30,28 @@ platform:
|
|||||||
arch: amd64
|
arch: amd64
|
||||||
|
|
||||||
steps:
|
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
|
- name: python38-pytest
|
||||||
image: python:3.8
|
image: python:3.8
|
||||||
commands:
|
commands:
|
||||||
@ -52,17 +74,6 @@ steps:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- clone
|
- 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:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
- refs/heads/master
|
- refs/heads/master
|
||||||
@ -195,6 +206,6 @@ depends_on:
|
|||||||
|
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: ab27526306385333095136e854eb03172f211ee4322181c63fd2b2d282e79c2e
|
hmac: caf424e7fa2ffcf45e2eebf15a840d2c8a256e4032d3cf8fb2a6f1cef59b42a4
|
||||||
|
|
||||||
...
|
...
|
||||||
|
@ -439,6 +439,8 @@ options:
|
|||||||
update:
|
update:
|
||||||
description:
|
description:
|
||||||
- If C(yes), the VM will be updated with new value.
|
- 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.
|
- Update of C(pool) is disabled. It needs an additional API endpoint not covered by this module.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
@ -732,12 +734,10 @@ msg:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import string
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from ansible.module_utils.six.moves.urllib.parse import quote
|
from ansible.module_utils.six.moves.urllib.parse import quote
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from proxmoxer import ProxmoxAPI
|
from proxmoxer import ProxmoxAPI
|
||||||
@ -778,6 +778,7 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs):
|
|||||||
global results # noqa
|
global results # noqa
|
||||||
results = {}
|
results = {}
|
||||||
mac = {}
|
mac = {}
|
||||||
|
devices = {}
|
||||||
try:
|
try:
|
||||||
vm = proxmox.nodes(node).qemu(vmid).config.get()
|
vm = proxmox.nodes(node).qemu(vmid).config.get()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -795,10 +796,25 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs):
|
|||||||
kwargs.update(kwargs[k])
|
kwargs.update(kwargs[k])
|
||||||
del 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["mac"] = mac
|
||||||
results["devices"] = _extract_devices(vm)
|
results["devices"] = devices
|
||||||
results["vmid"] = int(vmid)
|
results["vmid"] = int(vmid)
|
||||||
results["_raw"] = vm
|
|
||||||
|
|
||||||
|
|
||||||
def settings(module, proxmox, vmid, node, name, **kwargs):
|
def settings(module, proxmox, vmid, node, name, **kwargs):
|
||||||
@ -866,17 +882,18 @@ def create_vm(
|
|||||||
urlencoded_ssh_keys = quote(kwargs["sshkeys"], safe="")
|
urlencoded_ssh_keys = quote(kwargs["sshkeys"], safe="")
|
||||||
kwargs["sshkeys"] = str(urlencoded_ssh_keys)
|
kwargs["sshkeys"] = str(urlencoded_ssh_keys)
|
||||||
|
|
||||||
for item in [kwargs[i] for i in ["scsi", "virtio", "ide", "sata"] if i in kwargs]:
|
# If update, don't update disk (virtio, ide, sata, scsi) and network interface.
|
||||||
devices = _extract_devices(item)
|
# Pool parameter not supported by qemu/<vmid>/config endpoint on "update" (PVE 6.2),
|
||||||
|
# only with "create"
|
||||||
# If update, ensure existing disks are not recreated.
|
|
||||||
if update:
|
if update:
|
||||||
for k, v in devices.items():
|
if "virtio" in kwargs:
|
||||||
if results["devices"].get(k):
|
del kwargs["virtio"]
|
||||||
kwargs[k.rstrip(string.digits)][k] = "{0}:{1},{2}".format(
|
if "sata" in kwargs:
|
||||||
results["devices"][k]["storage_id"], results["devices"][k]["storage_opts"],
|
del kwargs["sata"]
|
||||||
",".join(devices[k]["opts"])
|
if "scsi" in kwargs:
|
||||||
)
|
del kwargs["scsi"]
|
||||||
|
if "ide" in kwargs:
|
||||||
|
del kwargs["ide"]
|
||||||
|
|
||||||
# Convert all dict in kwargs to elements.
|
# Convert all dict in kwargs to elements.
|
||||||
for k in list(kwargs.keys()):
|
for k in list(kwargs.keys()):
|
||||||
@ -1264,19 +1281,6 @@ def main():
|
|||||||
elif not node_check(proxmox, node):
|
elif not node_check(proxmox, node):
|
||||||
module.fail_json(msg="node '{}' does not exist in cluster".format(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(
|
create_vm(
|
||||||
module,
|
module,
|
||||||
proxmox,
|
proxmox,
|
||||||
@ -1349,6 +1353,18 @@ def main():
|
|||||||
watchdog=module.params["watchdog"]
|
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:
|
if update:
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
changed=True, vmid=vmid, msg="VM {} with vmid {} updated".format(name, vmid)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user