amazon: extract copies of boto_exception to module_utils.ec2 (#20403)

* amazon: extract boto_exception to ec2 module

This function was copy/pasted throughout several Amazon modules. This
causes a consistency problem, since some improvements to message
formatting were applied to some modules but not others. Now all modules
use the same, improved function.

* Rebase and make requested changes

* Rebase and make requested changes
This commit is contained in:
David M. Lee 2017-08-23 10:40:32 -05:00 committed by Ryan Brown
parent 587ab33415
commit 1d4ca0fd51
10 changed files with 36 additions and 92 deletions

View file

@ -126,6 +126,23 @@ def _boto3_conn(conn_type=None, resource=None, region=None, endpoint=None, **par
boto3_inventory_conn = _boto3_conn
def boto_exception(err):
"""
Extracts the error message from a boto exception.
:param err: Exception from boto
:return: Error message
"""
if hasattr(err, 'error_message'):
error = err.error_message
elif hasattr(err, 'message'):
error = str(err.message) + ' ' + str(err) + ' - ' + str(type(err))
else:
error = '%s: %s' % (Exception, err)
return error
def aws_common_argument_spec():
return dict(
ec2_url=dict(),