예제 #1
0
def get_container_network_for_lambda():
    global LAMBDA_CONTAINER_NETWORK
    if config.LAMBDA_DOCKER_NETWORK:
        return config.LAMBDA_DOCKER_NETWORK
    if LAMBDA_CONTAINER_NETWORK is None:
        try:
            if config.is_in_docker:
                networks = DOCKER_CLIENT.get_networks(
                    bootstrap.get_main_container_name())
                LAMBDA_CONTAINER_NETWORK = networks[0]
            else:
                LAMBDA_CONTAINER_NETWORK = (
                    "bridge"  # use the default bridge network in case of host mode
                )
            LOG.info("Determined lambda container network: %s",
                     LAMBDA_CONTAINER_NETWORK)
        except Exception as e:
            container_name = bootstrap.get_main_container_name()
            LOG.info('Unable to get network name of main container "%s": %s',
                     container_name, e)
    return LAMBDA_CONTAINER_NETWORK
예제 #2
0
def get_main_container_network() -> Optional[str]:
    """
    Gets the main network of the LocalStack container (if we run in one, bridge otherwise)
    If there are multiple networks connected to the LocalStack container, we choose the first as "main" network

    :return: Network name
    """
    main_container_network = None
    try:
        if config.is_in_docker:
            networks = DOCKER_CLIENT.get_networks(get_main_container_name())
            main_container_network = networks[0]
        else:
            main_container_network = "bridge"  # use the default bridge network in case of host mode
        LOG.info("Determined main container network: %s",
                 main_container_network)
    except Exception as e:
        container_name = get_main_container_name()
        LOG.info('Unable to get network name of main container "%s": %s',
                 container_name, e)
    return main_container_network