Support for listing members

This commit is contained in:
Davanum Srinivas 2017-03-30 10:48:47 -04:00
parent ec4180e1a4
commit 4aa5968cb8
3 changed files with 20 additions and 0 deletions

View File

@ -94,6 +94,15 @@ class Etcd3Client(object):
return self.post(self.get_url("/maintenance/status"), return self.post(self.get_url("/maintenance/status"),
json={}) json={})
def members(self):
"""Lists all the members in the cluster.
:return: json response
"""
result = self.post(self.get_url("/cluster/member/list"),
json={})
return result['members']
def lease(self, ttl=DEFAULT_TIMEOUT): def lease(self, ttl=DEFAULT_TIMEOUT):
"""Create a Lease object given a timeout """Create a Lease object given a timeout

View File

@ -23,6 +23,9 @@ def main():
result = client.status() result = client.status()
print("cluster id : %r" % result['header']['cluster_id']) print("cluster id : %r" % result['header']['cluster_id'])
result = client.members()
print("first member info : %r" % result[0])
print('>>>> Lease') print('>>>> Lease')
lease = client.lease() lease = client.lease()
print("Lease id : %r" % lease.id) print("Lease id : %r" % lease.id)

View File

@ -51,6 +51,14 @@ class TestEtcd3Gateway(base.TestCase):
self.assertIn('header', response) self.assertIn('header', response)
self.assertIn('cluster_id', response['header']) self.assertIn('cluster_id', response['header'])
@unittest.skipUnless(
_is_etcd3_running(), "etcd3 is not available")
def test_client_members(self):
response = self.client.members()
self.assertTrue(len(response) > 0)
self.assertIn('clientURLs', response[0])
self.assertIn('peerURLs', response[0])
@unittest.skipUnless( @unittest.skipUnless(
_is_etcd3_running(), "etcd3 is not available") _is_etcd3_running(), "etcd3 is not available")
def test_client_with_keys_and_values(self): def test_client_with_keys_and_values(self):