EC2: fixed filtering in describe az (#5307)
This commit is contained in:
parent
bc3ddcff5b
commit
5cdd5bf9d2
@ -1,4 +1,5 @@
|
||||
from boto3 import Session
|
||||
from moto.utilities.utils import filter_resources
|
||||
|
||||
|
||||
class Region(object):
|
||||
@ -9,10 +10,11 @@ class Region(object):
|
||||
|
||||
|
||||
class Zone(object):
|
||||
def __init__(self, name, region_name, zone_id):
|
||||
def __init__(self, name, region_name, zone_id, zone_type="availability-zone"):
|
||||
self.name = name
|
||||
self.region_name = region_name
|
||||
self.zone_id = zone_id
|
||||
self.zone_type = zone_type
|
||||
|
||||
|
||||
class RegionsAndZonesBackend:
|
||||
@ -304,9 +306,19 @@ class RegionsAndZonesBackend:
|
||||
ret.append(region)
|
||||
return ret
|
||||
|
||||
def describe_availability_zones(self):
|
||||
def describe_availability_zones(self, filters=None):
|
||||
# We might not have any zones for the current region, if it was introduced recently
|
||||
return self.zones.get(self.region_name, [])
|
||||
zones = self.zones.get(self.region_name, [])
|
||||
attr_pairs = (
|
||||
("zone-id", "zone_id"),
|
||||
("zone-type", "zone_type"),
|
||||
("zone-name", "name"),
|
||||
("region-name", "region_name"),
|
||||
)
|
||||
result = zones
|
||||
if filters:
|
||||
result = filter_resources(zones, filters, attr_pairs)
|
||||
return result
|
||||
|
||||
def get_zone_by_name(self, name):
|
||||
for zone in self.describe_availability_zones():
|
||||
|
@ -139,6 +139,7 @@ class VPC(TaggedEC2Resource, CloudFormationModel):
|
||||
is_default,
|
||||
instance_tenancy="default",
|
||||
amazon_provided_ipv6_cidr_block=False,
|
||||
ipv6_cidr_block_network_border_group=None,
|
||||
):
|
||||
|
||||
self.ec2_backend = ec2_backend
|
||||
@ -161,6 +162,7 @@ class VPC(TaggedEC2Resource, CloudFormationModel):
|
||||
self.associate_vpc_cidr_block(
|
||||
cidr_block,
|
||||
amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_block,
|
||||
ipv6_cidr_block_network_border_group=ipv6_cidr_block_network_border_group,
|
||||
)
|
||||
|
||||
@property
|
||||
@ -246,7 +248,10 @@ class VPC(TaggedEC2Resource, CloudFormationModel):
|
||||
return True
|
||||
|
||||
def associate_vpc_cidr_block(
|
||||
self, cidr_block, amazon_provided_ipv6_cidr_block=False
|
||||
self,
|
||||
cidr_block,
|
||||
amazon_provided_ipv6_cidr_block=False,
|
||||
ipv6_cidr_block_network_border_group=None,
|
||||
):
|
||||
max_associations = 5 if not amazon_provided_ipv6_cidr_block else 1
|
||||
|
||||
@ -274,6 +279,11 @@ class VPC(TaggedEC2Resource, CloudFormationModel):
|
||||
association_set["cidr_block"] = (
|
||||
random_ipv6_cidr() if amazon_provided_ipv6_cidr_block else cidr_block
|
||||
)
|
||||
if amazon_provided_ipv6_cidr_block:
|
||||
association_set["ipv6_pool"] = "Amazon"
|
||||
association_set[
|
||||
"ipv6_cidr_block_network_border_group"
|
||||
] = ipv6_cidr_block_network_border_group
|
||||
self.cidr_block_association_set[association_id] = association_set
|
||||
return association_set
|
||||
|
||||
@ -345,6 +355,7 @@ class VPCBackend:
|
||||
cidr_block,
|
||||
instance_tenancy="default",
|
||||
amazon_provided_ipv6_cidr_block=False,
|
||||
ipv6_cidr_block_network_border_group=None,
|
||||
tags=None,
|
||||
is_default=False,
|
||||
):
|
||||
@ -362,6 +373,7 @@ class VPCBackend:
|
||||
is_default=is_default,
|
||||
instance_tenancy=instance_tenancy,
|
||||
amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_block,
|
||||
ipv6_cidr_block_network_border_group=ipv6_cidr_block_network_border_group,
|
||||
)
|
||||
|
||||
for tag in tags or []:
|
||||
|
@ -4,7 +4,8 @@ from moto.core.responses import BaseResponse
|
||||
class AvailabilityZonesAndRegions(BaseResponse):
|
||||
def describe_availability_zones(self):
|
||||
self.error_on_dryrun()
|
||||
zones = self.ec2_backend.describe_availability_zones()
|
||||
filters = self._filters_from_querystring()
|
||||
zones = self.ec2_backend.describe_availability_zones(filters)
|
||||
template = self.response_template(DESCRIBE_ZONES_RESPONSE)
|
||||
return template.render(zones=zones)
|
||||
|
||||
@ -38,6 +39,7 @@ DESCRIBE_ZONES_RESPONSE = """<DescribeAvailabilityZonesResponse xmlns="http://ec
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>{{ zone.region_name }}</regionName>
|
||||
<zoneId>{{ zone.zone_id }}</zoneId>
|
||||
<zoneType>{{ zone.zone_type }}</zoneType>
|
||||
<messageSet/>
|
||||
</item>
|
||||
{% endfor %}
|
||||
|
@ -25,13 +25,19 @@ class VPCs(EC2BaseResponse):
|
||||
amazon_provided_ipv6_cidr_block = self._get_param(
|
||||
"AmazonProvidedIpv6CidrBlock"
|
||||
) in ["true", "True"]
|
||||
ipv6_cidr_block_network_border_group = self._get_param(
|
||||
"Ipv6CidrBlockNetworkBorderGroup"
|
||||
)
|
||||
# if network group is not specified, use the region of the VPC
|
||||
if not ipv6_cidr_block_network_border_group:
|
||||
ipv6_cidr_block_network_border_group = self.region
|
||||
if tags:
|
||||
tags = tags[0].get("Tag")
|
||||
|
||||
vpc = self.ec2_backend.create_vpc(
|
||||
cidr_block,
|
||||
instance_tenancy,
|
||||
amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_block,
|
||||
ipv6_cidr_block_network_border_group=ipv6_cidr_block_network_border_group,
|
||||
tags=tags,
|
||||
)
|
||||
doc_date = self._get_doc_date()
|
||||
@ -55,7 +61,7 @@ class VPCs(EC2BaseResponse):
|
||||
else "2016-11-15"
|
||||
)
|
||||
template = self.response_template(DESCRIBE_VPCS_RESPONSE)
|
||||
return template.render(vpcs=vpcs, doc_date=doc_date)
|
||||
return template.render(vpcs=vpcs, doc_date=doc_date, region=self.region)
|
||||
|
||||
def modify_vpc_tenancy(self):
|
||||
vpc_id = self._get_param("VpcId")
|
||||
@ -452,6 +458,8 @@ DESCRIBE_VPCS_RESPONSE = """
|
||||
<ipv6CidrBlockState>
|
||||
<state>{{assoc.cidr_block_state.state}}</state>
|
||||
</ipv6CidrBlockState>
|
||||
<networkBorderGroup>{{ assoc.ipv6_cidr_block_network_border_group }}</networkBorderGroup>
|
||||
<ipv6Pool>{{ assoc.ipv6_pool }}</ipv6Pool>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</ipv6CidrBlockAssociationSet>
|
||||
|
@ -281,7 +281,7 @@ index d42232fc09..8f7f983957 100644
|
||||
)
|
||||
|
||||
-const EventualConsistencyTimeout = 5 * time.Minute
|
||||
+const EventualConsistencyTimeout = 1 * time.Minute
|
||||
+const EventualConsistencyTimeout = 5 * time.Second
|
||||
|
||||
// CreateTags creates {{ .ServicePackage }} service tags for new resources.
|
||||
// The identifier is typically the Amazon Resource Name (ARN), although
|
||||
@ -1021,8 +1021,8 @@ index 5ad62e86c0..68209e7fb8 100644
|
||||
const (
|
||||
- vpcIPv6CIDRBlockAssociationCreatedTimeout = 10 * time.Minute
|
||||
- vpcIPv6CIDRBlockAssociationDeletedTimeout = 5 * time.Minute
|
||||
+ vpcIPv6CIDRBlockAssociationCreatedTimeout = 10 * time.Second
|
||||
+ vpcIPv6CIDRBlockAssociationDeletedTimeout = 5 * time.Second
|
||||
+ vpcIPv6CIDRBlockAssociationCreatedTimeout = 15 * time.Second
|
||||
+ vpcIPv6CIDRBlockAssociationDeletedTimeout = 15 * time.Second
|
||||
)
|
||||
|
||||
func WaitVPCIPv6CIDRBlockAssociationCreated(conn *ec2.EC2, id string, timeout time.Duration) (*ec2.VpcCidrBlockState, error) {
|
||||
|
@ -56,6 +56,7 @@ ec2:
|
||||
- TestAccEC2VPCsDataSource
|
||||
- TestAccEC2VPNGateway_
|
||||
- TestAccEC2VPNGatewayAttachment_
|
||||
- TestAccVPC_
|
||||
ecr:
|
||||
- TestAccECRLifecyclePolicy
|
||||
- TestAccECRRegistryPolicy
|
||||
|
Loading…
x
Reference in New Issue
Block a user