diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c39ec..07c771d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log +## 1.5.3 + +- **feature:** add replace_existing_checks option to agent.service.register() +- **revert:** add replace_existing_checks option to Catalog.register() + ## 1.5.2 - **feature:** add replace_existing_checks option to Catalog.register() diff --git a/consul/__init__.py b/consul/__init__.py index 2da0f91..cbe2f38 100644 --- a/consul/__init__.py +++ b/consul/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.5.2" +__version__ = "1.5.3" from consul.check import Check from consul.exceptions import ACLDisabled, ACLPermissionDenied, ConsulException, NotFound, Timeout diff --git a/consul/api/agent.py b/consul/api/agent.py index df999b2..7dc63ec 100644 --- a/consul/api/agent.py +++ b/consul/api/agent.py @@ -152,6 +152,7 @@ def register( timeout=None, enable_tag_override=False, extra_checks=None, + replace_existing_checks=False, ): """ Add a new service to the local agent. There is more @@ -184,6 +185,11 @@ def register( *script*, *interval*, *ttl*, *http*, and *timeout* arguments are deprecated. use *check* instead. + *replace_existing_checks* Missing health checks from the request will + be deleted from the agent. + Using this parameter allows to idempotently register a service and its + checks without having to manually deregister checks. + *enable_tag_override* is an optional bool that enable you to modify a service tags from servers(consul agent role server) Default is set to False. @@ -214,15 +220,15 @@ def register( payload["checks"] = [check] + extra_checks if weights: payload["weights"] = weights - else: payload.update( Check._compat( # pylint: disable=protected-access script=script, interval=interval, ttl=ttl, http=http, timeout=timeout ) ) - params = [] + if replace_existing_checks: + params.append(("replace-existing-checks", "true")) headers = self.agent.prepare_headers(token) return self.agent.http.put( CB.bool(), "/v1/agent/service/register", params=params, headers=headers, data=json.dumps(payload) diff --git a/consul/api/catalog.py b/consul/api/catalog.py index 633c64a..8bba8f3 100644 --- a/consul/api/catalog.py +++ b/consul/api/catalog.py @@ -7,17 +7,7 @@ class Catalog: def __init__(self, agent): self.agent = agent - def register( - self, - node, - address, - service=None, - check=None, - dc=None, - token=None, - node_meta=None, - replace_existing_checks=False, - ): + def register(self, node, address, service=None, check=None, dc=None, token=None, node_meta=None): """ A low level mechanism for directly registering or updating entries in the catalog. It is usually recommended to use @@ -70,11 +60,6 @@ def register( *node_meta* is an optional meta data used for filtering, a dictionary formatted as {k1:v1, k2:v2}. - *replace_existing_checks* Missing health checks from the request will - be deleted from the agent. - Using this parameter allows to idempotently register a service and its - checks without having to manually deregister checks. - This manipulates the health check entry, but does not setup a script or TTL to actually update the status. The full documentation is `here `_. @@ -94,8 +79,6 @@ def register( if token: data["WriteRequest"] = {"Token": token} params.append(("token", token)) - if replace_existing_checks: - params.append(("replace-existing-checks", "true")) if node_meta: for nodemeta_name, nodemeta_value in node_meta.items(): params.append(("node-meta", f"{nodemeta_name}:{nodemeta_value}"))