Merge pull request #2613 from levinine/add_nat_gateway_id_to_route_and_describe_route_tables
Add nat_gateway_id to route and describe_route_tables
This commit is contained in:
commit
4386999ea7
@ -3306,6 +3306,7 @@ class Route(object):
|
|||||||
local=False,
|
local=False,
|
||||||
gateway=None,
|
gateway=None,
|
||||||
instance=None,
|
instance=None,
|
||||||
|
nat_gateway=None,
|
||||||
interface=None,
|
interface=None,
|
||||||
vpc_pcx=None,
|
vpc_pcx=None,
|
||||||
):
|
):
|
||||||
@ -3315,6 +3316,7 @@ class Route(object):
|
|||||||
self.local = local
|
self.local = local
|
||||||
self.gateway = gateway
|
self.gateway = gateway
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
|
self.nat_gateway = nat_gateway
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.vpc_pcx = vpc_pcx
|
self.vpc_pcx = vpc_pcx
|
||||||
|
|
||||||
@ -3327,6 +3329,7 @@ class Route(object):
|
|||||||
gateway_id = properties.get("GatewayId")
|
gateway_id = properties.get("GatewayId")
|
||||||
instance_id = properties.get("InstanceId")
|
instance_id = properties.get("InstanceId")
|
||||||
interface_id = properties.get("NetworkInterfaceId")
|
interface_id = properties.get("NetworkInterfaceId")
|
||||||
|
nat_gateway_id = properties.get("NatGatewayId")
|
||||||
pcx_id = properties.get("VpcPeeringConnectionId")
|
pcx_id = properties.get("VpcPeeringConnectionId")
|
||||||
|
|
||||||
route_table_id = properties["RouteTableId"]
|
route_table_id = properties["RouteTableId"]
|
||||||
@ -3336,6 +3339,7 @@ class Route(object):
|
|||||||
destination_cidr_block=properties.get("DestinationCidrBlock"),
|
destination_cidr_block=properties.get("DestinationCidrBlock"),
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
instance_id=instance_id,
|
instance_id=instance_id,
|
||||||
|
nat_gateway_id=nat_gateway_id,
|
||||||
interface_id=interface_id,
|
interface_id=interface_id,
|
||||||
vpc_peering_connection_id=pcx_id,
|
vpc_peering_connection_id=pcx_id,
|
||||||
)
|
)
|
||||||
@ -3353,6 +3357,7 @@ class RouteBackend(object):
|
|||||||
local=False,
|
local=False,
|
||||||
gateway_id=None,
|
gateway_id=None,
|
||||||
instance_id=None,
|
instance_id=None,
|
||||||
|
nat_gateway_id=None,
|
||||||
interface_id=None,
|
interface_id=None,
|
||||||
vpc_peering_connection_id=None,
|
vpc_peering_connection_id=None,
|
||||||
):
|
):
|
||||||
@ -3373,12 +3378,17 @@ class RouteBackend(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise InvalidDestinationCIDRBlockParameterError(destination_cidr_block)
|
raise InvalidDestinationCIDRBlockParameterError(destination_cidr_block)
|
||||||
|
|
||||||
|
nat_gateway = None
|
||||||
|
if nat_gateway_id is not None:
|
||||||
|
nat_gateway = self.nat_gateways.get(nat_gateway_id)
|
||||||
|
|
||||||
route = Route(
|
route = Route(
|
||||||
route_table,
|
route_table,
|
||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
local=local,
|
local=local,
|
||||||
gateway=gateway,
|
gateway=gateway,
|
||||||
instance=self.get_instance(instance_id) if instance_id else None,
|
instance=self.get_instance(instance_id) if instance_id else None,
|
||||||
|
nat_gateway=nat_gateway,
|
||||||
interface=None,
|
interface=None,
|
||||||
vpc_pcx=self.get_vpc_peering_connection(vpc_peering_connection_id)
|
vpc_pcx=self.get_vpc_peering_connection(vpc_peering_connection_id)
|
||||||
if vpc_peering_connection_id
|
if vpc_peering_connection_id
|
||||||
|
@ -18,6 +18,7 @@ class RouteTables(BaseResponse):
|
|||||||
destination_cidr_block = self._get_param("DestinationCidrBlock")
|
destination_cidr_block = self._get_param("DestinationCidrBlock")
|
||||||
gateway_id = self._get_param("GatewayId")
|
gateway_id = self._get_param("GatewayId")
|
||||||
instance_id = self._get_param("InstanceId")
|
instance_id = self._get_param("InstanceId")
|
||||||
|
nat_gateway_id = self._get_param("NatGatewayId")
|
||||||
interface_id = self._get_param("NetworkInterfaceId")
|
interface_id = self._get_param("NetworkInterfaceId")
|
||||||
pcx_id = self._get_param("VpcPeeringConnectionId")
|
pcx_id = self._get_param("VpcPeeringConnectionId")
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ class RouteTables(BaseResponse):
|
|||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
instance_id=instance_id,
|
instance_id=instance_id,
|
||||||
|
nat_gateway_id=nat_gateway_id,
|
||||||
interface_id=interface_id,
|
interface_id=interface_id,
|
||||||
vpc_peering_connection_id=pcx_id,
|
vpc_peering_connection_id=pcx_id,
|
||||||
)
|
)
|
||||||
@ -173,6 +175,10 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """
|
|||||||
<origin>CreateRoute</origin>
|
<origin>CreateRoute</origin>
|
||||||
<state>blackhole</state>
|
<state>blackhole</state>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if route.nat_gateway %}
|
||||||
|
<natGatewayId>{{ route.nat_gateway.id }}</natGatewayId>
|
||||||
|
<state>active</state>
|
||||||
|
{% endif %}
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</routeSet>
|
</routeSet>
|
||||||
|
@ -581,3 +581,40 @@ def test_create_route_with_invalid_destination_cidr_block_parameter():
|
|||||||
destination_cidr_block
|
destination_cidr_block
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_describe_route_tables_with_nat_gateway():
|
||||||
|
ec2 = boto3.client("ec2", region_name="us-west-1")
|
||||||
|
vpc_id = ec2.create_vpc(CidrBlock="192.168.0.0/23")["Vpc"]["VpcId"]
|
||||||
|
igw_id = ec2.create_internet_gateway()["InternetGateway"]["InternetGatewayId"]
|
||||||
|
ec2.attach_internet_gateway(VpcId=vpc_id, InternetGatewayId=igw_id)
|
||||||
|
az = ec2.describe_availability_zones()["AvailabilityZones"][0]["ZoneName"]
|
||||||
|
sn_id = ec2.create_subnet(
|
||||||
|
AvailabilityZone=az, CidrBlock="192.168.0.0/24", VpcId=vpc_id
|
||||||
|
)["Subnet"]["SubnetId"]
|
||||||
|
route_table_id = ec2.create_route_table(VpcId=vpc_id)["RouteTable"]["RouteTableId"]
|
||||||
|
ec2.associate_route_table(SubnetId=sn_id, RouteTableId=route_table_id)
|
||||||
|
alloc_id = ec2.allocate_address(Domain="vpc")["AllocationId"]
|
||||||
|
nat_gw_id = ec2.create_nat_gateway(SubnetId=sn_id, AllocationId=alloc_id)[
|
||||||
|
"NatGateway"
|
||||||
|
]["NatGatewayId"]
|
||||||
|
ec2.create_route(
|
||||||
|
DestinationCidrBlock="0.0.0.0/0",
|
||||||
|
NatGatewayId=nat_gw_id,
|
||||||
|
RouteTableId=route_table_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
route_table = ec2.describe_route_tables(
|
||||||
|
Filters=[{"Name": "route-table-id", "Values": [route_table_id]}]
|
||||||
|
)["RouteTables"][0]
|
||||||
|
nat_gw_routes = [
|
||||||
|
route
|
||||||
|
for route in route_table["Routes"]
|
||||||
|
if route["DestinationCidrBlock"] == "0.0.0.0/0"
|
||||||
|
]
|
||||||
|
|
||||||
|
nat_gw_routes.should.have.length_of(1)
|
||||||
|
nat_gw_routes[0]["DestinationCidrBlock"].should.equal("0.0.0.0/0")
|
||||||
|
nat_gw_routes[0]["NatGatewayId"].should.equal(nat_gw_id)
|
||||||
|
nat_gw_routes[0]["State"].should.equal("active")
|
||||||
|
Loading…
Reference in New Issue
Block a user