Skip to content

Commit

Permalink
Added methods to add/remove etcd cluster members
Browse files Browse the repository at this point in the history
  • Loading branch information
r0p0s3c committed Dec 10, 2016
1 parent 0d0145f commit b2e486e
Showing 1 changed file with 30 additions and 1 deletion.
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

0 comments on commit b2e486e

Please sign in to comment.