Best Python code snippet using localstack_python
localstack.py
Source:localstack.py  
...42    name="docker", help="Query information about the LocalStack Docker image and runtime"43)44def cmd_status_docker():45    with console.status("Querying Docker status"):46        print_docker_status()47@localstack_status.command(name="services", help="Query information about running services")48def cmd_status_services():49    import requests50    from localstack import config51    url = config.get_edge_url()52    try:53        health = requests.get(f"{url}/health")54        doc = health.json()55        services = doc.get("services", [])56        print_service_table(services)57    except requests.ConnectionError:58        err = "[bold][red]:heavy_multiplication_x: ERROR[/red][/bold]"59        console.print(f"{err}: could not connect to LocalStack health endpoint at {url}")60        if config.DEBUG:61            console.print_exception()62        sys.exit(1)63@localstack.command(name="start", help="Start LocalStack")64@click.option("--docker", is_flag=True, help="Start LocalStack in a docker container (default)")65@click.option("--host", is_flag=True, help="Start LocalStack directly on the host")66@click.option("--no-banner", is_flag=True, help="Disable LocalStack banner", default=False)67def cmd_start(docker: bool, host: bool, no_banner: bool):68    if docker and host:69        raise click.ClickException("Please specify either --docker or --host")70    if not no_banner:71        print_banner()72        print_version()73        console.line()74    from localstack.utils import bootstrap75    if not no_banner:76        if host:77            console.log("starting LocalStack in host mode :laptop_computer:")78        else:79            console.log("starting LocalStack in Docker mode :whale:")80        console.rule("LocalStack Runtime Log (press [bold][yellow]CTRL-C[/yellow][/bold] to quit)")81    if host:82        bootstrap.start_infra_locally()83    else:84        bootstrap.start_infra_in_docker()85@localstack_config.command(86    name="validate", help="Validate your LocalStack configuration (e.g., your docker-compose.yml)"87)88@click.option(89    "--file",90    default="docker-compose.yml",91    type=click.Path(exists=True, file_okay=True, readable=True),92)93def cmd_config_validate(file):94    from rich.panel import Panel95    from localstack.utils import bootstrap96    try:97        if bootstrap.validate_localstack_config(file):98            console.print("[green]:heavy_check_mark:[/green] config valid")99            sys.exit(0)100        else:101            console.print("[red]:heavy_multiplication_x:[/red] validation error")102            sys.exit(1)103    except Exception as e:104        console.print(Panel(str(e), title="[red]Error[/red]", expand=False))105        console.print("[red]:heavy_multiplication_x:[/red] validation error")106        sys.exit(1)107@localstack.command(name="ssh", help="Obtain a shell in the running LocalStack container")108def cmd_ssh():109    from localstack import config110    from localstack.utils.docker_utils import DOCKER_CLIENT111    from localstack.utils.run import run112    if not DOCKER_CLIENT.is_container_running(config.MAIN_CONTAINER_NAME):113        raise click.ClickException(114            'Expected a running container named "%s", but found none' % config.MAIN_CONTAINER_NAME115        )116    try:117        process = run("docker exec -it %s bash" % config.MAIN_CONTAINER_NAME, tty=True)118        process.wait()119    except KeyboardInterrupt:120        pass121# legacy support122@localstack.group(123    name="infra",124    help="Manipulate LocalStack infrastructure (legacy)",125)126def infra():127    pass128@infra.command("start")129@click.pass_context130@click.option("--docker", is_flag=True, help="Start LocalStack in a docker container (default)")131@click.option("--host", is_flag=True, help="Start LocalStack directly on the host")132def cmd_infra_start(ctx, *args, **kwargs):133    ctx.invoke(cmd_start, *args, **kwargs)134def print_docker_status():135    from rich.table import Table136    from localstack import config137    from localstack.utils import docker138    from localstack.utils.bootstrap import (139        get_docker_image_details,140        get_main_container_ip,141        get_main_container_name,142        get_server_version,143    )144    grid = Table(show_header=False)145    grid.add_column()146    grid.add_column()147    # version148    grid.add_row("Runtime version", "[bold]%s[/bold]" % get_server_version())...test_fattree.py
Source:test_fattree.py  
...7try:8    # topo = StaticPerfectFatTree(hosts=2, host_type="docker")9    topo = StaticPerfectFatTree(hosts=32, host_type="process")10    exp = emu.setup(topo)11    emu.print_docker_status()12    emu.cli()13    emu.wait()14except Exception as e:15    print(e)16finally:...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
