Best Python code snippet using localstack_python
test_vpc_peering_connection.py
Source:test_vpc_peering_connection.py  
...224    225    connection_class = VPCConnection226    def default_body(self):227        return self.ACCEPT_VPC_PEERING_CONNECTION228    def test_accept_vpc_peering_connection(self):229        self.set_http_response(status_code=200)230        vpc_peering_connection = self.service_connection.accept_vpc_peering_connection('pcx-1a2b3c4d')231        self.assertEqual(vpc_peering_connection.id, 'pcx-1a2b3c4d')232        self.assertEqual(vpc_peering_connection.status_code, 'active')233        self.assertEqual(vpc_peering_connection.status_message, 'Active')234        self.assertEqual(vpc_peering_connection.requester_vpc_info.owner_id, '123456789012')235        self.assertEqual(vpc_peering_connection.requester_vpc_info.vpc_id, 'vpc-1a2b3c4d')236        self.assertEqual(vpc_peering_connection.requester_vpc_info.cidr_block, '10.0.0.0/28')237        self.assertEqual(vpc_peering_connection.accepter_vpc_info.owner_id, '777788889999')238        self.assertEqual(vpc_peering_connection.accepter_vpc_info.vpc_id, 'vpc-111aaa22')239        self.assertEqual(vpc_peering_connection.accepter_vpc_info.cidr_block, '10.0.1.0/28')240if __name__ == '__main__':...peering_connection.py
Source:peering_connection.py  
...52	ec2 = boto3.client('ec2', region_name=requester_region)53	response = ec2.create_vpc_peering_connection(VpcId=requester_vpc_id, PeerVpcId=accepter_vpc_id, PeerRegion=accepter_region)54	PeeringConnectionId = response['VpcPeeringConnection']['VpcPeeringConnectionId']55	return PeeringConnectionId56def accept_vpc_peering_connection(PeeringConnectionId, accepter_region):57	"""58		Read input data of established vpc peering connection and 59		corresponding region of the accepting vpc60		Args:61			PeeringConnectionId: Id of the peering connection62			accepter_region: The region of the accepting vpc63		Returns:64			peering connection status code    65	"""66	ec2 = boto3.client('ec2', region_name=accepter_region)67	response = ec2.accept_vpc_peering_connection(VpcPeeringConnectionId=PeeringConnectionId)68	connection_status = response['VpcPeeringConnection']['Status']['Code']69	return connection_status70def get_pairing_config(vpc_region_keypairs):71	"""72		Read input of vpc id and region for creating peering connection73		Args:74		   vpc_region_keypairs: vpc id and region pair75		Returns:76		   First item in the above list and a concatenated list77		   comprising of the second to end items 78   """79	popped_vpc = vpc_region_keypairs.pop(0)80	return [popped_vpc, vpc_region_keypairs]81def establish_vpc_connection(main_vpc, pairing_vpcs):82	"""83		Read configuration list with a popped item and a concatenated list84		comprising of the second to end items   85		Args:86			main_vpc: first vpc_id_region keypair87			pairing_vpcs: The rest of the vpc_id_region-keypair in the input list88		Returns:89			peering connection id and status code of connection    90	"""91	connection_state = []   92	requester_region = main_vpc['REGION']93	requester_vpc_id = main_vpc ['VPCID']94	for vpc in pairing_vpcs:95		accepter_region = vpc['REGION']96		accepter_vpc_id = vpc ['VPCID']97		peering_connection_id = request_vpc_peering_connection(accepter_vpc_id, requester_vpc_id, accepter_region, requester_region)98		# wait for peering lifecycle to transition from 'provisioning' to 'active'99		sleep(5)100		101		peering_connection_status = accept_vpc_peering_connection(peering_connection_id, accepter_region)102		status = {}103		status['Connection ID'] = peering_connection_id104		status['Status'] = peering_connection_status105		connection_state.append(status)106	return connection_state107def main():108	# Define global variables109	CONFIGS=sys.argv[1]110	try:111		# Create a list of vpc_id with region pair 112		vpc_region_keypairs = get_vpc_ids(CONFIGS)113		# Create a clone list to work with114		vpc_region_keypairs_clone = list(vpc_region_keypairs)115		# iterate through the cloned list to establish peering connection...vpc.py
Source:vpc.py  
...88            PeerVpcId=accepter_vpc_id,89            VpcId=requester_vpc_id,90            PeerRegion='ap-southeast-1'91        )92    def accept_vpc_peering_connection(self, vpc_peering_connection_id):93        print('Accepting VPC Peering Connection ' + vpc_peering_connection_id)94        return self.client.accept_vpc_peering_connection(95            VpcPeeringConnectionId=vpc_peering_connection_id96        )97    def create_route_to_peering_connection(self, rtb_id, destination_cidr_block, vpc_peering_conn_id):98        print('Created Route To VPC Peering Connection to ' + destination_cidr_block)99        return self.client.create_route(100            RouteTableId=rtb_id,101            DestinationCidrBlock=destination_cidr_block,102            VpcPeeringConnectionId=vpc_peering_conn_id...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!!
