mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
raise AnsibleAWSError instead of StandardError.
* StandardError doesn't exist in python3 * because it is the root of builtin expections, we can't catch it separate from the builtin exceptions * It doesn't tell us anything about the error being thrown as it's too generic
This commit is contained in:
parent
dc0fae1af7
commit
19d5759771
1 changed files with 9 additions and 5 deletions
|
@ -40,6 +40,10 @@ except:
|
||||||
HAS_LOOSE_VERSION = False
|
HAS_LOOSE_VERSION = False
|
||||||
|
|
||||||
|
|
||||||
|
class AnsibleAWSError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
|
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
|
||||||
profile = params.pop('profile_name', None)
|
profile = params.pop('profile_name', None)
|
||||||
params['aws_session_token'] = params.pop('security_token', None)
|
params['aws_session_token'] = params.pop('security_token', None)
|
||||||
|
@ -195,9 +199,9 @@ def connect_to_aws(aws_module, region, **params):
|
||||||
conn = aws_module.connect_to_region(region, **params)
|
conn = aws_module.connect_to_region(region, **params)
|
||||||
if not conn:
|
if not conn:
|
||||||
if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]:
|
if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]:
|
||||||
raise StandardError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade boto or extend with endpoints_path" % (region, aws_module.__name__))
|
raise AnsibleAWSError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade boto or extend with endpoints_path" % (region, aws_module.__name__))
|
||||||
else:
|
else:
|
||||||
raise StandardError("Unknown problem connecting to region %s for aws module %s." % (region, aws_module.__name__))
|
raise AnsibleAWSError("Unknown problem connecting to region %s for aws module %s." % (region, aws_module.__name__))
|
||||||
if params.get('profile_name'):
|
if params.get('profile_name'):
|
||||||
conn = boto_fix_security_token_in_profile(conn, params['profile_name'])
|
conn = boto_fix_security_token_in_profile(conn, params['profile_name'])
|
||||||
return conn
|
return conn
|
||||||
|
@ -213,13 +217,13 @@ def ec2_connect(module):
|
||||||
if region:
|
if region:
|
||||||
try:
|
try:
|
||||||
ec2 = connect_to_aws(boto.ec2, region, **boto_params)
|
ec2 = connect_to_aws(boto.ec2, region, **boto_params)
|
||||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
# Otherwise, no region so we fallback to the old connection method
|
# Otherwise, no region so we fallback to the old connection method
|
||||||
elif ec2_url:
|
elif ec2_url:
|
||||||
try:
|
try:
|
||||||
ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params)
|
ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params)
|
||||||
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError), e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Either region or ec2_url must be specified")
|
module.fail_json(msg="Either region or ec2_url must be specified")
|
||||||
|
|
Loading…
Reference in a new issue