Merge pull request #170 from DreadPirateShawn/DescribeSubnetsFiltering
DescribeSubnets: Added support for 'filters' parameter.
This commit is contained in:
commit
1846f28b41
3 changed files with 68 additions and 3 deletions
|
|
@ -46,3 +46,47 @@ def test_subnet_tagging():
|
|||
subnet = conn.get_all_subnets()[0]
|
||||
subnet.tags.should.have.length_of(1)
|
||||
subnet.tags["a key"].should.equal("some value")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_get_subnets_filtering():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
vpcA = conn.create_vpc("10.0.0.0/16")
|
||||
subnetA = conn.create_subnet(vpcA.id, "10.0.0.0/24")
|
||||
vpcB = conn.create_vpc("10.0.0.0/16")
|
||||
subnetB1 = conn.create_subnet(vpcB.id, "10.0.0.0/24")
|
||||
subnetB2 = conn.create_subnet(vpcB.id, "10.0.1.0/24")
|
||||
|
||||
all_subnets = conn.get_all_subnets()
|
||||
all_subnets.should.have.length_of(3)
|
||||
|
||||
# Filter by VPC ID
|
||||
subnets_by_vpc = conn.get_all_subnets(filters={'vpc-id': vpcB.id})
|
||||
subnets_by_vpc.should.have.length_of(2)
|
||||
set([subnet.id for subnet in subnets_by_vpc]).should.equal(set([subnetB1.id,subnetB2.id]))
|
||||
|
||||
# Filter by CIDR variations
|
||||
subnets_by_cidr1 = conn.get_all_subnets(filters={'cidr': "10.0.0.0/24"})
|
||||
subnets_by_cidr1.should.have.length_of(2)
|
||||
set([subnet.id for subnet in subnets_by_cidr1]).should.equal(set([subnetA.id,subnetB1.id]))
|
||||
|
||||
subnets_by_cidr2 = conn.get_all_subnets(filters={'cidr-block': "10.0.0.0/24"})
|
||||
subnets_by_cidr2.should.have.length_of(2)
|
||||
set([subnet.id for subnet in subnets_by_cidr2]).should.equal(set([subnetA.id,subnetB1.id]))
|
||||
|
||||
subnets_by_cidr3 = conn.get_all_subnets(filters={'cidrBlock': "10.0.0.0/24"})
|
||||
subnets_by_cidr3.should.have.length_of(2)
|
||||
set([subnet.id for subnet in subnets_by_cidr3]).should.equal(set([subnetA.id,subnetB1.id]))
|
||||
|
||||
# Filter by VPC ID and CIDR
|
||||
subnets_by_vpc_and_cidr = conn.get_all_subnets(filters={'vpc-id': vpcB.id, 'cidr': "10.0.0.0/24"})
|
||||
subnets_by_vpc_and_cidr.should.have.length_of(1)
|
||||
set([subnet.id for subnet in subnets_by_vpc_and_cidr]).should.equal(set([subnetB1.id]))
|
||||
|
||||
# Filter by subnet ID
|
||||
subnets_by_id = conn.get_all_subnets(filters={'subnet-id': subnetA.id})
|
||||
subnets_by_id.should.have.length_of(1)
|
||||
set([subnet.id for subnet in subnets_by_id]).should.equal(set([subnetA.id]))
|
||||
|
||||
# Unsupported filter
|
||||
conn.get_all_subnets.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue