summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorKristóf Havasi <chris.hvse@gmail.com>2018-01-19 22:33:52 +0100
committeransibot <ansibot@users.noreply.github.com>2018-01-19 16:33:52 -0500
commit1c22d82c5e8d624046323aa6c2a87d3b68009c60 (patch)
tree129e00ff6eb7b5702bfdf4ea88112621765c6eb8 /contrib
parenta13958d2738cea9512b4501181a780ddda442cbb (diff)
downloadansible-1c22d82c5e8d624046323aa6c2a87d3b68009c60.tar.gz
consul_io: fixed service availability check (#34293)
service is only up if the node publishing it is also available
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/consul_io.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/contrib/inventory/consul_io.py b/contrib/inventory/consul_io.py
index f9edd88add..8c311d3321 100755
--- a/contrib/inventory/consul_io.py
+++ b/contrib/inventory/consul_io.py
@@ -261,17 +261,25 @@ class ConsulInventory(object):
if self.config.has_config('availability'):
for service_name, service in iteritems(node['Services']):
for node in self.consul_api.health.service(service_name)[1]:
- for check in node['Checks']:
- if check['ServiceName'] == service_name:
- ok = 'passing' == check['Status']
- if ok:
- suffix = self.config.get_availability_suffix(
- 'available_suffix', '_available')
- else:
- suffix = self.config.get_availability_suffix(
- 'unavailable_suffix', '_unavailable')
- self.add_node_to_map(self.nodes_by_availability,
- service_name + suffix, node['Node'])
+ if self.is_service_available(node, service_name):
+ suffix = self.config.get_availability_suffix(
+ 'available_suffix', '_available')
+ else:
+ suffix = self.config.get_availability_suffix(
+ 'unavailable_suffix', '_unavailable')
+ self.add_node_to_map(self.nodes_by_availability,
+ service_name + suffix, node['Node'])
+
+ def is_service_available(self, node, service_name):
+ '''check the availability of the service on the node beside ensuring the
+ availability of the node itself'''
+ consul_ok = service_ok = False
+ for check in node['Checks']:
+ if check['CheckID'] == 'serfHealth':
+ consul_ok = check['Status'] == 'passing'
+ elif check['ServiceName'] == service_name:
+ service_ok = check['Status'] == 'passing'
+ return consul_ok and service_ok
def consul_get_kv_inmemory(self, key):
result = filter(lambda x: x['Key'] == key, self.inmemory_kv)