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

Commit

Permalink
Use generic connect function
Browse files Browse the repository at this point in the history
This points all the existing `connect_to_region` functions to the
generic `connect` function within regioninfo.
  • Loading branch information
JordonPhillips committed Feb 10, 2017
1 parent 0f6ac4d commit 74daf34
Show file tree
Hide file tree
Showing 49 changed files with 744 additions and 218 deletions.
8 changes: 4 additions & 4 deletions boto/awslambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -34,7 +35,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.awslambda.layer1 import AWSLambdaConnection
return connect('awslambda', region_name,
connection_cls=AWSLambdaConnection, **kw_params)
12 changes: 6 additions & 6 deletions boto/beanstalk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -30,15 +31,14 @@ def regions():
:rtype: list
:return: A list of :class:`boto.regioninfo.RegionInfo`
"""
import boto.beanstalk.layer1
from boto.beanstalk.layer1 import Layer1
return get_regions(
'elasticbeanstalk',
connection_cls=boto.beanstalk.layer1.Layer1
connection_cls=Layer1
)


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.beanstalk.layer1 import Layer1
return connect('elasticbeanstalk', region_name, connection_cls=Layer1,
**kw_params)
7 changes: 3 additions & 4 deletions boto/cloudformation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from boto.cloudformation.connection import CloudFormationConnection
from boto.regioninfo import RegionInfo, get_regions, load_regions
from boto.regioninfo import connect

RegionData = load_regions().get('cloudformation')

Expand Down Expand Up @@ -50,7 +51,5 @@ def connect_to_region(region_name, **kw_params):
:return: A connection to the given region, or None if an invalid region
name is given
"""
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
return connect('cloudformation', region_name,
connection_cls=CloudFormationConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/cloudhsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cloudhsm.layer1 import CloudHSMConnection
return connect('cloudhsm', region_name, connection_cls=CloudHSMConnection,
**kw_params)
15 changes: 6 additions & 9 deletions boto/cloudsearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -31,15 +32,11 @@ def regions():
:rtype: list
:return: A list of :class:`boto.regioninfo.RegionInfo`
"""
import boto.cloudsearch.layer1
return get_regions(
'cloudsearch',
connection_cls=boto.cloudsearch.layer1.Layer1
)
from boto.cloudsearch.layer1 import Layer1
return get_regions('cloudsearch',connection_cls=Layer1)


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cloudsearch.layer1 import Layer1
return connect('cloudsearch', region_name, connection_cls=Layer1,
**kw_params)
15 changes: 6 additions & 9 deletions boto/cloudsearch2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from boto.regioninfo import get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -28,15 +29,11 @@ def regions():
:rtype: list
:return: A list of :class:`boto.regioninfo.RegionInfo`
"""
import boto.cloudsearch2.layer1
return get_regions(
'cloudsearch',
connection_cls=boto.cloudsearch2.layer1.CloudSearchConnection
)
from boto.cloudsearch2.layer1 import CloudSearchConnection
return get_regions('cloudsearch', connection_cls=CloudSearchConnection)


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cloudsearch2.layer1 import CloudSearchConnection
return connect('cloudsearch', region_name,
connection_cls=CloudSearchConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/cloudsearchdomain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cloudsearchdomain.layer1 import CloudSearchDomainConnection
return connect('cloudsearchdomain', region_name,
connection_cls=CloudSearchDomainConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/cloudtrail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cloudtrail.layer1 import CloudTrailConnection
return connect('cloudtrail', region_name,
connection_cls=CloudTrailConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/codedeploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -34,7 +35,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.codedeploy.layer1 import CodeDeployConnection
return connect('codedeploy', region_name,
connection_cls=CodeDeployConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/cognito/identity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -36,7 +37,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cognito.identity.layer1 import CognitoIdentityConnection
return connect('cognito-identity', region_name,
connection_cls=CognitoIdentityConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/cognito/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.cognito.sync.layer1 import CognitoSyncConnection
return connect('cognito-sync', region_name,
connection_cls=CognitoSyncConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/configservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.configservice.layer1 import ConfigServiceConnection
return connect('configservice', region_name,
connection_cls=ConfigServiceConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/datapipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.datapipeline.layer1 import DataPipelineConnection
return connect('datapipeline', region_name,
connection_cls=DataPipelineConnection, **kw_params)
8 changes: 4 additions & 4 deletions boto/directconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -35,7 +36,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.directconnect.layer1 import DirectConnectConnection
return connect('directconnect', region_name,
connection_cls=DirectConnectConnection, **kw_params)
11 changes: 5 additions & 6 deletions boto/dynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#

from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -31,12 +32,10 @@ def regions():
:rtype: list
:return: A list of :class:`boto.regioninfo.RegionInfo`
"""
import boto.dynamodb.layer2
return get_regions('dynamodb', connection_cls=boto.dynamodb.layer2.Layer2)
from boto.dynamodb.layer2 import Layer2
return get_regions('dynamodb', connection_cls=Layer2)


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.dynamodb.layer2 import Layer2
return connect('dynamodb', region_name, connection_cls=Layer2, **kw_params)
8 changes: 4 additions & 4 deletions boto/dynamodb2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#

from boto.regioninfo import RegionInfo, get_regions
from boto.regioninfo import connect


def regions():
Expand All @@ -36,7 +37,6 @@ def regions():


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
from boto.dynamodb2.layer1 import DynamoDBConnection
return connect('dynamodb', region_name, connection_cls=DynamoDBConnection,
**kw_params)
8 changes: 3 additions & 5 deletions boto/ec2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""
from boto.ec2.connection import EC2Connection
from boto.regioninfo import RegionInfo, get_regions, load_regions
from boto.regioninfo import connect


RegionData = load_regions().get('ec2', {})
Expand Down Expand Up @@ -61,11 +62,8 @@ def connect_to_region(region_name, **kw_params):
and region_name == kw_params['region'].name:
return EC2Connection(**kw_params)

for region in regions(**kw_params):
if region.name == region_name:
return region.connect(**kw_params)

return None
return connect('ec2', region_name,
connection_cls=EC2Connection, **kw_params)


def get_region(region_name, **kw_params):
Expand Down
7 changes: 3 additions & 4 deletions boto/ec2/autoscale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import boto
from boto.connection import AWSQueryConnection
from boto.regioninfo import RegionInfo, get_regions, load_regions
from boto.regioninfo import connect
from boto.ec2.autoscale.request import Request
from boto.ec2.autoscale.launchconfig import LaunchConfiguration
from boto.ec2.autoscale.group import AutoScalingGroup
Expand Down Expand Up @@ -71,10 +72,8 @@ def connect_to_region(region_name, **kw_params):
:return: A connection to the given region, or None if an invalid region
name is given
"""
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
return connect('autoscaling', region_name,
connection_cls=AutoScaleConnection, **kw_params)


class AutoScaleConnection(AWSQueryConnection):
Expand Down
Loading

0 comments on commit 74daf34

Please sign in to comment.