vavavr00m / boto

Automatically exported from code.google.com/p/boto
1 stars 0 forks source link

get_all_vpcs filter not working properly #548

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run:
#!/usr/bin/python
import boto
from boto.vpc import VPCConnection

current_ec2_regions = boto.ec2.regions()
region_obj=current_ec2_regions[1]
c=VPCConnection(region=region_obj)
filterz = [('state','available')]
vpc_status=c.get_all_vpcs(None,filterz)
print vpc_status

* What is the expected output?
 The list of available VPCs:
[VPC:vpc-11223344, VPC:vpc-55667788]

* What do you see instead?

Traceback (most recent call last):
  File "./vpc.py", line 11, in <module>
    vpc_status=c.get_all_vpcs(None,filterz)
  File "/usr/local/lib/python2.7/dist-packages/boto/vpc/__init__.py", line 69, in get_all_vpcs
    return self.get_list('DescribeVpcs', params, [('item', VPC)])
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 680, in get_list
    raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>UnknownParameter</Code><Message>The parameter 
Key is not 
recognized</Message></Error></Errors><RequestID>4d76794b-b65a-468e-8ad6-3de4f982
9215</RequestID></Response>

According to 
http://docs.amazonwebservices.com/AWSEC2/2011-01-01/APIReference/index.html?ApiR
eference-query-DescribeVpcs.html boto should be submitting something like:
[...]
&Filter.1.Name=dhcp-options-id
&Filter.1.Value.1=dopt-7a8b9c2d

Instead it is sending:
[...]
&Filter.1.Key=dhcp-options-id   << Should be Filter.1.Name
&Filter.%d.Value.1=dopt-7a8b9c2d << Should be Filter.1.Value.1

Also, AWS supports multiple values which it seems currently boto won't do for 
now.

The following patch fixes the problem:
diff --git a/boto/vpc/__init__.py b/boto/vpc/__init__.py
index 76eea82..3527bfa 100644
--- a/boto/vpc/__init__.py
+++ b/boto/vpc/__init__.py
@@ -63,8 +63,8 @@ class VPCConnection(EC2Connection):
         if filters:
             i = 1
             for filter in filters:
-                params[('Filter.%d.Key' % i)] = filter[0]
-                params[('Filter.%d.Value.1')] = filter[1]
+                params[('Filter.%d.Name' % i)] = filter[0]
+                params[('Filter.%d.Value.1' % i)] = filter[1]
                 i += 1
         return self.get_list('DescribeVpcs', params, [('item', VPC)])

Original issue reported on code.google.com by joao%squ...@gtempaccount.com on 17 Aug 2011 at 11:47

GoogleCodeExporter commented 9 years ago
Forgot to mention this is with boto 2.0.

Original comment by joao%squ...@gtempaccount.com on 17 Aug 2011 at 11:48

GoogleCodeExporter commented 9 years ago
See https://github.com/boto/boto/issues/310

Original comment by joao%squ...@gtempaccount.com on 26 Aug 2011 at 7:26

GoogleCodeExporter commented 9 years ago
This issue has been fixed.  See github issue 310 for details.

Original comment by Mitch.Ga...@gmail.com on 21 Sep 2011 at 2:09