Best Python code snippet using localstack_python
main.py
Source:main.py
...26 message = msg.get_body().decode('utf-8')27 28 # Create container name for run and obtain environment variables for the worker docker image29 container_name = _get_container_name(message)30 env_vars = _create_env_vars(message, container_name)31 32 # Create container group and run image33 _create_container_group(ACIConfig().resource_group.get_secret_value(), 34 container_name, 35 ACIConfig().location, 36 ACIConfig().image_name, 37 env_vars)3839 logging.info(f'Python ServiceBus queue trigger processed message: {message}')404142def _create_env_vars(message: str, container_name: str) -> List[EnvironmentVariable]:43 """Creates a number of environment variables needed for running the job.4445 Args:46 message (str): The message from the Azure Service Bus queue47 container_name (str):4849 Returns:50 List[EnvironmentVariable]: List of environment variables51 """52 msg_var = EnvironmentVariable(name='MESSAGE', value=message)53 container_name_var = EnvironmentVariable(name='CONTAINER_NAME', value=container_name)54 55 # Cosmos DB variables56 cosmos_endpoint_var = EnvironmentVariable(name='COSMOS_DB_ENDPOINT', value=CosmosSettings().cosmos_db_endpoint.get_secret_value())
...
terraform.py
Source:terraform.py
...7 os.path.dirname(os.path.dirname(os.path.realpath(__file__))),8 'tf_data'9)10def create(network_config):11 env_vars = _create_env_vars(network_config)12 state_flag = _create_state_flag(network_config)13 14 cwd = os.getcwd()15 os.chdir(TF_PATH)16 new = _state_exists(network_config)17 # Create18 if not new:19 runner.run(20 ['terraform', 'apply'] + env_vars + state_flag,21 retries=3, delay=15, delay_factor=222 )23 # Convert ips to csv24 ips = ",".join([25 "{}/32".format(ip) for ip in get_network_ips(network_config)26 ])27 # Create ingress from ips28 runner.run(29 ['terraform', 'apply'] + env_vars + state_flag + 30 ['--var', 'validator_ingress={}'.format(ips)],31 retries=3, delay=15, delay_factor=232 )33 os.chdir(cwd)34def destroy(network_config):35 env_vars = _create_env_vars(network_config)36 state_flag = _create_state_flag(network_config)37 cwd = os.getcwd()38 os.chdir(TF_PATH)39 # Destory40 runner.run(['terraform', 'destroy'] + env_vars + state_flag + ['--force'])41 os.chdir(cwd)42def _get_output(network_config):43 state_flag = _create_state_flag(network_config)44 # Get ips45 return yaml.load(runner.run(46 ['terraform', 'output', '-json'] + state_flag,47 capture_stdout=True48 ))49def get_network_ips(network_config):50 return _get_output(network_config)['ips']['value']51def get_node_name(node, network_config):52 return "{}-node{}".format(network_config['network_id'], node)53 54def get_node_ip(node, network_config):55 output = _get_output(network_config)56 node_name = get_node_name(node, network_config)57 i = 058 for node in output['tags']['value']:59 if node['Name'] == node_name:60 return output['ips']['value'][i]61 i += 162 raise LrException("Node `{}` not found.".format(node_name))63def _create_env_vars(config):64 return [65 '--var', 'network_id={}'.format(config['network_id']),66 '--var', 'environment={}'.format(config['environment']),67 '--var', 'host_user={}'.format(config['host_user']),68 '--var', 'owner={}'.format(config['owner']),69 '--var', 'region={}'.format(config['region']),70 '--var', 'count={}'.format(config['count']),71 '--var', 'ami={}'.format(config['image_id']),72 '--var', 'instance_type={}'.format(config['instance_type']),73 ]74def _state_exists(config):75 return os.path.exists(os.path.join(76 network.config.get_dir(config['network_id']), 77 'terraform.tfstate'...
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!!