mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-09 17:59:09 -07:00
generalize error context reporting, add elasticache explanations
This commit is contained in:
parent
610223fbf4
commit
17b94cf139
1 changed files with 10 additions and 11 deletions
|
@ -406,9 +406,7 @@ class Ec2Inventory(object):
|
||||||
else:
|
else:
|
||||||
backend = 'Eucalyptus' if self.eucalyptus else 'AWS'
|
backend = 'Eucalyptus' if self.eucalyptus else 'AWS'
|
||||||
error = "Error connecting to %s backend.\n%s" % (backend, e.message)
|
error = "Error connecting to %s backend.\n%s" % (backend, e.message)
|
||||||
self.fail_with_error(
|
self.fail_with_error(error, 'getting EC2 instances')
|
||||||
'ERROR: "{error}", while: {err_operation}'.format(
|
|
||||||
error=error, err_operation='getting EC2 instances'))
|
|
||||||
|
|
||||||
def get_rds_instances_by_region(self, region):
|
def get_rds_instances_by_region(self, region):
|
||||||
''' Makes an AWS API call to the list of RDS instances in a particular
|
''' Makes an AWS API call to the list of RDS instances in a particular
|
||||||
|
@ -427,9 +425,7 @@ class Ec2Inventory(object):
|
||||||
error = self.get_auth_error_message()
|
error = self.get_auth_error_message()
|
||||||
if not e.reason == "Forbidden":
|
if not e.reason == "Forbidden":
|
||||||
error = "Looks like AWS RDS is down:\n%s" % e.message
|
error = "Looks like AWS RDS is down:\n%s" % e.message
|
||||||
self.fail_with_error(
|
self.fail_with_error(error, 'getting RDS instances')
|
||||||
'ERROR: "{error}", while: {err_operation}'.format(
|
|
||||||
error=error, err_operation='getting RDS instances'))
|
|
||||||
|
|
||||||
def get_elasticache_clusters_by_region(self, region):
|
def get_elasticache_clusters_by_region(self, region):
|
||||||
''' Makes an AWS API call to the list of ElastiCache clusters (with
|
''' Makes an AWS API call to the list of ElastiCache clusters (with
|
||||||
|
@ -452,7 +448,7 @@ class Ec2Inventory(object):
|
||||||
error = self.get_auth_error_message()
|
error = self.get_auth_error_message()
|
||||||
if not e.reason == "Forbidden":
|
if not e.reason == "Forbidden":
|
||||||
error = "Looks like AWS ElastiCache is down:\n%s" % e.message
|
error = "Looks like AWS ElastiCache is down:\n%s" % e.message
|
||||||
self.fail_with_error(error)
|
self.fail_with_error(error, 'getting ElastiCache clusters')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Boto also doesn't provide wrapper classes to CacheClusters or
|
# Boto also doesn't provide wrapper classes to CacheClusters or
|
||||||
|
@ -462,7 +458,7 @@ class Ec2Inventory(object):
|
||||||
|
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
error = "ElastiCache query to AWS failed (unexpected format)."
|
error = "ElastiCache query to AWS failed (unexpected format)."
|
||||||
self.fail_with_error(error)
|
self.fail_with_error(error, 'getting ElastiCache clusters')
|
||||||
|
|
||||||
for cluster in clusters:
|
for cluster in clusters:
|
||||||
self.add_elasticache_cluster(cluster, region)
|
self.add_elasticache_cluster(cluster, region)
|
||||||
|
@ -486,7 +482,7 @@ class Ec2Inventory(object):
|
||||||
error = self.get_auth_error_message()
|
error = self.get_auth_error_message()
|
||||||
if not e.reason == "Forbidden":
|
if not e.reason == "Forbidden":
|
||||||
error = "Looks like AWS ElastiCache [Replication Groups] is down:\n%s" % e.message
|
error = "Looks like AWS ElastiCache [Replication Groups] is down:\n%s" % e.message
|
||||||
self.fail_with_error(error)
|
self.fail_with_error(error, 'getting ElastiCache clusters')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Boto also doesn't provide wrapper classes to ReplicationGroups
|
# Boto also doesn't provide wrapper classes to ReplicationGroups
|
||||||
|
@ -496,7 +492,7 @@ class Ec2Inventory(object):
|
||||||
|
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
error = "ElastiCache [Replication Groups] query to AWS failed (unexpected format)."
|
error = "ElastiCache [Replication Groups] query to AWS failed (unexpected format)."
|
||||||
self.fail_with_error(error)
|
self.fail_with_error(error, 'getting ElastiCache clusters')
|
||||||
|
|
||||||
for replication_group in replication_groups:
|
for replication_group in replication_groups:
|
||||||
self.add_elasticache_replication_group(replication_group, region)
|
self.add_elasticache_replication_group(replication_group, region)
|
||||||
|
@ -518,8 +514,11 @@ class Ec2Inventory(object):
|
||||||
|
|
||||||
return '\n'.join(errors)
|
return '\n'.join(errors)
|
||||||
|
|
||||||
def fail_with_error(self, err_msg):
|
def fail_with_error(self, err_msg, err_operation_context=None):
|
||||||
'''log an error to std err for ansible-playbook to consume and exit'''
|
'''log an error to std err for ansible-playbook to consume and exit'''
|
||||||
|
if err_operation_context:
|
||||||
|
err_msg = 'ERROR: "{err_msg}", while: {err_operation}'.format(
|
||||||
|
err_msg=err_msg, err_operation=err_operation_context)
|
||||||
sys.stderr.write(err_msg)
|
sys.stderr.write(err_msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue