Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 356da91

Browse files
committed
Merge pull request #2399 from felixonmars/vpc-py3
vpc module: add backward-compatible support for Python 3.3+. Fixes #2399.
2 parents 78300f1 + 23d0700 commit 356da91

15 files changed

+103
-96
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ At the moment, boto supports:
7676
* Networking
7777

7878
* Amazon Route53 (Python 3)
79-
* Amazon Virtual Private Cloud (VPC)
79+
* Amazon Virtual Private Cloud (VPC) (Python 3)
8080
* Elastic Load Balancing (ELB) (Python 3)
8181
* AWS Direct Connect (Python 3)
8282

boto/ec2/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def get_params(self):
122122
return params
123123

124124
def build_filter_params(self, params, filters):
125+
if not isinstance(filters, dict):
126+
filters = dict(filters)
127+
125128
i = 1
126129
for name in filters:
127130
aws_name = name

boto/vpc/__init__.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def get_all_vpcs(self, vpc_ids=None, filters=None, dry_run=False):
8585
:type vpc_ids: list
8686
:param vpc_ids: A list of strings with the desired VPC ID's
8787
88-
:type filters: list of tuples
89-
:param filters: A list of tuples containing filters. Each tuple
90-
consists of a filter key and a filter value.
88+
:type filters: list of tuples or dict
89+
:param filters: A list of tuples or dict containing filters. Each tuple
90+
or dict item consists of a filter key and a filter value.
9191
Possible filter keys are:
9292
9393
* *state* - a list of states of the VPC (pending or available)
@@ -104,7 +104,7 @@ def get_all_vpcs(self, vpc_ids=None, filters=None, dry_run=False):
104104
if vpc_ids:
105105
self.build_list_params(params, vpc_ids, 'VpcId')
106106
if filters:
107-
self.build_filter_params(params, dict(filters))
107+
self.build_filter_params(params, filters)
108108
if dry_run:
109109
params['DryRun'] = 'true'
110110
return self.get_list('DescribeVpcs', params, [('item', VPC)])
@@ -204,9 +204,9 @@ def get_all_route_tables(self, route_table_ids=None, filters=None,
204204
:param route_table_ids: A list of strings with the desired route table
205205
IDs.
206206
207-
:type filters: list of tuples
208-
:param filters: A list of tuples containing filters. Each tuple
209-
consists of a filter key and a filter value.
207+
:type filters: list of tuples or dict
208+
:param filters: A list of tuples or dict containing filters. Each tuple
209+
or dict item consists of a filter key and a filter value.
210210
211211
:type dry_run: bool
212212
:param dry_run: Set to True if the operation should not actually run.
@@ -218,7 +218,7 @@ def get_all_route_tables(self, route_table_ids=None, filters=None,
218218
if route_table_ids:
219219
self.build_list_params(params, route_table_ids, "RouteTableId")
220220
if filters:
221-
self.build_filter_params(params, dict(filters))
221+
self.build_filter_params(params, filters)
222222
if dry_run:
223223
params['DryRun'] = 'true'
224224
return self.get_list('DescribeRouteTables', params,
@@ -516,9 +516,9 @@ def get_all_network_acls(self, network_acl_ids=None, filters=None):
516516
:param network_acl_ids: A list of strings with the desired network ACL
517517
IDs.
518518
519-
:type filters: list of tuples
520-
:param filters: A list of tuples containing filters. Each tuple
521-
consists of a filter key and a filter value.
519+
:type filters: list of tuples or dict
520+
:param filters: A list of tuples or dict containing filters. Each tuple
521+
or dict item consists of a filter key and a filter value.
522522
523523
:rtype: list
524524
:return: A list of :class:`boto.vpc.networkacl.NetworkAcl`
@@ -527,7 +527,7 @@ def get_all_network_acls(self, network_acl_ids=None, filters=None):
527527
if network_acl_ids:
528528
self.build_list_params(params, network_acl_ids, "NetworkAclId")
529529
if filters:
530-
self.build_filter_params(params, dict(filters))
530+
self.build_filter_params(params, filters)
531531
return self.get_list('DescribeNetworkAcls', params,
532532
[('item', NetworkAcl)])
533533

@@ -779,9 +779,9 @@ def get_all_internet_gateways(self, internet_gateway_ids=None,
779779
:type internet_gateway_ids: list
780780
:param internet_gateway_ids: A list of strings with the desired gateway IDs.
781781
782-
:type filters: list of tuples
783-
:param filters: A list of tuples containing filters. Each tuple
784-
consists of a filter key and a filter value.
782+
:type filters: list of tuples or dict
783+
:param filters: A list of tuples or dict containing filters. Each tuple
784+
or dict item consists of a filter key and a filter value.
785785
786786
:type dry_run: bool
787787
:param dry_run: Set to True if the operation should not actually run.
@@ -793,7 +793,7 @@ def get_all_internet_gateways(self, internet_gateway_ids=None,
793793
self.build_list_params(params, internet_gateway_ids,
794794
'InternetGatewayId')
795795
if filters:
796-
self.build_filter_params(params, dict(filters))
796+
self.build_filter_params(params, filters)
797797
if dry_run:
798798
params['DryRun'] = 'true'
799799
return self.get_list('DescribeInternetGateways', params,
@@ -896,9 +896,9 @@ def get_all_customer_gateways(self, customer_gateway_ids=None,
896896
:param customer_gateway_ids: A list of strings with the desired
897897
CustomerGateway ID's.
898898
899-
:type filters: list of tuples
900-
:param filters: A list of tuples containing filters. Each tuple
901-
consists of a filter key and a filter value.
899+
:type filters: list of tuples or dict
900+
:param filters: A list of tuples or dict containing filters. Each tuple
901+
or dict item consists of a filter key and a filter value.
902902
Possible filter keys are:
903903
904904
- *state*, the state of the CustomerGateway
@@ -918,7 +918,7 @@ def get_all_customer_gateways(self, customer_gateway_ids=None,
918918
self.build_list_params(params, customer_gateway_ids,
919919
'CustomerGatewayId')
920920
if filters:
921-
self.build_filter_params(params, dict(filters))
921+
self.build_filter_params(params, filters)
922922

923923
if dry_run:
924924
params['DryRun'] = 'true'
@@ -985,9 +985,9 @@ def get_all_vpn_gateways(self, vpn_gateway_ids=None, filters=None,
985985
:type vpn_gateway_ids: list
986986
:param vpn_gateway_ids: A list of strings with the desired VpnGateway ID's
987987
988-
:type filters: list of tuples
989-
:param filters: A list of tuples containing filters. Each tuple
990-
consists of a filter key and a filter value.
988+
:type filters: list of tuples or dict
989+
:param filters: A list of tuples or dict containing filters. Each tuple
990+
or dict item consists of a filter key and a filter value.
991991
Possible filter keys are:
992992
993993
- *state*, a list of states of the VpnGateway
@@ -1006,7 +1006,7 @@ def get_all_vpn_gateways(self, vpn_gateway_ids=None, filters=None,
10061006
if vpn_gateway_ids:
10071007
self.build_list_params(params, vpn_gateway_ids, 'VpnGatewayId')
10081008
if filters:
1009-
self.build_filter_params(params, dict(filters))
1009+
self.build_filter_params(params, filters)
10101010
if dry_run:
10111011
params['DryRun'] = 'true'
10121012
return self.get_list('DescribeVpnGateways', params,
@@ -1109,9 +1109,9 @@ def get_all_subnets(self, subnet_ids=None, filters=None, dry_run=False):
11091109
:type subnet_ids: list
11101110
:param subnet_ids: A list of strings with the desired Subnet ID's
11111111
1112-
:type filters: list of tuples
1113-
:param filters: A list of tuples containing filters. Each tuple
1114-
consists of a filter key and a filter value.
1112+
:type filters: list of tuples or dict
1113+
:param filters: A list of tuples or dict containing filters. Each tuple
1114+
or dict item consists of a filter key and a filter value.
11151115
Possible filter keys are:
11161116
11171117
- *state*, a list of states of the Subnet
@@ -1132,7 +1132,7 @@ def get_all_subnets(self, subnet_ids=None, filters=None, dry_run=False):
11321132
if subnet_ids:
11331133
self.build_list_params(params, subnet_ids, 'SubnetId')
11341134
if filters:
1135-
self.build_filter_params(params, dict(filters))
1135+
self.build_filter_params(params, filters)
11361136
if dry_run:
11371137
params['DryRun'] = 'true'
11381138
return self.get_list('DescribeSubnets', params, [('item', Subnet)])
@@ -1192,9 +1192,9 @@ def get_all_dhcp_options(self, dhcp_options_ids=None, filters=None, dry_run=Fals
11921192
:type dhcp_options_ids: list
11931193
:param dhcp_options_ids: A list of strings with the desired DhcpOption ID's
11941194
1195-
:type filters: list of tuples
1196-
:param filters: A list of tuples containing filters. Each tuple
1197-
consists of a filter key and a filter value.
1195+
:type filters: list of tuples or dict
1196+
:param filters: A list of tuples or dict containing filters. Each tuple
1197+
or dict item consists of a filter key and a filter value.
11981198
11991199
:type dry_run: bool
12001200
:param dry_run: Set to True if the operation should not actually run.
@@ -1206,7 +1206,7 @@ def get_all_dhcp_options(self, dhcp_options_ids=None, filters=None, dry_run=Fals
12061206
if dhcp_options_ids:
12071207
self.build_list_params(params, dhcp_options_ids, 'DhcpOptionsId')
12081208
if filters:
1209-
self.build_filter_params(params, dict(filters))
1209+
self.build_filter_params(params, filters)
12101210
if dry_run:
12111211
params['DryRun'] = 'true'
12121212
return self.get_list('DescribeDhcpOptions', params,
@@ -1339,9 +1339,9 @@ def get_all_vpn_connections(self, vpn_connection_ids=None, filters=None,
13391339
:type vpn_connection_ids: list
13401340
:param vpn_connection_ids: A list of strings with the desired VPN_CONNECTION ID's
13411341
1342-
:type filters: list of tuples
1343-
:param filters: A list of tuples containing filters. Each tuple
1344-
consists of a filter key and a filter value.
1342+
:type filters: list of tuples or dict
1343+
:param filters: A list of tuples or dict containing filters. Each tuple
1344+
or dict item consists of a filter key and a filter value.
13451345
Possible filter keys are:
13461346
13471347
- *state*, a list of states of the VPN_CONNECTION
@@ -1363,7 +1363,7 @@ def get_all_vpn_connections(self, vpn_connection_ids=None, filters=None,
13631363
self.build_list_params(params, vpn_connection_ids,
13641364
'VpnConnectionId')
13651365
if filters:
1366-
self.build_filter_params(params, dict(filters))
1366+
self.build_filter_params(params, filters)
13671367
if dry_run:
13681368
params['DryRun'] = 'true'
13691369
return self.get_list('DescribeVpnConnections', params,

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Currently Supported Services
8282
* **Networking**
8383

8484
* :doc:`Route 53 <route53_tut>` -- (:doc:`API Reference <ref/route53>`) (Python 3)
85-
* :doc:`Virtual Private Cloud (VPC) <vpc_tut>` -- (:doc:`API Reference <ref/vpc>`)
85+
* :doc:`Virtual Private Cloud (VPC) <vpc_tut>` -- (:doc:`API Reference <ref/vpc>`) (Python 3)
8686
* :doc:`Elastic Load Balancing (ELB) <elb_tut>` -- (:doc:`API Reference <ref/elb>`) (Python 3)
8787
* AWS Direct Connect (Python 3)
8888

tests/integration/ec2/vpc/test_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2121
# IN THE SOFTWARE.
2222
#
23-
import unittest
2423
import time
2524

2625
import boto
26+
from boto.compat import unittest, six
2727
from boto.ec2.networkinterface import NetworkInterfaceCollection
2828
from boto.ec2.networkinterface import NetworkInterfaceSpecification
2929
from boto.ec2.networkinterface import PrivateIPAddress
@@ -37,7 +37,7 @@ def setUp(self):
3737
# Registry for cleaning up the vpc after all instances are terminated
3838
# in the format [ ( func, (arg1, ... argn) ) ]
3939
self.post_terminate_cleanups = []
40-
40+
4141
self.api = boto.connect_vpc()
4242
self.vpc = self.api.create_vpc('10.0.0.0/16')
4343

@@ -71,7 +71,7 @@ def terminate_instances(self):
7171

7272
def terminate_instance(self, instance):
7373
instance.terminate()
74-
for i in xrange(300):
74+
for i in six.moves.range(300):
7575
instance.update()
7676
if instance.state == 'terminated':
7777
# Give it a litle more time to settle.

tests/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'tests/unit/sts',
6363
'tests/unit/swf',
6464
'tests/unit/utils',
65+
'tests/unit/vpc',
6566
'tests/unit/test_connection.py',
6667
'tests/unit/test_exception.py',
6768
'tests/unit/test_regioninfo.py',

tests/unit/vpc/test_customergateway.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from tests.unit import AWSMockServiceTestCase
33

44
from boto.vpc import VPCConnection, CustomerGateway
5+
from boto.compat import OrderedDict
56

67

78
class TestDescribeCustomerGateways(AWSMockServiceTestCase):
89

910
connection_class = VPCConnection
1011

1112
def default_body(self):
12-
return """
13+
return b"""
1314
<DescribeCustomerGatewaysResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
1415
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
1516
<customerGatewaySet>
@@ -29,8 +30,8 @@ def test_get_all_customer_gateways(self):
2930
self.set_http_response(status_code=200)
3031
api_response = self.service_connection.get_all_customer_gateways(
3132
'cgw-b4dc3961',
32-
filters=[('state', ['pending', 'available']),
33-
('ip-address', '12.1.2.3')])
33+
filters=OrderedDict([('state', ['pending', 'available']),
34+
('ip-address', '12.1.2.3')]))
3435
self.assert_request_parameters({
3536
'Action': 'DescribeCustomerGateways',
3637
'CustomerGatewayId.1': 'cgw-b4dc3961',
@@ -52,7 +53,7 @@ class TestCreateCustomerGateway(AWSMockServiceTestCase):
5253
connection_class = VPCConnection
5354

5455
def default_body(self):
55-
return """
56+
return b"""
5657
<CreateCustomerGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
5758
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
5859
<customerGateway>
@@ -91,7 +92,7 @@ class TestDeleteCustomerGateway(AWSMockServiceTestCase):
9192
connection_class = VPCConnection
9293

9394
def default_body(self):
94-
return """
95+
return b"""
9596
<DeleteCustomerGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
9697
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
9798
<return>true</return>

tests/unit/vpc/test_dhcpoptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestDescribeDhcpOptions(AWSMockServiceTestCase):
99
connection_class = VPCConnection
1010

1111
def default_body(self):
12-
return """
12+
return b"""
1313
<DescribeDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
1414
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
1515
<dhcpOptionsSet>
@@ -71,7 +71,7 @@ class TestCreateDhcpOptions(AWSMockServiceTestCase):
7171
connection_class = VPCConnection
7272

7373
def default_body(self):
74-
return """
74+
return b"""
7575
<CreateDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
7676
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
7777
<dhcpOptions>
@@ -167,7 +167,7 @@ class TestDeleteDhcpOptions(AWSMockServiceTestCase):
167167
connection_class = VPCConnection
168168

169169
def default_body(self):
170-
return """
170+
return b"""
171171
<DeleteDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
172172
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
173173
<return>true</return>
@@ -191,7 +191,7 @@ class TestAssociateDhcpOptions(AWSMockServiceTestCase):
191191
connection_class = VPCConnection
192192

193193
def default_body(self):
194-
return """
194+
return b"""
195195
<AssociateDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
196196
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
197197
<return>true</return>

tests/unit/vpc/test_internetgateway.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestDescribeInternetGateway(AWSMockServiceTestCase):
99
connection_class = VPCConnection
1010

1111
def default_body(self):
12-
return """
12+
return b"""
1313
<DescribeInternetGatewaysResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
1414
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
1515
<internetGatewaySet>
@@ -50,7 +50,7 @@ class TestCreateInternetGateway(AWSMockServiceTestCase):
5050
connection_class = VPCConnection
5151

5252
def default_body(self):
53-
return """
53+
return b"""
5454
<CreateInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
5555
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
5656
<internetGateway>
@@ -78,7 +78,7 @@ class TestDeleteInternetGateway(AWSMockServiceTestCase):
7878
connection_class = VPCConnection
7979

8080
def default_body(self):
81-
return """
81+
return b"""
8282
<DeleteInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
8383
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
8484
<return>true</return>
@@ -102,7 +102,7 @@ class TestAttachInternetGateway(AWSMockServiceTestCase):
102102
connection_class = VPCConnection
103103

104104
def default_body(self):
105-
return """
105+
return b"""
106106
<AttachInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
107107
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
108108
<return>true</return>
@@ -128,7 +128,7 @@ class TestDetachInternetGateway(AWSMockServiceTestCase):
128128
connection_class = VPCConnection
129129

130130
def default_body(self):
131-
return """
131+
return b"""
132132
<DetachInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
133133
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
134134
<return>true</return>

0 commit comments

Comments
 (0)