Skip to content

Commit

Permalink
Merge pull request ansible#566 from 47lining/cloud_modules_sts_suppor…
Browse files Browse the repository at this point in the history
…t_redux

Cloud Modules STS Support Redux
  • Loading branch information
bcoca committed Mar 27, 2015
2 parents eacf4e4 + a01a0ed commit aeb264f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 141 deletions.
31 changes: 6 additions & 25 deletions cloud/amazon/cloudformation.py
Expand Up @@ -41,12 +41,6 @@
required: false
default: {}
aliases: []
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: ['aws_region', 'ec2_region']
state:
description:
- If state is "present", stack will be created. If state is "present" and if stack exists and template has changed, it will be updated.
Expand Down Expand Up @@ -75,29 +69,17 @@
default: null
aliases: []
version_added: "1.4"
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
version_added: "1.5"
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
version_added: "1.5"
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
required: false
- The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: ['aws_region', 'ec2_region']
version_added: "1.5"
requirements: [ "boto" ]
author: James S. Martin
extends_documentation_fragment: aws
'''

EXAMPLES = '''
Expand Down Expand Up @@ -220,7 +202,7 @@ def main():
template_parameters = module.params['template_parameters']
tags = module.params['tags']

ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

kwargs = dict()
if tags is not None:
Expand All @@ -236,8 +218,7 @@ def main():
try:
cfn = boto.cloudformation.connect_to_region(
region,
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
**aws_connect_kwargs
)
except boto.exception.NoAuthHandlerFound, e:
module.fail_json(msg=str(e))
Expand Down
40 changes: 16 additions & 24 deletions cloud/amazon/ec2_vpc.py
Expand Up @@ -96,33 +96,13 @@
aliases: []
region:
description:
- region in which the resource exists.
required: false
- The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: ['aws_region', 'ec2_region']
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key' ]
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_access_key', 'access_key' ]
validate_certs:
description:
- When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0.
required: false
default: "yes"
choices: ["yes", "no"]
aliases: []
version_added: "1.5"
requirements: [ "boto" ]
author: Carson Gee
extends_documentation_fragment: aws
'''

EXAMPLES = '''
Expand Down Expand Up @@ -599,7 +579,19 @@ def main():

state = module.params.get('state')

vpc_conn = ec2_connect(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

# If we have a region specified, connect to its endpoint.
if region:
try:
vpc_conn = boto.vpc.connect_to_region(
region,
**aws_connect_kwargs
)
except boto.exception.NoAuthHandlerFound, e:
module.fail_json(msg = str(e))
else:
module.fail_json(msg="region must be specified")

if module.params.get('state') == 'absent':
vpc_id = module.params.get('vpc_id')
Expand Down
38 changes: 13 additions & 25 deletions cloud/amazon/elasticache.py
Expand Up @@ -92,24 +92,13 @@
required: false
default: no
choices: [ "yes", "no" ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key']
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_access_key', 'access_key']
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
required: false
- The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: ['aws_region', 'ec2_region']
extends_documentation_fragment: aws
"""

EXAMPLES = """
Expand Down Expand Up @@ -163,7 +152,7 @@ class ElastiCacheManager(object):
def __init__(self, module, name, engine, cache_engine_version, node_type,
num_nodes, cache_port, cache_subnet_group,
cache_security_groups, security_group_ids, zone, wait,
hard_modify, aws_access_key, aws_secret_key, region):
hard_modify, region, **aws_connect_kwargs):
self.module = module
self.name = name
self.engine = engine
Expand All @@ -178,9 +167,8 @@ def __init__(self, module, name, engine, cache_engine_version, node_type,
self.wait = wait
self.hard_modify = hard_modify

self.aws_access_key = aws_access_key
self.aws_secret_key = aws_secret_key
self.region = region
self.aws_connect_kwargs = aws_connect_kwargs

self.changed = False
self.data = None
Expand Down Expand Up @@ -433,9 +421,10 @@ def _get_elasticache_connection(self):
try:
endpoint = "elasticache.%s.amazonaws.com" % self.region
connect_region = RegionInfo(name=self.region, endpoint=endpoint)
return ElastiCacheConnection(aws_access_key_id=self.aws_access_key,
aws_secret_access_key=self.aws_secret_key,
region=connect_region)
return ElastiCacheConnection(
region=connect_region,
**self.aws_connect_kwargs
)
except boto.exception.NoAuthHandlerFound, e:
self.module.fail_json(msg=e.message)

Expand Down Expand Up @@ -509,7 +498,7 @@ def main():
argument_spec=argument_spec,
)

ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

name = module.params['name']
state = module.params['state']
Expand Down Expand Up @@ -537,16 +526,15 @@ def main():
module.fail_json(msg="'num_nodes' is a required parameter. Please specify num_nodes > 0")

if not region:
module.fail_json(msg=str("Either region or EC2_REGION environment variable must be set."))
module.fail_json(msg=str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))

elasticache_manager = ElastiCacheManager(module, name, engine,
cache_engine_version, node_type,
num_nodes, cache_port,
cache_subnet_group,
cache_security_groups,
security_group_ids, zone, wait,
hard_modify, aws_access_key,
aws_secret_key, region)
hard_modify, region, **aws_connect_kwargs)

if state == 'present':
elasticache_manager.ensure_present()
Expand Down
23 changes: 6 additions & 17 deletions cloud/amazon/rds_param_group.py
Expand Up @@ -63,24 +63,13 @@
choices: [ 'mysql5.1', 'mysql5.5', 'mysql5.6', 'oracle-ee-11.2', 'oracle-se-11.2', 'oracle-se1-11.2', 'postgres9.3', 'sqlserver-ee-10.5', 'sqlserver-ee-11.0', 'sqlserver-ex-10.5', 'sqlserver-ex-11.0', 'sqlserver-se-10.5', 'sqlserver-se-11.0', 'sqlserver-web-10.5', 'sqlserver-web-11.0']
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
- The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: [ 'aws_region', 'ec2_region' ]
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
aliases: ['aws_region', 'ec2_region']
requirements: [ "boto" ]
author: Scott Anderson
extends_documentation_fragment: aws
'''

EXAMPLES = '''
Expand Down Expand Up @@ -248,13 +237,13 @@ def main():
module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed))

# Retrieve any AWS settings from the environment.
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

if not region:
module.fail_json(msg = str("region not specified and unable to determine region from EC2_REGION."))
module.fail_json(msg = str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))

try:
conn = boto.rds.connect_to_region(region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key)
conn = boto.rds.connect_to_region(region, **aws_connect_kwargs)
except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message)

Expand Down
23 changes: 6 additions & 17 deletions cloud/amazon/rds_subnet_group.py
Expand Up @@ -49,24 +49,13 @@
aliases: []
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
- The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: [ 'aws_region', 'ec2_region' ]
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
aliases: ['aws_region', 'ec2_region']
requirements: [ "boto" ]
author: Scott Anderson
extends_documentation_fragment: aws
'''

EXAMPLES = '''
Expand Down Expand Up @@ -121,13 +110,13 @@ def main():
module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed))

# Retrieve any AWS settings from the environment.
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

if not region:
module.fail_json(msg = str("region not specified and unable to determine region from EC2_REGION."))
module.fail_json(msg = str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))

try:
conn = boto.rds.connect_to_region(region, **aws_connect_params)
conn = boto.rds.connect_to_region(region, **aws_connection_kwargs)
except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message)

Expand Down
18 changes: 4 additions & 14 deletions cloud/amazon/route53.py
Expand Up @@ -74,18 +74,6 @@
required: false
default: null
aliases: []
aws_secret_key:
description:
- AWS secret key.
required: false
default: null
aliases: ['ec2_secret_key', 'secret_key']
aws_access_key:
description:
- AWS access key.
required: false
default: null
aliases: ['ec2_access_key', 'access_key']
overwrite:
description:
- Whether an existing record should be overwritten on create if values do not match
Expand All @@ -106,6 +94,7 @@
version_added: "1.9"
requirements: [ "boto" ]
author: Bruce Pennypacker
extends_documentation_fragment: aws
'''

# FIXME: the command stuff should have a more state like configuration alias -- MPD
Expand Down Expand Up @@ -177,6 +166,7 @@
import boto
import boto.ec2
from boto import route53
from boto.route53 import Route53Connection
from boto.route53.record import ResourceRecordSets
except ImportError:
print "failed=True msg='boto required for this module'"
Expand Down Expand Up @@ -225,7 +215,7 @@ def main():
retry_interval_in = module.params.get('retry_interval')
private_zone_in = module.params.get('private_zone')

region, ec2_url, aws_connect_params = get_aws_connection_info(module)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)

value_list = ()

Expand All @@ -252,7 +242,7 @@ def main():

# connect to the route53 endpoint
try:
conn = boto.route53.Route53Connection(**aws_connect_params)
conn = Route53Connection(**aws_connect_kwargs)
except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message)

Expand Down

0 comments on commit aeb264f

Please sign in to comment.