[cloud] ec2.py: region is documented as optional; allow endpoints to be used - fixes #24382 (#24470)
* region isn't required for ec2.py; allow endpoints to be used * move where aws_connect_kwargs is set * remove camel_dict_to_snake_dict and display error message
This commit is contained in:
parent
58db0da5a5
commit
3bba43a487
1 changed files with 13 additions and 12 deletions
|
@ -615,11 +615,12 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
import traceback
|
||||
import time
|
||||
from ast import literal_eval
|
||||
from ansible.module_utils.six import get_function_code
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect, connect_to_aws
|
||||
from ansible.module_utils.ec2 import get_aws_connection_info, ec2_argument_spec, ec2_connect
|
||||
from distutils.version import LooseVersion
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
@ -627,7 +628,8 @@ try:
|
|||
import boto.ec2
|
||||
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
|
||||
from boto.exception import EC2ResponseError
|
||||
from boto.vpc import VPCConnection
|
||||
from boto import connect_ec2_endpoint
|
||||
from boto import connect_vpc
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
@ -1618,17 +1620,16 @@ def main():
|
|||
if not HAS_BOTO:
|
||||
module.fail_json(msg='boto required for this module')
|
||||
|
||||
ec2 = ec2_connect(module)
|
||||
try:
|
||||
_, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
|
||||
if module.params.get('region') or not module.params.get('ec2_url'):
|
||||
ec2 = ec2_connect(module)
|
||||
elif module.params.get('ec2_url'):
|
||||
ec2 = connect_ec2_endpoint(ec2_url, **aws_connect_kwargs)
|
||||
|
||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
|
||||
|
||||
if region:
|
||||
try:
|
||||
vpc = connect_to_aws(boto.vpc, region, **aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg=str(e))
|
||||
else:
|
||||
vpc = None
|
||||
vpc = connect_vpc(**aws_connect_kwargs)
|
||||
except boto.exception.NoAuthHandlerFound as e:
|
||||
module.fail_json(msg="Failed to get connection: %s" % e.message, exception=traceback.format_exc())
|
||||
|
||||
tagged_instances = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue