mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Xen orchestra inventory: Added groups, keyed_groups and compose support (#3766)
* Xen orchestra inventory: Added groups, keyed_groups and compose support * Update plugins/inventory/xen_orchestra.py Remove extra params declaration Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
25e80762aa
commit
336f9465cb
2 changed files with 28 additions and 1 deletions
|
@ -69,6 +69,11 @@ simple_config_file:
|
||||||
password: xo_pwd
|
password: xo_pwd
|
||||||
validate_certs: true
|
validate_certs: true
|
||||||
use_ssl: true
|
use_ssl: true
|
||||||
|
groups:
|
||||||
|
kube_nodes: "'kube_node' in tags"
|
||||||
|
compose:
|
||||||
|
ansible_port: 2222
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -165,6 +170,12 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
'hosts': self.get_object('host'),
|
'hosts': self.get_object('host'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _apply_constructable(self, name, variables):
|
||||||
|
strict = self.get_option('strict')
|
||||||
|
self._add_host_to_composed_groups(self.get_option('groups'), variables, name, strict=strict)
|
||||||
|
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), variables, name, strict=strict)
|
||||||
|
self._set_composite_vars(self.get_option('compose'), variables, name, strict=strict)
|
||||||
|
|
||||||
def _add_vms(self, vms, hosts, pools):
|
def _add_vms(self, vms, hosts, pools):
|
||||||
for uuid, vm in vms.items():
|
for uuid, vm in vms.items():
|
||||||
group = 'with_ip'
|
group = 'with_ip'
|
||||||
|
@ -213,6 +224,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
self.inventory.set_variable(
|
self.inventory.set_variable(
|
||||||
entry_name, 'os_version', vm['os_version'])
|
entry_name, 'os_version', vm['os_version'])
|
||||||
|
|
||||||
|
self._apply_constructable(entry_name, self.inventory.get_host(entry_name).get_vars())
|
||||||
|
|
||||||
def _add_hosts(self, hosts, pools):
|
def _add_hosts(self, hosts, pools):
|
||||||
for host in hosts.values():
|
for host in hosts.values():
|
||||||
entry_name = host['uuid']
|
entry_name = host['uuid']
|
||||||
|
|
|
@ -129,6 +129,19 @@ objects = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_option(option):
|
||||||
|
if option == 'groups':
|
||||||
|
return {}
|
||||||
|
elif option == 'keyed_groups':
|
||||||
|
return []
|
||||||
|
elif option == 'compose':
|
||||||
|
return {}
|
||||||
|
elif option == 'strict':
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def serialize_groups(groups):
|
def serialize_groups(groups):
|
||||||
return list(map(str, groups))
|
return list(map(str, groups))
|
||||||
|
|
||||||
|
@ -144,7 +157,8 @@ def test_verify_file_bad_config(inventory):
|
||||||
assert inventory.verify_file('foobar.xen_orchestra.yml') is False
|
assert inventory.verify_file('foobar.xen_orchestra.yml') is False
|
||||||
|
|
||||||
|
|
||||||
def test_populate(inventory):
|
def test_populate(inventory, mocker):
|
||||||
|
inventory.get_option = mocker.MagicMock(side_effect=get_option)
|
||||||
inventory._populate(objects)
|
inventory._populate(objects)
|
||||||
actual = sorted(inventory.inventory.hosts.keys())
|
actual = sorted(inventory.inventory.hosts.keys())
|
||||||
expected = sorted(['c96ec4dd-28ac-4df4-b73c-4371bd202728', '222d8594-9426-468a-ad69-7a6f02330fa3',
|
expected = sorted(['c96ec4dd-28ac-4df4-b73c-4371bd202728', '222d8594-9426-468a-ad69-7a6f02330fa3',
|
||||||
|
|
Loading…
Reference in a new issue