Skip to content

Commit

Permalink
Merge pull request #3 from derpston/master
Browse files Browse the repository at this point in the history
Add support for the 'members' command, other small fixes
  • Loading branch information
KushalP committed Apr 6, 2014
2 parents 145abba + 1b52251 commit 35e1d85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions serfclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def event(self, name, payload=None, coalesce=True):
'event',
{'Name': name, 'Payload': payload, 'Coalesce': coalesce})

def members(self):
"""
Lists members of a Serf cluster.
"""
return self.connection.call('members')

def force_leave(self, name):
"""
Force a node to leave the cluster.
Expand Down
8 changes: 3 additions & 5 deletions serfclient/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import msgpack

from io import BytesIO
try:
from serfclient.result import SerfResult
except ImportError:
Expand Down Expand Up @@ -49,12 +48,11 @@ def call(self, command, params=None):
else:
self._socket.sendall(header)

buf = BytesIO()
buf.write(self._socket.recv(4096))
buf.seek(0)
unpacker = msgpack.Unpacker()
unpacker.feed(self._socket.recv(4096))

response = SerfResult()
for item in msgpack.Unpacker(buf):
for item in unpacker:
if response.head is None:
response.head = item
else:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ def test_providing_a_single_value_should_put_it_inside_a_list(self, serf):
assert join.head == {b'Error': b'Reading remote state failed: EOF',
b'Seq': 1}
assert join.body == {b'Num': 0}

def test_member_list_is_not_empty(self, serf):
members = serf.members()
assert len(members.body[b'Members']) > 0

0 comments on commit 35e1d85

Please sign in to comment.