Merge pull request #2747 from lwade/ec2_vol_region

Add region support to ec2 volume module.
pull/2469/merge
Michael DeHaan 12 years ago
commit 4350585a1f

@ -40,6 +40,12 @@ options:
required: false required: false
default: null default: null
aliases: [] aliases: []
region:
description:
- region in which to create the volume
required: false
default: null
aliases: []
zone: zone:
description: description:
- zone in which to create the volume, if unset uses the zone the instance is in (if set) - zone in which to create the volume, if unset uses the zone the instance is in (if set)
@ -71,7 +77,7 @@ import sys
import time import time
try: try:
import boto import boto.ec2
except ImportError: except ImportError:
print "failed=True msg='boto required for this module'" print "failed=True msg='boto required for this module'"
sys.exit(1) sys.exit(1)
@ -82,6 +88,7 @@ def main():
instance = dict(), instance = dict(),
volume_size = dict(required=True), volume_size = dict(required=True),
device_name = dict(), device_name = dict(),
region = dict(),
zone = dict(), zone = dict(),
ec2_url = dict(aliases=['EC2_URL']), ec2_url = dict(aliases=['EC2_URL']),
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY']), ec2_secret_key = dict(aliases=['EC2_SECRET_KEY']),
@ -92,6 +99,7 @@ def main():
instance = module.params.get('instance') instance = module.params.get('instance')
volume_size = module.params.get('volume_size') volume_size = module.params.get('volume_size')
device_name = module.params.get('device_name') device_name = module.params.get('device_name')
region = module.params.get('region')
zone = module.params.get('zone') zone = module.params.get('zone')
ec2_url = module.params.get('ec2_url') ec2_url = module.params.get('ec2_url')
ec2_secret_key = module.params.get('ec2_secret_key') ec2_secret_key = module.params.get('ec2_secret_key')
@ -105,6 +113,14 @@ def main():
if not ec2_access_key and 'EC2_ACCESS_KEY' in os.environ: if not ec2_access_key and 'EC2_ACCESS_KEY' in os.environ:
ec2_access_key = os.environ['EC2_ACCESS_KEY'] ec2_access_key = os.environ['EC2_ACCESS_KEY']
# If we have a region specified, connect to its endpoint.
if region:
try:
ec2 = boto.ec2.connect_to_region(region, aws_access_key_id=ec2_access_key, aws_secret_access_key=ec2_secret_key)
except boto.exception.NoAuthHandlerFound, e:
module.fail_json(msg = str(e))
# Otherwise, no region so we fallback to the old connection method
else:
try: try:
if ec2_url: # if we have an URL set, connect to the specified endpoint if ec2_url: # if we have an URL set, connect to the specified endpoint
ec2 = boto.connect_ec2_endpoint(ec2_url, ec2_access_key, ec2_secret_key) ec2 = boto.connect_ec2_endpoint(ec2_url, ec2_access_key, ec2_secret_key)

Loading…
Cancel
Save