diff --git a/etcd3gw/client.py b/etcd3gw/client.py index adbb41e..d403957 100644 --- a/etcd3gw/client.py +++ b/etcd3gw/client.py @@ -94,6 +94,15 @@ class Etcd3Client(object): return self.post(self.get_url("/maintenance/status"), 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): """Create a Lease object given a timeout diff --git a/etcd3gw/examples/etcd.py b/etcd3gw/examples/etcd.py index 198232f..47da17a 100644 --- a/etcd3gw/examples/etcd.py +++ b/etcd3gw/examples/etcd.py @@ -23,6 +23,9 @@ def main(): result = client.status() print("cluster id : %r" % result['header']['cluster_id']) + result = client.members() + print("first member info : %r" % result[0]) + print('>>>> Lease') lease = client.lease() print("Lease id : %r" % lease.id) diff --git a/etcd3gw/tests/test_etcd3gw.py b/etcd3gw/tests/test_etcd3gw.py index b258f92..fb5197a 100644 --- a/etcd3gw/tests/test_etcd3gw.py +++ b/etcd3gw/tests/test_etcd3gw.py @@ -51,6 +51,14 @@ class TestEtcd3Gateway(base.TestCase): self.assertIn('header', response) 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( _is_etcd3_running(), "etcd3 is not available") def test_client_with_keys_and_values(self):