How to use get_main_container_name method in localstack

Best Python code snippet using localstack_python

diagnose.py

Source:diagnose.py Github

copy

Full Screen

...56ENDPOINT_RESOLVE_LIST = ["localhost.localstack.cloud", "api.localstack.cloud"]57INSPECT_DIRECTORIES = [DEFAULT_VOLUME_DIR, "/tmp"]58def get_localstack_logs() -> Union[str, Dict]:59 try:60 result = DOCKER_CLIENT.get_container_logs(get_main_container_name())61 except Exception as e:62 result = "error getting docker logs for container: %s" % e63 return {"docker": result}64def get_localstack_config() -> Dict:65 result = {}66 for k, v in inspect.getmembers(config):67 if k in EXCLUDE_CONFIG_KEYS:68 continue69 if inspect.isbuiltin(v):70 continue71 if inspect.isfunction(v):72 continue73 if inspect.ismodule(v):74 continue75 if inspect.isclass(v):76 continue77 if "typing." in str(type(v)):78 continue79 if hasattr(v, "__dict__"):80 result[k] = v.__dict__81 else:82 result[k] = v83 return result84def inspect_main_container() -> Union[str, Dict]:85 try:86 return DOCKER_CLIENT.inspect_container(get_main_container_name())87 except Exception as e:88 return f"inspect failed: {e}"89def get_localstack_version() -> Dict[str, str]:90 return {91 "build-date": os.environ.get("LOCALSTACK_BUILD_DATE"),92 "build-git-hash": os.environ.get("LOCALSTACK_BUILD_GIT_HASH"),93 "build-version": os.environ.get("LOCALSTACK_BUILD_VERSION"),94 }95def resolve_endpoints() -> Dict[str, str]:96 result = {}97 for endpoint in ENDPOINT_RESOLVE_LIST:98 try:99 resolved_endpoint = socket.gethostbyname(endpoint)100 except Exception as e:...

Full Screen

Full Screen

container_networking.py

Source:container_networking.py Github

copy

Full Screen

...15 """16 main_container_network = None17 try:18 if config.is_in_docker:19 networks = DOCKER_CLIENT.get_networks(get_main_container_name())20 main_container_network = networks[0]21 else:22 main_container_network = "bridge" # use the default bridge network in case of host mode23 LOG.info("Determined main container network: %s", main_container_network)24 except Exception as e:25 container_name = get_main_container_name()26 LOG.info('Unable to get network name of main container "%s": %s', container_name, e)27 return main_container_network28@lru_cache()29def get_endpoint_for_network(network: Optional[str] = None) -> str:30 """31 Get the LocalStack endpoint (= IP address) on the given network.32 If a network is given, it will return the IP address/hostname of LocalStack on that network33 If omitted, it will return the IP address/hostname of the main container network34 This is a cached call, clear cache if networks might have changed35 :param network: Network to return the endpoint for36 :return: IP address or hostname of LS on the given network37 """38 container_name = get_main_container_name()39 network = network or get_main_container_network()40 main_container_ip = None41 try:42 if config.is_in_docker:43 main_container_ip = DOCKER_CLIENT.get_container_ipv4_for_network(44 container_name_or_id=container_name,45 container_network=network,46 )47 else:48 # default gateway for the network should be the host49 # (only under Linux - otherwise fall back to DOCKER_HOST_FROM_CONTAINER below)50 if config.is_in_linux:51 main_container_ip = DOCKER_CLIENT.inspect_network(network)["IPAM"]["Config"][0][52 "Gateway"53 ]54 LOG.info("Determined main container target IP: %s", main_container_ip)55 except Exception as e:56 LOG.info('Unable to get IP address of main Docker container "%s": %s', container_name, e)57 # return (1) predefined endpoint host, or (2) main container IP, or (3) Docker host (e.g., bridge IP)58 return main_container_ip or config.DOCKER_HOST_FROM_CONTAINER59def get_main_container_ip():60 """61 Get the container IP address of the LocalStack container.62 Use get_endpoint_for network where possible, as it allows better control about which address to return63 :return: IP address of LocalStack container64 """65 container_name = get_main_container_name()66 return DOCKER_CLIENT.get_container_ip(container_name)67def get_main_container_id():68 """69 Return the container ID of the LocalStack container70 :return: container ID71 """72 container_name = get_main_container_name()73 try:74 return DOCKER_CLIENT.get_container_id(container_name)75 except ContainerException:76 return None77@lru_cache()78def get_main_container_name():79 """80 Returns the container name of the LocalStack container81 :return: LocalStack container name82 """83 hostname = os.environ.get("HOSTNAME")84 if hostname:85 try:86 return DOCKER_CLIENT.get_container_name(hostname)87 except ContainerException:88 return config.MAIN_CONTAINER_NAME89 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful