diff --git a/consul/base.py b/consul/base.py index 9d27dbd..0559987 100755 --- a/consul/base.py +++ b/consul/base.py @@ -1350,6 +1350,26 @@ def force_leave(self, node, token=None): CB.bool(), path='/v1/agent/force-leave/%s' % node, headers=headers) + def leave(self, node, token=None): + """ + This endpoint instructs the agent to graceful leave a node. + It is used to ensure other nodes see the agent as "left" + instead of "failed". Nodes that leave will not attempt to + re-join the cluster on restarting with a snapshot. For nodes + in server mode, the node is removed from the Raft peer + set in a graceful manner. This is critical, as in certain + situations a non-graceful leave can affect cluster availability. + + *node* is the node to change state for. + """ + headers = {} + token = token or self.agent.token + if token: + headers['X-Consul-Token'] = token + + return self.agent.http.put( + CB.bool(), '/v1/agent/leave/%s' % node, headers=headers) + class Service(object): def __init__(self, agent): self.agent = agent