refactor: rework ci and testing #3

Merged
xoxys merged 14 commits from refactor-ci into main 2023-01-31 19:09:30 +00:00
4 changed files with 288 additions and 225 deletions
Showing only changes of commit 37ca6e3991 - Show all commits

View File

@ -9,42 +9,49 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = """ DOCUMENTATION = """
name: proxmox ---
plugin_type: inventory name: proxmox
short_description: Proxmox VE inventory source plugin_type: inventory
version_added: 1.1.0 short_description: Proxmox VE inventory source
description: version_added: 1.1.0
description:
- Get inventory hosts from the proxmox service. - Get inventory hosts from the proxmox service.
- "Uses a configuration file as an inventory source, it must end in C(.proxmox.yml) or C(.proxmox.yaml) and has a C(plugin: xoxys.general.proxmox) entry." - "Uses a configuration file as an inventory source, it must end in C(.proxmox.yml) or C(.proxmox.yaml) and has a C(plugin: xoxys.general.proxmox) entry."
extends_documentation_fragment: extends_documentation_fragment:
- inventory_cache - inventory_cache
options: options:
plugin: plugin:
description: The name of this plugin, it should always be set to C(xoxys.general.proxmox) for this plugin to recognize it as it's own. description: The name of this plugin, it should always be set to C(xoxys.general.proxmox) for this plugin to recognize it as it's own.
required: yes required: yes
choices: ["xoxys.general.proxmox"] choices: ["xoxys.general.proxmox"]
server: api_host:
description: Proxmox VE server url. description:
default: "pve.example.com" - Specify the target host of the Proxmox VE cluster.
type: string type: str
required: yes required: true
env: api_user:
- name: PROXMOX_SERVER description:
user: - Specify the user to authenticate with.
description: Proxmox VE authentication user. type: str
type: string required: true
required: yes api_password:
env: description:
- name: PROXMOX_USER - Specify the password to authenticate with.
password: - You can use C(PROXMOX_PASSWORD) environment variable.
description: Proxmox VE authentication password. type: str
type: string api_token_id:
required: yes description:
env: - Specify the token ID.
- name: PROXMOX_PASSWORD type: str
api_token_secret:
description:
- Specify the token secret.
type: str
verify_ssl: verify_ssl:
description: Skip SSL certificate verification. description:
type: boolean - If C(false), SSL certificates will not be validated.
- This should only be used on personally controlled sites using self-signed certificates.
type: bool
default: True default: True
auth_timeout: auth_timeout:
description: Proxmox VE authentication timeout. description: Proxmox VE authentication timeout.
@ -68,14 +75,15 @@ DOCUMENTATION = """
description: Toggle, if C(true) the plugin will retrieve host facts from the server description: Toggle, if C(true) the plugin will retrieve host facts from the server
type: boolean type: boolean
default: True default: True
""" # noqa """ # noqa
EXAMPLES = """ EXAMPLES = """
# proxmox.yml # proxmox.yml
plugin: xoxys.general.proxmox plugin: xoxys.general.proxmox
server: pve.example.com api_user: root@pam
user: admin@pve api_password: secret
password: secure api_host: helldorado
""" """
import json import json
@ -113,17 +121,22 @@ class InventoryModule(BaseInventoryPlugin):
NAME = "xoxys.general.proxmox" NAME = "xoxys.general.proxmox"
def _auth(self): def _auth(self):
verify_ssl = boolean(self.get_option("verify_ssl"), strict=False) auth_args = {"user": self.get_option("api_user")}
if not (self.get_option("api_token_id") and self.get_option("api_token_secret")):
auth_args["password"] = self.get_option("api_password")
else:
auth_args["token_name"] = self.get_option("api_token_id")
auth_args["token_value"] = self.get_option("api_token_secret")
verify_ssl = boolean(self.get_option("verify_ssl"), strict=False)
if not verify_ssl and HAS_URLLIB3: if not verify_ssl and HAS_URLLIB3:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
return ProxmoxAPI( return ProxmoxAPI(
self.get_option("server"), self.get_option("api_host"),
user=self.get_option("user"),
password=self.get_option("password"),
verify_ssl=verify_ssl, verify_ssl=verify_ssl,
timeout=self.get_option("auth_timeout") timeout=self.get_option("auth_timeout"),
**auth_args
) )
def _get_version(self): def _get_version(self):

View File

@ -58,7 +58,7 @@ options:
- Specify the token secret. - Specify the token secret.
type: str type: str
version_added: 1.3.0 version_added: 1.3.0
validate_certs: verify_ssl:
description: description:
- If C(false), SSL certificates will not be validated. - If C(false), SSL certificates will not be validated.
- This should only be used on personally controlled sites using self-signed certificates. - This should only be used on personally controlled sites using self-signed certificates.
@ -98,7 +98,7 @@ options:
description: description:
- Specify the BIOS implementation. - Specify the BIOS implementation.
type: str type: str
choices: ['seabios', 'ovmf'] choices: ["seabios", "ovmf"]
boot: boot:
description: description:
- Specify the boot order -> boot on floppy C(a), hard disk C(c), CD-ROM C(d), or network C(n). - Specify the boot order -> boot on floppy C(a), hard disk C(c), CD-ROM C(d), or network C(n).
@ -112,22 +112,22 @@ options:
type: str type: str
cicustom: cicustom:
description: description:
- 'cloud-init: Specify custom files to replace the automatically generated ones at start.' - "cloud-init: Specify custom files to replace the automatically generated ones at start."
type: str type: str
cipassword: cipassword:
description: description:
- 'cloud-init: password of default user to create.' - "cloud-init: password of default user to create."
type: str type: str
citype: citype:
description: description:
- 'cloud-init: Specifies the cloud-init configuration format.' - "cloud-init: Specifies the cloud-init configuration format."
- The default depends on the configured operating system type (C(ostype)). - The default depends on the configured operating system type (C(ostype)).
- We use the C(nocloud) format for Linux, and C(configdrive2) for Windows. - We use the C(nocloud) format for Linux, and C(configdrive2) for Windows.
type: str type: str
choices: ['nocloud', 'configdrive2'] choices: ["nocloud", "configdrive2"]
ciuser: ciuser:
description: description:
- 'cloud-init: username of default user to create.' - "cloud-init: username of default user to create."
type: str type: str
clone: clone:
description: description:
@ -187,7 +187,8 @@ options:
option has a default of C(qcow2). If I(proxmox_default_behavior) is set to C(no_defaults), option has a default of C(qcow2). If I(proxmox_default_behavior) is set to C(no_defaults),
not specifying this option is equivalent to setting it to C(unspecified). not specifying this option is equivalent to setting it to C(unspecified).
type: str type: str
choices: [ "cloop", "cow", "qcow", "qcow2", "qed", "raw", "vmdk", "unspecified" ] choices:
["cloop", "cow", "qcow", "qcow2", "qed", "raw", "vmdk", "unspecified"]
freeze: freeze:
description: description:
- Specify if PVE should freeze CPU at startup (use 'c' monitor command to start execution). - Specify if PVE should freeze CPU at startup (use 'c' monitor command to start execution).
@ -198,7 +199,7 @@ options:
- For VM templates, we try to create a linked clone by default. - For VM templates, we try to create a linked clone by default.
- Used only with clone - Used only with clone
type: bool type: bool
default: 'yes' default: "yes"
hostpci: hostpci:
description: description:
- Specify a hash/dictionary of map host pci devices into guest. C(hostpci='{"key":"value", "key":"value"}'). - Specify a hash/dictionary of map host pci devices into guest. C(hostpci='{"key":"value", "key":"value"}').
@ -220,7 +221,7 @@ options:
description: description:
- Enable/disable hugepages memory. - Enable/disable hugepages memory.
type: str type: str
choices: ['any', '2', '1024'] choices: ["any", "2", "1024"]
ide: ide:
description: description:
- A hash/dictionary of volume used as IDE hard disk or CD-ROM. C(ide='{"key":"value", "key":"value"}'). - A hash/dictionary of volume used as IDE hard disk or CD-ROM. C(ide='{"key":"value", "key":"value"}').
@ -232,11 +233,11 @@ options:
type: dict type: dict
ipconfig: ipconfig:
description: description:
- 'cloud-init: Set the IP configuration.' - "cloud-init: Set the IP configuration."
- A hash/dictionary of network ip configurations. C(ipconfig='{"key":"value", "key":"value"}'). - A hash/dictionary of network ip configurations. C(ipconfig='{"key":"value", "key":"value"}').
- Keys allowed are - C(ipconfig[n]) where 0 n network interfaces. - Keys allowed are - C(ipconfig[n]) where 0 n network interfaces.
- Values allowed are - C("[gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]"). - Values allowed are - C("[gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]").
- 'cloud-init: Specify IP addresses and gateways for the corresponding interface.' - "cloud-init: Specify IP addresses and gateways for the corresponding interface."
- IP addresses use CIDR notation, gateways are optional but they should be in the same subnet of specified IP address. - IP addresses use CIDR notation, gateways are optional but they should be in the same subnet of specified IP address.
- The special string 'dhcp' can be used for IP addresses to use DHCP, in which case no explicit gateway should be provided. - The special string 'dhcp' can be used for IP addresses to use DHCP, in which case no explicit gateway should be provided.
- For IPv6 the special string 'auto' can be used to use stateless autoconfiguration. - For IPv6 the special string 'auto' can be used to use stateless autoconfiguration.
@ -261,7 +262,7 @@ options:
description: description:
- Lock/unlock the VM. - Lock/unlock the VM.
type: str type: str
choices: ['migrate', 'backup', 'snapshot', 'rollback'] choices: ["migrate", "backup", "snapshot", "rollback"]
machine: machine:
description: description:
- Specifies the Qemu machine type. - Specifies the Qemu machine type.
@ -289,7 +290,7 @@ options:
type: str type: str
nameservers: nameservers:
description: description:
- 'cloud-init: DNS server IP address(es).' - "cloud-init: DNS server IP address(es)."
- If unset, PVE host settings are used. - If unset, PVE host settings are used.
type: list type: list
elements: str elements: str
@ -336,7 +337,21 @@ options:
- If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
option has a default of C(l26). option has a default of C(l26).
type: str type: str
choices: ['other', 'wxp', 'w2k', 'w2k3', 'w2k8', 'wvista', 'win7', 'win8', 'win10', 'l24', 'l26', 'solaris'] choices:
[
"other",
"wxp",
"w2k",
"w2k3",
"w2k8",
"wvista",
"win7",
"win8",
"win10",
"l24",
"l26",
"solaris",
]
parallel: parallel:
description: description:
- A hash/dictionary of map host parallel devices. C(parallel='{"key":"value", "key":"value"}'). - A hash/dictionary of map host parallel devices. C(parallel='{"key":"value", "key":"value"}').
@ -377,10 +392,18 @@ options:
description: description:
- Specifies the SCSI controller model. - Specifies the SCSI controller model.
type: str type: str
choices: ['lsi', 'lsi53c810', 'virtio-scsi-pci', 'virtio-scsi-single', 'megasas', 'pvscsi'] choices:
[
"lsi",
"lsi53c810",
"virtio-scsi-pci",
"virtio-scsi-single",
"megasas",
"pvscsi",
]
searchdomains: searchdomains:
description: description:
- 'cloud-init: Sets DNS search domain(s).' - "cloud-init: Sets DNS search domain(s)."
- If unset, PVE host settings are used. - If unset, PVE host settings are used.
type: list type: list
elements: str elements: str
@ -419,7 +442,7 @@ options:
type: int type: int
sshkeys: sshkeys:
description: description:
- 'cloud-init: SSH key to assign to the default user. NOT TESTED with multiple keys but a multi-line value should work.' - "cloud-init: SSH key to assign to the default user. NOT TESTED with multiple keys but a multi-line value should work."
type: str type: str
startdate: startdate:
description: description:
@ -437,7 +460,7 @@ options:
- Indicates desired state of the instance. - Indicates desired state of the instance.
- If C(current), the current state of the VM will be fetched. You can access it with C(results.status) - If C(current), the current state of the VM will be fetched. You can access it with C(results.status)
type: str type: str
choices: ['present', 'started', 'absent', 'stopped', 'restarted','current'] choices: ["present", "started", "absent", "stopped", "restarted", "current"]
default: present default: present
storage: storage:
description: description:
@ -481,7 +504,7 @@ options:
- If C(yes), the VM will be updated with new value. - If C(yes), the VM will be updated with new value.
- 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"
vcpus: vcpus:
description: description:
- Sets number of hotplugged vcpus. - Sets number of hotplugged vcpus.
@ -492,7 +515,20 @@ options:
- If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this - If I(proxmox_default_behavior) is set to C(compatiblity) (the default value), this
option has a default of C(std). option has a default of C(std).
type: str type: str
choices: ['std', 'cirrus', 'vmware', 'qxl', 'serial0', 'serial1', 'serial2', 'serial3', 'qxl2', 'qxl3', 'qxl4'] choices:
[
"std",
"cirrus",
"vmware",
"qxl",
"serial0",
"serial1",
"serial2",
"serial3",
"qxl2",
"qxl3",
"qxl4",
]
virtio: virtio:
description: description:
- A hash/dictionary of volume used as VIRTIO hard disk. C(virtio='{"key":"value", "key":"value"}'). - A hash/dictionary of volume used as VIRTIO hard disk. C(virtio='{"key":"value", "key":"value"}').
@ -545,8 +581,8 @@ EXAMPLES = """
name: spynal name: spynal
node: sabrewulf node: sabrewulf
net: net:
net0: 'virtio,bridge=vmbr1,rate=200' net0: "virtio,bridge=vmbr1,rate=200"
net1: 'e1000,bridge=vmbr2' net1: "e1000,bridge=vmbr2"
- name: Create new VM with one network interface, three virto hard disk, 4 cores, and 2 vcpus - name: Create new VM with one network interface, three virto hard disk, 4 cores, and 2 vcpus
xoxys.general.proxmox_kvm: xoxys.general.proxmox_kvm:
@ -556,11 +592,11 @@ EXAMPLES = """
name: spynal name: spynal
node: sabrewulf node: sabrewulf
net: net:
net0: 'virtio,bridge=vmbr1,rate=200' net0: "virtio,bridge=vmbr1,rate=200"
virtio: virtio:
virtio0: 'VMs_LVM:10' virtio0: "VMs_LVM:10"
virtio1: 'VMs:2,format=qcow2' virtio1: "VMs:2,format=qcow2"
virtio2: 'VMs:5,format=raw' virtio2: "VMs:5,format=raw"
cores: 4 cores: 4
vcpus: 2 vcpus: 2
@ -635,15 +671,15 @@ EXAMPLES = """
api_host: helldorado api_host: helldorado
name: spynal name: spynal
ide: ide:
ide2: 'local:cloudinit,format=qcow2' ide2: "local:cloudinit,format=qcow2"
ciuser: mylinuxuser ciuser: mylinuxuser
cipassword: supersecret cipassword: supersecret
searchdomains: 'mydomain.internal' searchdomains: "mydomain.internal"
nameservers: 1.1.1.1 nameservers: 1.1.1.1
net: net:
net0: 'virtio,bridge=vmbr1,tag=77' net0: "virtio,bridge=vmbr1,tag=77"
ipconfig: ipconfig:
ipconfig0: 'ip=192.168.1.1/24,gw=192.168.1.1' ipconfig0: "ip=192.168.1.1/24,gw=192.168.1.1"
- name: Create new VM using Cloud-Init with an ssh key - name: Create new VM using Cloud-Init with an ssh key
xoxys.general.proxmox_kvm: xoxys.general.proxmox_kvm:
@ -653,16 +689,16 @@ EXAMPLES = """
api_host: helldorado api_host: helldorado
name: spynal name: spynal
ide: ide:
ide2: 'local:cloudinit,format=qcow2' ide2: "local:cloudinit,format=qcow2"
sshkeys: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILJkVm98B71lD5XHfihwcYHE9TVpsJmK1vR1JcaU82L+' sshkeys: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILJkVm98B71lD5XHfihwcYHE9TVpsJmK1vR1JcaU82L+"
searchdomains: 'mydomain.internal' searchdomains: "mydomain.internal"
nameservers: nameservers:
- '1.1.1.1' - "1.1.1.1"
- '8.8.8.8' - "8.8.8.8"
net: net:
net0: 'virtio,bridge=vmbr1,tag=77' net0: "virtio,bridge=vmbr1,tag=77"
ipconfig: ipconfig:
ipconfig0: 'ip=192.168.1.1/24' ipconfig0: "ip=192.168.1.1/24"
- name: Start VM - name: Start VM
xoxys.general.proxmox_kvm: xoxys.general.proxmox_kvm:
@ -737,7 +773,7 @@ EXAMPLES = """
api_host: helldorado api_host: helldorado
name: spynal name: spynal
node: sabrewulf node: sabrewulf
delete: 'args,template,cpulimit' delete: "args,template,cpulimit"
- name: Revert a pending change - name: Revert a pending change
xoxys.general.proxmox_kvm: xoxys.general.proxmox_kvm:
@ -746,7 +782,8 @@ EXAMPLES = """
api_host: helldorado api_host: helldorado
name: spynal name: spynal
node: sabrewulf node: sabrewulf
revert: 'template,cpulimit' revert: "template,cpulimit"
""" """
RETURN = """ RETURN = """
@ -782,6 +819,16 @@ try:
except ImportError: except ImportError:
HAS_PROXMOXER = False HAS_PROXMOXER = False
try:
from requests.packages import urllib3
HAS_URLLIB3 = True
except ImportError:
try:
import urllib3
HAS_URLLIB3 = True
except ImportError:
HAS_URLLIB3 = False
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule, env_fallback from ansible.module_utils.basic import AnsibleModule, env_fallback
@ -1120,7 +1167,7 @@ def main():
template=dict(type="bool"), template=dict(type="bool"),
timeout=dict(type="int", default=30), timeout=dict(type="int", default=30),
update=dict(type="bool", default=False), update=dict(type="bool", default=False),
validate_certs=dict(type="bool", default=True), verify_ssl=dict(type="bool", default=True),
vcpus=dict(type="int"), vcpus=dict(type="int"),
vga=dict( vga=dict(
choices=[ choices=[
@ -1161,7 +1208,7 @@ def main():
state = module.params["state"] state = module.params["state"]
update = bool(module.params["update"]) update = bool(module.params["update"])
vmid = module.params["vmid"] vmid = module.params["vmid"]
validate_certs = module.params["validate_certs"] verify_ssl = module.params["verify_ssl"]
if module.params["proxmox_default_behavior"] is None: if module.params["proxmox_default_behavior"] is None:
module.params["proxmox_default_behavior"] = "compatibility" module.params["proxmox_default_behavior"] = "compatibility"
@ -1197,8 +1244,11 @@ def main():
auth_args["token_name"] = api_token_id auth_args["token_name"] = api_token_id
auth_args["token_value"] = api_token_secret auth_args["token_value"] = api_token_secret
if not verify_ssl and HAS_URLLIB3:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
try: try:
proxmox = ProxmoxAPI(api_host, verify_ssl=validate_certs, **auth_args) proxmox = ProxmoxAPI(api_host, verify_ssl=verify_ssl, **auth_args)
global PVE_MAJOR_VERSION global PVE_MAJOR_VERSION
version = proxmox_version(proxmox) version = proxmox_version(proxmox)
PVE_MAJOR_VERSION = 3 if version < LooseVersion("4.0") else version.version[0] PVE_MAJOR_VERSION = 3 if version < LooseVersion("4.0") else version.version[0]