Enchance reference_group logic for inventory
reference_group [1] is a key used to filter out provider_networks assignment to containers more easily. So one can use same group_binds but execute extra filtering using reference_group. This is especially useful in multi-pod or multi-az deployments. However, currently reference_group expects always to find hosts directly in the group, but not looking inside children groups. The patch changes the logic of how reference_group lookups for the hosts in group by descending into each child and populating the list to compare with. [1] https://docs.openstack.org/openstack-ansible/latest/user/l3pods/example.html#environment-layout Change-Id: I7faccad43e55692656ba3046165e6eecd38a9984
This commit is contained in:
parent
0e6e1a5654
commit
120c942fda
@ -128,6 +128,22 @@ class GroupConflict(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _hosts_in_group(group, inventory):
|
||||
"""Generator that flattens nested inventory data.
|
||||
|
||||
:param group: The group name for which to find hosts for.
|
||||
:param inventory: An dictionary representing the inventory data.
|
||||
|
||||
:yields: Each host found in the inventory structure within the group.
|
||||
"""
|
||||
inv = inventory.get(group)
|
||||
for host in inv.get("hosts", list()):
|
||||
yield host
|
||||
|
||||
for child in inv.get("children", list()):
|
||||
yield from _hosts_in_group(child, inventory)
|
||||
|
||||
|
||||
def _parse_belongs_to(key, belongs_to, inventory):
|
||||
"""Parse all items in a `belongs_to` list.
|
||||
|
||||
@ -628,7 +644,7 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
|
||||
|
||||
physical_host = container.get('physical_host')
|
||||
if (reference_group and physical_host
|
||||
not in inventory.get(reference_group).get('hosts')):
|
||||
not in _hosts_in_group(reference_group, inventory)):
|
||||
continue
|
||||
|
||||
# TODO(cloudnull) after a few releases this should be removed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user