OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2006-2012 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 3 # All rights reserved. |
| 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. |
| 23 # |
| 24 |
| 25 from boto.regioninfo import RegionInfo |
| 26 |
| 27 |
| 28 class S3RegionInfo(RegionInfo): |
| 29 |
| 30 def connect(self, **kw_params): |
| 31 """ |
| 32 Connect to this Region's endpoint. Returns an connection |
| 33 object pointing to the endpoint associated with this region. |
| 34 You may pass any of the arguments accepted by the connection |
| 35 class's constructor as keyword arguments and they will be |
| 36 passed along to the connection object. |
| 37 |
| 38 :rtype: Connection object |
| 39 :return: The connection to this regions endpoint |
| 40 """ |
| 41 if self.connection_cls: |
| 42 return self.connection_cls(host=self.endpoint, **kw_params) |
| 43 |
| 44 |
| 45 def regions(): |
| 46 """ |
| 47 Get all available regions for the Amazon S3 service. |
| 48 |
| 49 :rtype: list |
| 50 :return: A list of :class:`boto.regioninfo.RegionInfo` |
| 51 """ |
| 52 from .connection import S3Connection |
| 53 return [S3RegionInfo(name='us-east-1', |
| 54 endpoint='s3.amazonaws.com', |
| 55 connection_cls=S3Connection), |
| 56 S3RegionInfo(name='us-west-1', |
| 57 endpoint='s3-us-west-1.amazonaws.com', |
| 58 connection_cls=S3Connection), |
| 59 S3RegionInfo(name='us-west-2', |
| 60 endpoint='s3-us-west-2.amazonaws.com', |
| 61 connection_cls=S3Connection), |
| 62 S3RegionInfo(name='ap-northeast-1', |
| 63 endpoint='s3-ap-northeast-1.amazonaws.com', |
| 64 connection_cls=S3Connection), |
| 65 S3RegionInfo(name='ap-southeast-1', |
| 66 endpoint='s3-ap-southeast-1.amazonaws.com', |
| 67 connection_cls=S3Connection), |
| 68 S3RegionInfo(name='ap-southeast-2', |
| 69 endpoint='s3-ap-southeast-2.amazonaws.com', |
| 70 connection_cls=S3Connection), |
| 71 S3RegionInfo(name='eu-west-1', |
| 72 endpoint='s3-eu-west-1.amazonaws.com', |
| 73 connection_cls=S3Connection), |
| 74 S3RegionInfo(name='sa-east-1', |
| 75 endpoint='s3-sa-east-1.amazonaws.com', |
| 76 connection_cls=S3Connection), |
| 77 ] |
| 78 |
| 79 |
| 80 def connect_to_region(region_name, **kw_params): |
| 81 for region in regions(): |
| 82 if region.name == region_name: |
| 83 return region.connect(**kw_params) |
| 84 return None |
OLD | NEW |