From 2b8dd2cc6ae43c06ad44b2920c1df69ecbf2709a Mon Sep 17 00:00:00 2001 From: Antoine Barbare Date: Sat, 6 Oct 2018 13:23:33 +0200 Subject: [PATCH 1/2] feat: implements issue #236 --- consul/base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/consul/base.py b/consul/base.py index ee6ab254..609800e2 100755 --- a/consul/base.py +++ b/consul/base.py @@ -806,6 +806,20 @@ def force_leave(self, node): return self.agent.http.put( CB.bool(), '/v1/agent/force-leave/%s' % node) + def leave(self, node): + """ + 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. + """ + + return self.agent.http.put( + CB.bool(), '/v1/agent/leave/%s' % node) + class Service(object): def __init__(self, agent): self.agent = agent From c30683002f11513162e83160887b40fb6044c27a Mon Sep 17 00:00:00 2001 From: Antoine Barbare Date: Sat, 6 Oct 2018 13:37:07 +0200 Subject: [PATCH 2/2] pep8 --- consul/base.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/consul/base.py b/consul/base.py index 609800e2..17d375c7 100755 --- a/consul/base.py +++ b/consul/base.py @@ -358,6 +358,7 @@ class Event(object): practice, this means you cannot rely on the order of message delivery. An advantage however is that events can still be used even in the absence of server nodes or during an outage.""" + def __init__(self, agent): self.agent = agent @@ -465,6 +466,7 @@ class KV(object): used to store service configurations or other meta data in a simple way. """ + def __init__(self, agent): self.agent = agent @@ -662,6 +664,7 @@ class Txn(object): The Transactions endpoints manage updates or fetches of multiple keys inside a single, atomic transaction. """ + def __init__(self, agent): self.agent = agent @@ -697,6 +700,7 @@ class Agent(object): takes on the burden of registering with the Catalog and performing anti-entropy to recover from outages. """ + def __init__(self, agent): self.agent = agent self.service = Consul.Agent.Service(agent) @@ -809,10 +813,12 @@ def force_leave(self, node): def leave(self, node): """ 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. + 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. """ @@ -2125,6 +2131,7 @@ class Status(object): The Status endpoints are used to get information about the status of the Consul cluster. """ + def __init__(self, agent): self.agent = agent