Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit d98a3ed

Browse files
committed
Merge pull request #85 from abn/issue/51
Add support for join and force-leave
2 parents 0d5ae9c + 8a48680 commit d98a3ed

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

consul/base.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ class Agent(object):
536536
takes on the burden of registering with the Catalog and performing
537537
anti-entropy to recover from outages.
538538
"""
539-
# TODO: join, force-leave
540539
def __init__(self, agent):
541540
self.agent = agent
542541
self.service = Consul.Agent.Service(agent)
@@ -619,6 +618,44 @@ def maintenance(self, enable, reason=None):
619618
'/v1/agent/maintenance',
620619
params=params)
621620

621+
def join(self, address, wan=False):
622+
"""
623+
This endpoint instructs the agent to attempt to connect to a
624+
given address.
625+
626+
*address* is the ip to connect to.
627+
628+
*wan* is either 'true' or 'false'. For agents running in server
629+
mode, 'true' causes the agent to attempt to join using the WAN
630+
pool. Default is 'false'.
631+
"""
632+
633+
params = {}
634+
635+
if wan:
636+
params['wan'] = 1
637+
638+
return self.agent.http.get(
639+
lambda x: x.code == 200,
640+
'/v1/agent/join/%s' % address,
641+
params=params)
642+
643+
def force_leave(self, node):
644+
"""
645+
This endpoint instructs the agent to force a node into the left
646+
state. If a node fails unexpectedly, then it will be in a failed
647+
state. Once in the failed state, Consul will attempt to reconnect,
648+
and the services and checks belonging to that node will not be
649+
cleaned up. Forcing a node into the left state allows its old
650+
entries to be removed.
651+
652+
*node* is the node to change state for.
653+
"""
654+
655+
return self.agent.http.get(
656+
lambda x: x.code == 200,
657+
'/v1/agent/force-leave/%s' % node)
658+
622659
class Service(object):
623660
def __init__(self, agent):
624661
self.agent = agent

0 commit comments

Comments
 (0)