Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods to add/remove etcd cluster members #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/etcd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,35 @@ def leader(self):
except Exception as e:
raise etcd.EtcdException("Cannot get leader data: %s" % e)

def addmember(self, memberuri):
"""
add a member to the cluster

Args:
memberuri (str): new member's address as a uri

Returns:
dict with id and peerURLs as documented at https://coreos.com/etcd/docs/latest/v2/members_api.html#add-a-member

"""
try:
return self.api_execute_json(self.version_prefix + '/members', self._MPOST, {"peerURLs":[memberuri]}).data.decode('utf-8')
except Exception as e:
raise etcd.EtcdException("Cannot add member: %s" % e)

def deletemember(self, memberid):
"""
add a member to the cluster

Args:
memberid (str): member id to delete

"""
try:
self.api_execute(self.version_prefix + '/members/%s'%memberid, self._MDELETE)
except Exception as e:
raise etcd.EtcdException("Cannot delete member: %s" % e)

@property
def stats(self):
"""
Expand Down Expand Up @@ -937,7 +966,7 @@ def _check_cluster_id(self, response):

def _handle_server_response(self, response):
""" Handles the server response """
if response.status in [200, 201]:
if response.status in [200, 201, 204]:
return response

else:
Expand Down