Skip to content

Commit

Permalink
Merge pull request #875 from jvgutierrez/eni-az-filter
Browse files Browse the repository at this point in the history
Implement availability-zone filter for DescribeNetworkInterfaces
  • Loading branch information
spulec committed Apr 13, 2017
2 parents bba197e + 6e209bb commit be7dc36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions moto/ec2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def get_filter_value(self, filter_name):
return self.subnet.vpc_id
elif filter_name == 'group-id':
return [group.id for group in self._group_set]
elif filter_name == 'availability-zone':
return self.subnet.availability_zone

filter_value = super(
NetworkInterface, self).get_filter_value(filter_name)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_ec2/test_elastic_network_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,37 @@ def test_elastic_network_interfaces_get_by_tag_name():
enis.should.have.length_of(0)


@mock_ec2
def test_elastic_network_interfaces_get_by_availability_zone():
ec2 = boto3.resource('ec2', region_name='us-west-2')
ec2_client = boto3.client('ec2', region_name='us-west-2')

vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet1 = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')

subnet2 = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.1.0/24', AvailabilityZone='us-west-2b')

eni1 = ec2.create_network_interface(
SubnetId=subnet1.id, PrivateIpAddress='10.0.0.15')

eni2 = ec2.create_network_interface(
SubnetId=subnet2.id, PrivateIpAddress='10.0.1.15')

# The status of the new interface should be 'available'
waiter = ec2_client.get_waiter('network_interface_available')
waiter.wait(NetworkInterfaceIds=[eni1.id, eni2.id])

filters = [{'Name': 'availability-zone', 'Values': ['us-west-2a']}]
enis = list(ec2.network_interfaces.filter(Filters=filters))
enis.should.have.length_of(1)

filters = [{'Name': 'availability-zone', 'Values': ['us-west-2c']}]
enis = list(ec2.network_interfaces.filter(Filters=filters))
enis.should.have.length_of(0)


@mock_ec2
def test_elastic_network_interfaces_get_by_private_ip():
ec2 = boto3.resource('ec2', region_name='us-west-2')
Expand Down

0 comments on commit be7dc36

Please sign in to comment.