How to use create_transit_gateway_route method in localstack

Best Python code snippet using localstack_python

transit-gateway.py

Source:transit-gateway.py Github

copy

Full Screen

...42 DryRun=False43 )44 return response45#Create transit gateway route46def create_transit_gateway_route(transit_gateway_rt_id, destination_ip_block, transit_gateway_attachment_id):47 client = boto3.client('ec2', region_name='us-east-1')48 response = client.create_transit_gateway_route(49 DestinationCidrBlock=destination_ip_block,50 TransitGatewayRouteTableId=transit_gateway_rt_id,51 TransitGatewayAttachmentId=transit_gateway_attachment_id,52 Blackhole=False,53 DryRun=False54 )55 return response56#Create transit gateway multi-cast domain57def create_transit_gateway_multicast_domain(transit_gateway_id):58 client = boto3.client('ec2', region_name='us-east-1')59 response = client.create_transit_gateway_multicast_domain(60 TransitGatewayId=transit_gateway_id,61 DryRun=False62 )63 return response64#Associate transit gateway multi cast domain65def associate_transit_gateway_multicast_domain(tgw_multicast_domain_id, tgw_attachment_id, subnetID):66 client = boto3.client('ec2', region_name='us-east-1')67 response = client.associate_transit_gateway_multicast_domain(68 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,69 TransitGatewayAttachmentId=tgw_attachment_id,70 SubnetIds=[71 subnetID,72 ],73 DryRun=False74 )75 return response76#Delete transit gateway multi-cast domain77def delete_transit_gateway_multicast_domain(tgwy_multicast_domain_id):78 client = boto3.client('ec2', region_name='us-east-1')79 response = client.delete_transit_gateway_multicast_domain(80 TransitGatewayMulticastDomainId=tgwy_multicast_domain_id,81 DryRun=False82 )83 return response84#Delete transit gateway vpc attachment85def delete_transit_gateway_vpc_attachment(transit_gateway_attachment_id):86 client = boto3.client('ec2', region_name='us-east-1')87 response = client.delete_transit_gateway_vpc_attachment(88 TransitGatewayAttachmentId=transit_gateway_attachment_id,89 DryRun=False90 )91 return response92#Delete transit gateway93def delete_transit_gateway(transit_gateway_id):94 client = boto3.client('ec2', region_name='us-east-1')95 response = client.delete_transit_gateway(96 TransitGatewayId=transit_gateway_id,97 DryRun=False98 )99# dissacotiate transit gateway multicast domain100def disassociate_transit_gateway_multicast_domain(tgw_multicast_domain_id, tgw_attachment_id, subnet_id):101 client = boto3.client('ec2', region_name='us-east-1')102 response = client.disassociate_transit_gateway_multicast_domain(103 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,104 TransitGatewayAttachmentId=tgw_attachment_id,105 SubnetIds=[106 subnet_id,107 ],108 DryRun=False109 )110#register transit gateway multi-cast members111def register_transit_gateway_multicast_group_members(tgw_multicast_domain_id, group_address, network_interface2, network_interface3, network_interface4):112 client = boto3.client('ec2', region_name='us-east-1')113 response = client.register_transit_gateway_multicast_group_members(114 TransitGatewayMulticastDomainId = tgw_multicast_domain_id,115 GroupIpAddress = group_address,116 NetworkInterfaceIds = [117 network_interface2, network_interface3, network_interface4118 ],119 DryRun = False120 )121 return response122def register_transit_gateway_multicast_group_sources(tgw_multicast_domain_id, nic1id):123 client = boto3.client('ec2', region_name='us-east-1')124 response = client.register_transit_gateway_multicast_group_sources(125 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,126 GroupIpAddress='224.0.0.0',127 NetworkInterfaceIds=[128 nic1id,129 ],130 DryRun=False131 )132 return response133if __name__ == '__main__':134 action = sys.argv[1]135 if action == "apply":136 #Get variables from cmd line137 vpc_id = sys.argv[2]138 subnet_id = sys.argv[3]139 i1nic = sys.argv[4]140 i2nic = sys.argv[5]141 i3nic = sys.argv[6]142 i4nic = sys.argv[7]143 #Create transit gateway144 tgw_response = create_transit_gateway()145 #Collect transit gateway id from response146 tgw_id = tgw_response['TransitGateway']['TransitGatewayId']147 time.sleep(180)148 #Create transit gateway attachment149 tgw_attachment_response = create_transit_gateway_vpc_attachment(tgw_id, vpc_id, subnet_id)150 #get tgw attachment id response151 tgw_attachment_id = tgw_attachment_response['TransitGatewayVpcAttachment']['TransitGatewayAttachmentId']152 time.sleep(60)153 #Create transit gateway route table and get response154 tgw_rt_response = create_transit_gateway_rt(tgw_id)155 #Get transit gateway route table id from the response156 tgw_rt_id = tgw_rt_response ['TransitGatewayRouteTable']['TransitGatewayRouteTableId']157 time.sleep(90)158 #Create transit gateway route159 create_transit_gateway_route(tgw_rt_id, "10.123.111.0/24", tgw_attachment_id)160 #Create transit gateway multi cast domain161 tgw_multicast_domain_response = create_transit_gateway_multicast_domain(tgw_id)162 #Get transit gateway multi cast domain id163 tgw_multicast_domain_id = tgw_multicast_domain_response['TransitGatewayMulticastDomain']['TransitGatewayMulticastDomainId']164 time.sleep(90)165 #Associate transit gateway multi-cast domain166 associate_transit_gateway_multicast_domain(tgw_multicast_domain_id, tgw_attachment_id, subnet_id)167 time.sleep(30)168 #register transit gateway multicast group members169 register_transit_gateway_multicast_group_members(tgw_multicast_domain_id, "224.0.0.0", i2nic, i3nic, i4nic)170 time.sleep(30)171 #register transit gateway multicast group sources172 register_transit_gateway_multicast_group_sources(tgw_multicast_domain_id,i1nic)173 if action == "destroy":...

Full Screen

Full Screen

create-tgw-routes.py

Source:create-tgw-routes.py Github

copy

Full Screen

...17 ]18)19tgw_rt_id_us_east_1=(query['TransitGatewayAttachments'][0]['Association']['TransitGatewayRouteTableId'])20tgw_attachment_id=(query['TransitGatewayAttachments'][0]['TransitGatewayAttachmentId'])21response = client.create_transit_gateway_route(22 DestinationCidrBlock='172.16.1.0/24',23 TransitGatewayRouteTableId=(tgw_rt_id_us_east_1),24 TransitGatewayAttachmentId=(tgw_attachment_id)25)26client = boto3.client('ec2', region_name='eu-west-1')27query = client.describe_transit_gateway_attachments(28 Filters=[29 {30 'Name': 'resource-type',31 'Values': [32 'peering',33 ]34 },35 {36 'Name': 'state',37 'Values': [38 'available',39 ]40 }41 ]42)43tgw_rt_id_eu_west_1=(query['TransitGatewayAttachments'][0]['Association']['TransitGatewayRouteTableId'])44tgw_attachment_id=(query['TransitGatewayAttachments'][0]['TransitGatewayAttachmentId'])45response = client.create_transit_gateway_route(46 DestinationCidrBlock='172.16.0.0/24',47 TransitGatewayRouteTableId=(tgw_rt_id_eu_west_1),48 TransitGatewayAttachmentId=(tgw_attachment_id)...

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