Add support for route table routes to target virtual private gateways.
This commit is contained in:
parent
3a82f089a2
commit
b513d69313
@ -1817,12 +1817,12 @@ class RouteTableBackend(object):
|
||||
|
||||
class Route(object):
|
||||
def __init__(self, route_table, destination_cidr_block, local=False,
|
||||
internet_gateway=None, instance=None, interface=None, vpc_pcx=None):
|
||||
gateway=None, instance=None, interface=None, vpc_pcx=None):
|
||||
self.id = generate_route_id(route_table.id, destination_cidr_block)
|
||||
self.route_table = route_table
|
||||
self.destination_cidr_block = destination_cidr_block
|
||||
self.local = local
|
||||
self.internet_gateway = internet_gateway
|
||||
self.gateway = gateway
|
||||
self.instance = instance
|
||||
self.interface = interface
|
||||
self.vpc_pcx = vpc_pcx
|
||||
@ -1861,8 +1861,15 @@ class RouteBackend(object):
|
||||
if interface_id:
|
||||
self.raise_not_implemented_error("CreateRoute to NetworkInterfaceId")
|
||||
|
||||
gateway = None
|
||||
if gateway_id:
|
||||
if EC2_RESOURCE_TO_PREFIX['vpn-gateway'] in gateway_id:
|
||||
gateway = self.get_vpn_gateway(gateway_id)
|
||||
elif EC2_RESOURCE_TO_PREFIX['internet-gateway'] in gateway_id:
|
||||
gateway = self.get_internet_gateway(gateway_id)
|
||||
|
||||
route = Route(route_table, destination_cidr_block, local=local,
|
||||
internet_gateway=self.get_internet_gateway(gateway_id) if gateway_id else None,
|
||||
gateway=gateway,
|
||||
instance=self.get_instance(instance_id) if instance_id else None,
|
||||
interface=None,
|
||||
vpc_pcx=self.get_vpc_peering_connection(vpc_peering_connection_id) if vpc_peering_connection_id else None)
|
||||
@ -1879,7 +1886,13 @@ class RouteBackend(object):
|
||||
if interface_id:
|
||||
self.raise_not_implemented_error("ReplaceRoute to NetworkInterfaceId")
|
||||
|
||||
route.internet_gateway = self.get_internet_gateway(gateway_id) if gateway_id else None
|
||||
route.gateway = None
|
||||
if gateway_id:
|
||||
if EC2_RESOURCE_TO_PREFIX['vpn-gateway'] in gateway_id:
|
||||
route.gateway = self.get_vpn_gateway(gateway_id)
|
||||
elif EC2_RESOURCE_TO_PREFIX['internet-gateway'] in gateway_id:
|
||||
route.gateway = self.get_internet_gateway(gateway_id)
|
||||
|
||||
route.instance = self.get_instance(instance_id) if instance_id else None
|
||||
route.interface = None
|
||||
route.vpc_pcx = self.get_vpc_peering_connection(vpc_peering_connection_id) if vpc_peering_connection_id else None
|
||||
|
@ -17,13 +17,13 @@ class RouteTables(BaseResponse):
|
||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
||||
destination_cidr_block = self.querystring.get('DestinationCidrBlock')[0]
|
||||
|
||||
internet_gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
||||
gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
||||
instance_id = optional_from_querystring('InstanceId', self.querystring)
|
||||
interface_id = optional_from_querystring('NetworkInterfaceId', self.querystring)
|
||||
pcx_id = optional_from_querystring('VpcPeeringConnectionId', self.querystring)
|
||||
|
||||
self.ec2_backend.create_route(route_table_id, destination_cidr_block,
|
||||
gateway_id=internet_gateway_id,
|
||||
gateway_id=gateway_id,
|
||||
instance_id=instance_id,
|
||||
interface_id=interface_id,
|
||||
vpc_peering_connection_id=pcx_id)
|
||||
@ -67,13 +67,13 @@ class RouteTables(BaseResponse):
|
||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
||||
destination_cidr_block = self.querystring.get('DestinationCidrBlock')[0]
|
||||
|
||||
internet_gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
||||
gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
||||
instance_id = optional_from_querystring('InstanceId', self.querystring)
|
||||
interface_id = optional_from_querystring('NetworkInterfaceId', self.querystring)
|
||||
pcx_id = optional_from_querystring('VpcPeeringConnectionId', self.querystring)
|
||||
|
||||
self.ec2_backend.replace_route(route_table_id, destination_cidr_block,
|
||||
gateway_id=internet_gateway_id,
|
||||
gateway_id=gateway_id,
|
||||
instance_id=instance_id,
|
||||
interface_id=interface_id,
|
||||
vpc_peering_connection_id=pcx_id)
|
||||
@ -152,8 +152,8 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """
|
||||
<origin>CreateRouteTable</origin>
|
||||
<state>active</state>
|
||||
{% endif %}
|
||||
{% if route.internet_gateway %}
|
||||
<gatewayId>{{ route.internet_gateway.id }}</gatewayId>
|
||||
{% if route.gateway %}
|
||||
<gatewayId>{{ route.gateway.id }}</gatewayId>
|
||||
<origin>CreateRoute</origin>
|
||||
<state>active</state>
|
||||
{% endif %}
|
||||
|
@ -419,6 +419,29 @@ def test_routes_vpc_peering_connection():
|
||||
new_route.destination_cidr_block.should.equal(ROUTE_CIDR)
|
||||
|
||||
|
||||
@requires_boto_gte("2.34.0")
|
||||
@mock_ec2
|
||||
def test_routes_vpn_gateway():
|
||||
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
main_route_table = conn.get_all_route_tables(filters={'association.main':'true','vpc-id':vpc.id})[0]
|
||||
ROUTE_CIDR = "10.0.0.4/24"
|
||||
|
||||
vpn_gw = conn.create_vpn_gateway(type="ipsec.1")
|
||||
|
||||
conn.create_route(main_route_table.id, ROUTE_CIDR, gateway_id=vpn_gw.id)
|
||||
|
||||
main_route_table = conn.get_all_route_tables(main_route_table.id)[0]
|
||||
new_routes = [route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
|
||||
new_routes.should.have.length_of(1)
|
||||
|
||||
new_route = new_routes[0]
|
||||
new_route.gateway_id.should.equal(vpn_gw.id)
|
||||
new_route.instance_id.should.be.none
|
||||
new_route.vpc_peering_connection_id.should.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_network_acl_tagging():
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user