diff options
author | James Hart <jhart@uk.ibm.com> | 2016-11-11 22:44:02 +0000 |
---|---|---|
committer | Rene Moser <mail@renemoser.net> | 2016-11-11 23:44:38 +0100 |
commit | d1be0506da9c7092af3bcfd30da0f9482ae658e6 (patch) | |
tree | 10c708d11b414f2a737966d325064cb7a93b312e | |
parent | f04d91a155982ee0a0e2e614c2f85622aed9cb06 (diff) | |
download | ansible-modules-extras-d1be0506da9c7092af3bcfd30da0f9482ae658e6.tar.gz |
consul: Pass through service_id if specified on a check (#3295)
Fixes #3249
The python-consul library already supports this, so it is just a simple
case of enablement.
This does not break the current logic in `add` of parsing as a check,
then parsing as a service if that fails… because service_name is
mandatory on a service registration and is invalid on a check
registration.
(cherry picked from commit cb87ac2a6b3f1383fc9be9a812aacfa924339dbc)
-rw-r--r-- | clustering/consul.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/clustering/consul.py b/clustering/consul.py index 12fb9630..d2913d60 100644 --- a/clustering/consul.py +++ b/clustering/consul.py @@ -185,7 +185,7 @@ EXAMPLES = ''' name: nginx service_port: 80 interval: 60s - http: /status + http: "http://localhost:80/status" - name: register external service nginx available at 10.1.5.23 consul: @@ -213,6 +213,14 @@ EXAMPLES = ''' script: "/opt/disk_usage.py" interval: 5m + - name: register an http check against a service that's already registered + consul: + check_name: nginx-check2 + check_id: nginx-check2 + service_id: nginx + interval: 60s + http: "http://localhost:80/morestatus" + ''' try: @@ -265,7 +273,7 @@ def add_check(module, check): retrieve the full metadata of an existing check through the consul api. Without this we can't compare to the supplied check and so we must assume a change. ''' - if not check.name: + if not check.name and not service_id: module.fail_json(msg='a check name is required for a node level check, one not attached to a service') consul_api = get_consul_api(module) @@ -278,7 +286,8 @@ def add_check(module, check): interval=check.interval, ttl=check.ttl, http=check.http, - timeout=check.timeout) + timeout=check.timeout, + service_id=check.service_id) def remove_check(module, check_id): @@ -363,7 +372,8 @@ def parse_check(module): module.params.get('ttl'), module.params.get('notes'), module.params.get('http'), - module.params.get('timeout') + module.params.get('timeout'), + module.params.get('service_id'), ) @@ -451,10 +461,11 @@ class ConsulService(): class ConsulCheck(): def __init__(self, check_id, name, node=None, host='localhost', - script=None, interval=None, ttl=None, notes=None, http=None, timeout=None): + script=None, interval=None, ttl=None, notes=None, http=None, timeout=None, service_id=None): self.check_id = self.name = name if check_id: self.check_id = check_id + self.service_id = service_id self.notes = notes self.node = node self.host = host @@ -488,13 +499,14 @@ class ConsulCheck(): return duration def register(self, consul_api): - consul_api.agent.check.register(self.name, check_id=self.check_id, + consul_api.agent.check.register(self.name, check_id=self.check_id, service_id=self.service_id, notes=self.notes, check=self.check) def __eq__(self, other): return (isinstance(other, self.__class__) and self.check_id == other.check_id + and self.service_id == other.service_id and self.name == other.name and self.script == script and self.interval == interval) @@ -514,6 +526,7 @@ class ConsulCheck(): self._add(data, 'ttl') self._add(data, 'http') self._add(data, 'timeout') + self._add(data, 'service_id') return data def _add(self, data, key, attr=None): |