Esempio n. 1
0
def container_skel_load(container_skel, inventory, config):
    """Build out all containers as defined in the environment file.

    :param container_skel: ``dict`` container skeleton for all known containers
    :param inventory: ``dict``  Living dictionary of inventory
    :param config: ``dict``  User defined information
    """
    logger.debug("Loading container skeleton")

    for key, value in container_skel.items():
        contains_in = value.get('contains', False)
        belongs_to_in = value.get('belongs_to', False)
        if contains_in or belongs_to_in:
            for assignment in value['contains']:
                for container_type in value['belongs_to']:
                    _add_container_hosts(assignment, config, key,
                                         container_type, inventory,
                                         value.get('properties', {}))
    else:
        cidr_networks = config.get('cidr_networks')
        provider_queues = {}
        for net_name in cidr_networks:
            ip_q = ip.load_optional_q(cidr_networks, cidr_name=net_name)
            provider_queues[net_name] = ip_q
            if ip_q is not None:
                net = netaddr.IPNetwork(cidr_networks.get(net_name))
                q_netmask = '{}_netmask'.format(net_name)
                provider_queues[q_netmask] = str(net.netmask)

        overrides = config['global_overrides']
        # iterate over a list of provider_networks, var=pn
        pns = overrides.get('provider_networks', list())
        for pn in pns:
            # p_net are the provider_network values
            p_net = pn.get('network')
            if not p_net:
                continue

            q_name = p_net.get('ip_from_q')
            ip_from_q = provider_queues.get(q_name)
            if ip_from_q:
                netmask = provider_queues['{}_netmask'.format(q_name)]
            else:
                netmask = None

            for group in p_net.get('group_binds', list()):
                _add_additional_networks(
                    key=group,
                    inventory=inventory,
                    ip_q=ip_from_q,
                    q_name=q_name,
                    netmask=netmask,
                    interface=p_net['container_interface'],
                    bridge=p_net['container_bridge'],
                    net_type=p_net.get('container_type'),
                    net_mtu=p_net.get('container_mtu'),
                    user_config=config,
                    is_ssh_address=p_net.get('is_ssh_address'),
                    is_container_address=p_net.get('is_container_address'),
                    static_routes=p_net.get('static_routes'),
                    reference_group=p_net.get('reference_group'),
                    address_prefix=p_net.get('address_prefix'))

    populate_lxc_hosts(inventory)
def container_skel_load(container_skel, inventory, config):
    """Build out all containers as defined in the environment file.

    :param container_skel: ``dict`` container skeleton for all known containers
    :param inventory: ``dict``  Living dictionary of inventory
    :param config: ``dict``  User defined information
    """
    logger.debug("Loading container skeleton")

    for key, value in container_skel.items():
        contains_in = value.get('contains', False)
        belongs_to_in = value.get('belongs_to', False)
        if contains_in or belongs_to_in:
            for assignment in value['contains']:
                for container_type in value['belongs_to']:
                    _add_container_hosts(
                        assignment,
                        config,
                        key,
                        container_type,
                        inventory,
                        value.get('properties', {})
                    )
    else:
        cidr_networks = config.get('cidr_networks')
        provider_queues = {}
        for net_name in cidr_networks:
            ip_q = ip.load_optional_q(
                cidr_networks, cidr_name=net_name
            )
            provider_queues[net_name] = ip_q
            if ip_q is not None:
                net = netaddr.IPNetwork(cidr_networks.get(net_name))
                q_netmask = '{}_netmask'.format(net_name)
                provider_queues[q_netmask] = str(net.netmask)

        overrides = config['global_overrides']
        # iterate over a list of provider_networks, var=pn
        pns = overrides.get('provider_networks', list())
        for pn in pns:
            # p_net are the provider_network values
            p_net = pn.get('network')
            if not p_net:
                continue

            q_name = p_net.get('ip_from_q')
            ip_from_q = provider_queues.get(q_name)
            if ip_from_q:
                netmask = provider_queues['{}_netmask'.format(q_name)]
            else:
                netmask = None

            for group in p_net.get('group_binds', list()):
                _add_additional_networks(
                    key=group,
                    inventory=inventory,
                    ip_q=ip_from_q,
                    q_name=q_name,
                    netmask=netmask,
                    interface=p_net['container_interface'],
                    bridge=p_net['container_bridge'],
                    net_type=p_net.get('container_type'),
                    net_mtu=p_net.get('container_mtu'),
                    user_config=config,
                    is_ssh_address=p_net.get('is_ssh_address'),
                    is_container_address=p_net.get('is_container_address'),
                    static_routes=p_net.get('static_routes')
                )

    populate_lxc_hosts(inventory)