def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
                             bridge, net_type, net_mtu, user_config,
                             is_ssh_address, is_container_address,
                             static_routes):
    """Process additional ip adds and append then to hosts as needed.

    If the host is found to be "is_metal" it will be marked as "on_metal"
    and will not have an additionally assigned IP address.

    :param key: ``str`` Component key name.
    :param inventory: ``dict``  Living dictionary of inventory.
    :param ip_q: ``object`` build queue of IP addresses.
    :param q_name: ``str`` key to use in host vars for storage.
    :param netmask: ``str`` netmask to use.
    :param interface: ``str`` interface name to set for the network.
    :param user_config: ``dict`` user defined configuration details.
    :param is_ssh_address: ``bol`` set this address as ansible_ssh_host.
    :param is_container_address: ``bol`` set this address to container_address.
    :param static_routes: ``list`` List containing static route dicts.
    """
    def network_entry():
        """Return a network entry for a container."""

        # TODO(cloudnull) After a few releases this conditional should be
        # simplified. The container address checking that is ssh address
        # is only being done to support old inventory.

        if is_metal:
            _network = dict()
        else:
            _network = {'interface': interface}

        if bridge:
            _network['bridge'] = bridge

        if net_type:
            _network['type'] = net_type

        if net_mtu:
            _network['mtu'] = net_mtu

        return _network

    def return_netmask():
        """Return the netmask for a container."""
        # TODO(cloudnull) After a few releases this conditional should be
        # simplified. The container address checking that is ssh address
        # is only being done to support old inventory.
        _old_netmask = container.get(old_netmask)
        if _old_netmask:
            return container.pop(old_netmask)
        elif netmask:
            return netmask

    base_hosts = inventory['_meta']['hostvars']
    lookup = inventory.get(key, list())

    if 'children' in lookup and lookup['children']:
        for group in lookup['children']:
            _add_additional_networks(
                group,
                inventory,
                ip_q,
                q_name,
                netmask,
                interface,
                bridge,
                net_type,
                net_mtu,
                user_config,
                is_ssh_address,
                is_container_address,
                static_routes
            )

    # Make sure the lookup object has a value.
    if lookup:
        hosts = lookup.get('hosts')
        if not hosts:
            return
    else:
        return

    # TODO(cloudnull) after a few releases this should be removed.
    if q_name:
        old_address = '%s_address' % q_name
    else:
        old_address = '%s_address' % interface
    old_netmask = '%s_netmask' % q_name

    for container_host in hosts:
        container = base_hosts[container_host]

        # TODO(cloudnull) after a few releases this should be removed.
        # This removes the old container network value that now serves purpose.
        container.pop('container_network', None)

        if 'container_networks' in container:
            networks = container['container_networks']
        else:
            networks = container['container_networks'] = dict()

        is_metal = False
        properties = container.get('properties')
        if properties:
            is_metal = properties.get('is_metal', False)

        # This should convert found addresses based on q_name + "_address"
        #  and then build the network if its not found.
        if not is_metal and old_address not in networks:
            network = networks[old_address] = network_entry()
            if old_address in container and container[old_address]:
                network['address'] = container.pop(old_address)
            elif not is_metal:
                address = get_ip_address(name=q_name, ip_q=ip_q)
                if address:
                    network['address'] = address

            network['netmask'] = return_netmask()
        elif is_metal:
            network = networks[old_address] = network_entry()
            network['netmask'] = return_netmask()
            # TODO(cloudnull) After a few releases this conditional should be
            # simplified. The container address checking that is ssh address
            # is only being done to support old inventory.
            if old_address in container and container[old_address]:
                network['address'] = container.pop(old_address)
            else:
                if is_ssh_address or is_container_address:
                    # Container physical host group
                    cphg = container.get('physical_host_group')

                    # user_config data from the container physical host group
                    phg = user_config[cphg][container_host]
                    network['address'] = phg['ip']

        if is_ssh_address is True:
            container['ansible_ssh_host'] = networks[old_address]['address']

        if is_container_address is True:
            container['container_address'] = networks[old_address]['address']

        if static_routes:
            # NOTE: networks[old_address]['static_routes'] will get
            #       regenerated on each run
            networks[old_address]['static_routes'] = []
            for s in static_routes:
                # only add static routes if they are specified correctly
                if 'cidr' in s and 'gateway' in s:
                    networks[old_address]['static_routes'].append(s)
dataset/ETHPy150Open openstack/openstack-ansible/playbooks/inventory/dynamic_inventory.py/_add_additional_networks/original