fixed rt, eip, natgateway integration (#4176)
This commit is contained in:
parent
d2c9e85ed3
commit
7397b8c129
@ -5297,7 +5297,7 @@ class SpotFleetBackend(object):
|
||||
|
||||
|
||||
class ElasticAddress(TaggedEC2Resource, CloudFormationModel):
|
||||
def __init__(self, ec2_backend, domain, address=None):
|
||||
def __init__(self, ec2_backend, domain, address=None, tags=None):
|
||||
self.ec2_backend = ec2_backend
|
||||
if address:
|
||||
self.public_ip = address
|
||||
@ -5309,6 +5309,7 @@ class ElasticAddress(TaggedEC2Resource, CloudFormationModel):
|
||||
self.instance = None
|
||||
self.eni = None
|
||||
self.association_id = None
|
||||
self.add_tags(tags or {})
|
||||
|
||||
@staticmethod
|
||||
def cloudformation_name_type():
|
||||
@ -5329,6 +5330,7 @@ class ElasticAddress(TaggedEC2Resource, CloudFormationModel):
|
||||
instance_id = None
|
||||
if properties:
|
||||
domain = properties.get("Domain")
|
||||
# TODO: support tags from cloudformation template
|
||||
eip = ec2_backend.allocate_address(domain=domain if domain else "standard")
|
||||
instance_id = properties.get("InstanceId")
|
||||
else:
|
||||
@ -5380,13 +5382,13 @@ class ElasticAddressBackend(object):
|
||||
self.addresses = []
|
||||
super(ElasticAddressBackend, self).__init__()
|
||||
|
||||
def allocate_address(self, domain, address=None):
|
||||
def allocate_address(self, domain, address=None, tags=None):
|
||||
if domain not in ["standard", "vpc"]:
|
||||
raise InvalidDomainError(domain)
|
||||
if address:
|
||||
address = ElasticAddress(self, domain=domain, address=address)
|
||||
address = ElasticAddress(self, domain=domain, address=address, tags=tags)
|
||||
else:
|
||||
address = ElasticAddress(self, domain=domain)
|
||||
address = ElasticAddress(self, domain=domain, tags=tags)
|
||||
self.addresses.append(address)
|
||||
return address
|
||||
|
||||
@ -6940,13 +6942,16 @@ class TransitGatewayRelationsBackend(object):
|
||||
|
||||
|
||||
class NatGateway(CloudFormationModel):
|
||||
def __init__(self, backend, subnet_id, allocation_id, tags=[]):
|
||||
def __init__(
|
||||
self, backend, subnet_id, allocation_id, tags=[], connectivity_type="public"
|
||||
):
|
||||
# public properties
|
||||
self.id = random_nat_gateway_id()
|
||||
self.subnet_id = subnet_id
|
||||
self.allocation_id = allocation_id
|
||||
self.state = "available"
|
||||
self.private_ip = random_private_ip()
|
||||
self.connectivity_type = connectivity_type
|
||||
|
||||
# protected properties
|
||||
self._created_at = datetime.utcnow()
|
||||
@ -7039,8 +7044,12 @@ class NatGatewayBackend(object):
|
||||
|
||||
return nat_gateways
|
||||
|
||||
def create_nat_gateway(self, subnet_id, allocation_id, tags=[]):
|
||||
nat_gateway = NatGateway(self, subnet_id, allocation_id, tags)
|
||||
def create_nat_gateway(
|
||||
self, subnet_id, allocation_id, tags=[], connectivity_type="public"
|
||||
):
|
||||
nat_gateway = NatGateway(
|
||||
self, subnet_id, allocation_id, tags, connectivity_type
|
||||
)
|
||||
self.nat_gateways[nat_gateway.id] = nat_gateway
|
||||
return nat_gateway
|
||||
|
||||
|
@ -1,19 +1,22 @@
|
||||
from __future__ import unicode_literals
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.ec2.utils import filters_from_querystring
|
||||
from moto.ec2.utils import filters_from_querystring, add_tag_specification
|
||||
|
||||
|
||||
class ElasticIPAddresses(BaseResponse):
|
||||
def allocate_address(self):
|
||||
domain = self._get_param("Domain", if_none="standard")
|
||||
reallocate_address = self._get_param("Address", if_none=None)
|
||||
tags = self._get_multi_param("TagSpecification")
|
||||
tags = add_tag_specification(tags)
|
||||
|
||||
if self.is_not_dryrun("AllocateAddress"):
|
||||
if reallocate_address:
|
||||
address = self.ec2_backend.allocate_address(
|
||||
domain, address=reallocate_address
|
||||
domain, address=reallocate_address, tags=tags
|
||||
)
|
||||
else:
|
||||
address = self.ec2_backend.allocate_address(domain)
|
||||
address = self.ec2_backend.allocate_address(domain, tags=tags)
|
||||
template = self.response_template(ALLOCATE_ADDRESS_RESPONSE)
|
||||
return template.render(address=address)
|
||||
|
||||
@ -152,14 +155,12 @@ DESCRIBE_ADDRESS_RESPONSE = """<DescribeAddressesResponse xmlns="http://ec2.amaz
|
||||
<associationId>{{ address.association_id }}</associationId>
|
||||
{% endif %}
|
||||
<tagSet>
|
||||
{% for tag in address.get_tags() %}
|
||||
{% for tag in address.get_tags() %}
|
||||
<item>
|
||||
<resourceId>{{ tag.resource_id }}</resourceId>
|
||||
<resourceType>{{ tag.resource_type }}</resourceType>
|
||||
<key>{{ tag.key }}</key>
|
||||
<value>{{ tag.value }}</value>
|
||||
<key>{{ tag.key }}</key>
|
||||
<value>{{ tag.value }}</value>
|
||||
</item>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tagSet>
|
||||
</item>
|
||||
{% endfor %}
|
||||
|
@ -7,11 +7,15 @@ class NatGateways(BaseResponse):
|
||||
def create_nat_gateway(self):
|
||||
subnet_id = self._get_param("SubnetId")
|
||||
allocation_id = self._get_param("AllocationId")
|
||||
connectivity_type = self._get_param("ConnectivityType")
|
||||
tags = self._get_multi_param("TagSpecification")
|
||||
if tags:
|
||||
tags = tags[0].get("Tag")
|
||||
nat_gateway = self.ec2_backend.create_nat_gateway(
|
||||
subnet_id=subnet_id, allocation_id=allocation_id, tags=tags
|
||||
subnet_id=subnet_id,
|
||||
allocation_id=allocation_id,
|
||||
tags=tags,
|
||||
connectivity_type=connectivity_type,
|
||||
)
|
||||
template = self.response_template(CREATE_NAT_GATEWAY)
|
||||
return template.render(nat_gateway=nat_gateway)
|
||||
@ -46,6 +50,7 @@ DESCRIBE_NAT_GATEWAYS_RESPONSE = """<DescribeNatGatewaysResponse xmlns="http://e
|
||||
<createTime>{{ nat_gateway.create_time }}</createTime>
|
||||
<vpcId>{{ nat_gateway.vpc_id }}</vpcId>
|
||||
<natGatewayId>{{ nat_gateway.id }}</natGatewayId>
|
||||
<connectivityType>{{ nat_gateway.connectivity_type }}</connectivityType>
|
||||
<state>{{ nat_gateway.state }}</state>
|
||||
{% if nat_gateway.tags %}
|
||||
<tagSet>
|
||||
@ -75,6 +80,7 @@ CREATE_NAT_GATEWAY = """<CreateNatGatewayResponse xmlns="http://ec2.amazonaws.co
|
||||
<createTime>{{ nat_gateway.create_time }}</createTime>
|
||||
<vpcId>{{ nat_gateway.vpc_id }}</vpcId>
|
||||
<natGatewayId>{{ nat_gateway.id }}</natGatewayId>
|
||||
<connectivityType>{{ nat_gateway.connectivity_type }}</connectivityType>
|
||||
<state>{{ nat_gateway.state }}</state>
|
||||
</natGateway>
|
||||
</CreateNatGatewayResponse>
|
||||
|
@ -81,6 +81,7 @@ TestAccAWSRouteTable_tags
|
||||
TestAccAWSRouteTable_vgwRoutePropagation
|
||||
TestAccAWSRouteTable_RequireRouteTarget
|
||||
TestAccAWSRouteTable_disappears_SubnetAssociation
|
||||
TestAccAWSRouteTable_IPv4_To_NatGateway
|
||||
TestAccAWSRouteTable_disappears
|
||||
TestAccAWSRouteTable_basic
|
||||
TestAccAwsEc2ManagedPrefixList
|
Loading…
Reference in New Issue
Block a user