mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* proxmox: ignore QEMU templates altogether
* add changelog fragment
* add test case
* Update changelogs/fragments/1185-proxmox-ignore-qemu-templates.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c488cb1dd3
)
Co-authored-by: Krzysztof Dąbrowski <krzysdabro@live.com>
This commit is contained in:
parent
29819e04ec
commit
be27bf1eae
3 changed files with 31 additions and 6 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- proxmox inventory plugin - ignore QEMU templates altogether instead of skipping the creation of the host in the inventory (https://github.com/ansible-collections/community.general/pull/1185).
|
|
@ -300,10 +300,12 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
node_qemu_group = self.to_safe('%s%s' % (self.get_option('group_prefix'), ('%s_qemu' % node['node']).lower()))
|
node_qemu_group = self.to_safe('%s%s' % (self.get_option('group_prefix'), ('%s_qemu' % node['node']).lower()))
|
||||||
self.inventory.add_group(node_qemu_group)
|
self.inventory.add_group(node_qemu_group)
|
||||||
for qemu in self._get_qemu_per_node(node['node']):
|
for qemu in self._get_qemu_per_node(node['node']):
|
||||||
if not qemu['template']:
|
if qemu['template']:
|
||||||
self.inventory.add_host(qemu['name'])
|
continue
|
||||||
self.inventory.add_child(qemu_group, qemu['name'])
|
|
||||||
self.inventory.add_child(node_qemu_group, qemu['name'])
|
self.inventory.add_host(qemu['name'])
|
||||||
|
self.inventory.add_child(qemu_group, qemu['name'])
|
||||||
|
self.inventory.add_child(node_qemu_group, qemu['name'])
|
||||||
|
|
||||||
# get QEMU status
|
# get QEMU status
|
||||||
self._get_vm_status(node['node'], qemu['vmid'], 'qemu', qemu['name'])
|
self._get_vm_status(node['node'], qemu['vmid'], 'qemu', qemu['name'])
|
||||||
|
|
|
@ -75,7 +75,7 @@ def get_json(url):
|
||||||
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu":
|
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu":
|
||||||
# _get_qemu_per_node
|
# _get_qemu_per_node
|
||||||
return [{"name": "test-qemu",
|
return [{"name": "test-qemu",
|
||||||
"cpus": 1,
|
"cpus": 1,
|
||||||
"mem": 1000,
|
"mem": 1000,
|
||||||
"template": "",
|
"template": "",
|
||||||
"diskread": 0,
|
"diskread": 0,
|
||||||
|
@ -89,7 +89,23 @@ def get_json(url):
|
||||||
"vmid": "101",
|
"vmid": "101",
|
||||||
"uptime": 1000,
|
"uptime": 1000,
|
||||||
"disk": 0,
|
"disk": 0,
|
||||||
"status": "running"}]
|
"status": "running"},
|
||||||
|
{"name": "test-qemu-template",
|
||||||
|
"cpus": 1,
|
||||||
|
"mem": 0,
|
||||||
|
"template": 1,
|
||||||
|
"diskread": 0,
|
||||||
|
"cpu": 0,
|
||||||
|
"maxmem": 1000,
|
||||||
|
"diskwrite": 0,
|
||||||
|
"netout": 0,
|
||||||
|
"pid": "1001",
|
||||||
|
"netin": 0,
|
||||||
|
"maxdisk": 1000,
|
||||||
|
"vmid": "9001",
|
||||||
|
"uptime": 0,
|
||||||
|
"disk": 0,
|
||||||
|
"status": "stopped"}]
|
||||||
elif url == "https://localhost:8006/api2/json/pools/test":
|
elif url == "https://localhost:8006/api2/json/pools/test":
|
||||||
# _get_members_per_pool
|
# _get_members_per_pool
|
||||||
return {"members": [{"uptime": 1000,
|
return {"members": [{"uptime": 1000,
|
||||||
|
@ -174,6 +190,7 @@ def test_populate(inventory, mocker):
|
||||||
|
|
||||||
# get different hosts
|
# get different hosts
|
||||||
host_qemu = inventory.inventory.get_host('test-qemu')
|
host_qemu = inventory.inventory.get_host('test-qemu')
|
||||||
|
host_qemu_template = inventory.inventory.get_host('test-qemu-template')
|
||||||
host_lxc = inventory.inventory.get_host('test-lxc')
|
host_lxc = inventory.inventory.get_host('test-lxc')
|
||||||
host_node = inventory.inventory.get_host('testnode')
|
host_node = inventory.inventory.get_host('testnode')
|
||||||
|
|
||||||
|
@ -185,3 +202,6 @@ def test_populate(inventory, mocker):
|
||||||
# check if lxc-test has been discovered correctly
|
# check if lxc-test has been discovered correctly
|
||||||
group_lxc = inventory.inventory.groups['proxmox_all_lxc']
|
group_lxc = inventory.inventory.groups['proxmox_all_lxc']
|
||||||
assert group_lxc.hosts == [host_lxc]
|
assert group_lxc.hosts == [host_lxc]
|
||||||
|
|
||||||
|
# check if qemu template is not present
|
||||||
|
assert host_qemu_template is None
|
||||||
|
|
Loading…
Reference in a new issue