Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vpc.subnets.all() is not a superset of vpc.subnets.filter(...) #148

Closed
kislyuk opened this issue Jun 24, 2015 · 4 comments
Closed

vpc.subnets.all() is not a superset of vpc.subnets.filter(...) #148

kislyuk opened this issue Jun 24, 2015 · 4 comments
Labels
bug This issue is a confirmed bug.

Comments

@kislyuk
Copy link
Contributor

kislyuk commented Jun 24, 2015

ec2 = boto3.resource("ec2")
for vpc in ec2.vpcs.all():
    for subnet in vpc.subnets.all():
        print(vpc, "all:", subnet)
    for az in ec2.meta.client.describe_availability_zones()["AvailabilityZones"]:
        for subnet in vpc.subnets.filter(Filters=[{"Name": "availabilityZone", "Values": [az["ZoneName"]]}]):
            print(vpc, "filter:", subnet)

It appears vpc.subnets.filter(...) admits subnets from other VPCs, while all() does not. This is confusing.

@kyleknap
Copy link
Contributor

That seems strange. I tried it and I can account for all of my subnets with the filter() and all() method. If some of the subnets are missing, it must have been omitted by the availability zone filter you used for the filter() method.

Could you identify the availability zone of the missing subnets?

@kyleknap kyleknap added the response-requested Waiting on additional information or feedback. label Jun 24, 2015
@kislyuk
Copy link
Contributor Author

kislyuk commented Jun 24, 2015

ec2 = boto3.resource("ec2")
for vpc in ec2.vpcs.all():
    for subnet in vpc.subnets.all():
        print(vpc, "all:", subnet)
    for az in ec2.meta.client.describe_availability_zones()["AvailabilityZones"]:
        for subnet in vpc.subnets.filter(Filters=[{"Name": "availabilityZone", "Values": [az["ZoneName"]]}]):
            print(vpc, az["ZoneName"], "filter:", subnet)
ec2.Vpc(id='vpc-71979a15') us-east-1c filter: ec2.Subnet(id='subnet-65b8557e')
ec2.Vpc(id='vpc-f0979a96') us-east-1c filter: ec2.Subnet(id='subnet-65b8557e')
ec2.Vpc(id='vpc-b86defde') all: ec2.Subnet(id='subnet-65b8557e')
ec2.Vpc(id='vpc-b86defde') us-east-1c filter: ec2.Subnet(id='subnet-65b8557e')
ec2.Vpc(id='vpc-fb979a9d') us-east-1c filter: ec2.Subnet(id='subnet-65b8557e')
ec2.Vpc(id='vpc-d9979abd') us-east-1c filter: ec2.Subnet(id='subnet-65b8557e')

(IDs changed)

What I see is a particular subnet showing up in the all() listing for all VPCs in a region, not just for the one that it really belongs to. I believe the other VPCs are empty.

@kyleknap
Copy link
Contributor

I can confirm the issue. What is happening is that the use of Filter in the filter() method clobbers another filter that was injected into the parameter for the VPC Id, thus you were just getting all of the subnets for the particular availability zone instead of the all of the subnets for a particular availability zone and VPC Id.

The PR that is referenced in the issue fixes the issue.

@kyleknap kyleknap added bug This issue is a confirmed bug. confirmed and removed response-requested Waiting on additional information or feedback. labels Jun 25, 2015
@kyleknap
Copy link
Contributor

This should be fixed now that both PR's are merged. Closing issue. Please reopen if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants