Best Python code snippet using localstack_python
gateways.py
Source:gateways.py
...94 self.save()95 except KeyError as k:96 logger.debug("delete_internet_gateways::KeyError::{}".format(k.args[0]))97 return 098 def create_nat_gateway(self, affinity_group=0):99 logger.info("create_nat_gateway::Executing")100 self.refresh_internet_gateway()101 if 'InternetGateway' not in self:102 raise Exception("No Internet Gateway")103 data = self.ec2_client.allocate_address(Domain='vpc')104 eipalloc_id = data['AllocationId']105 logger.debug("create_nat_gateway::create_nat_gateway::data::{}".format(data))106 subnet_id = self.get_af_subnets(affinity_group)[0]107 res = self.ec2_client.create_nat_gateway(108 AllocationId=eipalloc_id,109 SubnetId=subnet_id)110 meta = res['ResponseMetadata']111 data = res['NatGateway']112 logger.debug("create_nat_gateway::create_nat_gateway::meta::{}".format(meta))113 logger.debug("create_nat_gateway::create_nat_gateway::data::{}".format(data))114 ngw_id = data['NatGatewayId']115 self.sleep()116 logger.info("create_nat_gateway::waiter::{}".format(ngw_id))117 waiter = self.ec2_client.get_waiter('nat_gateway_available')118 waiter.wait(NatGatewayIds=[ngw_id])119 res = self.ec2_client.create_tags(120 Resources=[ngw_id],121 Tags=[{'Key': 'affinity_group', 'Value': str(affinity_group)}])...
nat_gateways.py
Source:nat_gateways.py
1from moto.core.responses import BaseResponse2from moto.ec2.utils import filters_from_querystring, add_tag_specification3class NatGateways(BaseResponse):4 def create_nat_gateway(self):5 subnet_id = self._get_param("SubnetId")6 allocation_id = self._get_param("AllocationId")7 connectivity_type = self._get_param("ConnectivityType")8 tags = self._get_multi_param("TagSpecification")9 tags = add_tag_specification(tags)10 nat_gateway = self.ec2_backend.create_nat_gateway(11 subnet_id=subnet_id,12 allocation_id=allocation_id,13 tags=tags,14 connectivity_type=connectivity_type,15 )16 template = self.response_template(CREATE_NAT_GATEWAY)17 return template.render(nat_gateway=nat_gateway)18 def delete_nat_gateway(self):19 nat_gateway_id = self._get_param("NatGatewayId")20 nat_gateway = self.ec2_backend.delete_nat_gateway(nat_gateway_id)21 template = self.response_template(DELETE_NAT_GATEWAY_RESPONSE)22 return template.render(nat_gateway=nat_gateway)23 def describe_nat_gateways(self):24 filters = filters_from_querystring(self.querystring)...
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!!