From 8a4868017160e2a3f5fdeb98b6c9b920b647d51a Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sat, 26 Dec 2015 14:12:49 +1000 Subject: [PATCH] Add support for join and force-leave Resolves: #51 --- consul/base.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/consul/base.py b/consul/base.py index 4592a576..178dee3d 100644 --- a/consul/base.py +++ b/consul/base.py @@ -507,7 +507,6 @@ class Agent(object): takes on the burden of registering with the Catalog and performing anti-entropy to recover from outages. """ - # TODO: join, force-leave def __init__(self, agent): self.agent = agent self.service = Consul.Agent.Service(agent) @@ -590,6 +589,44 @@ def maintenance(self, enable, reason=None): '/v1/agent/maintenance', params=params) + def join(self, address, wan=False): + """ + This endpoint instructs the agent to attempt to connect to a + given address. + + *address* is the ip to connect to. + + *wan* is either 'true' or 'false'. For agents running in server + mode, 'true' causes the agent to attempt to join using the WAN + pool. Default is 'false'. + """ + + params = {} + + if wan: + params['wan'] = 1 + + return self.agent.http.get( + lambda x: x.code == 200, + '/v1/agent/join/%s' % address, + params=params) + + def force_leave(self, node): + """ + This endpoint instructs the agent to force a node into the left + state. If a node fails unexpectedly, then it will be in a failed + state. Once in the failed state, Consul will attempt to reconnect, + and the services and checks belonging to that node will not be + cleaned up. Forcing a node into the left state allows its old + entries to be removed. + + *node* is the node to change state for. + """ + + return self.agent.http.get( + lambda x: x.code == 200, + '/v1/agent/force-leave/%s' % node) + class Service(object): def __init__(self, agent): self.agent = agent