diff --git a/influxdb/client.py b/influxdb/client.py index 683e0bcb..e9e015df 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -592,6 +592,25 @@ def get_list_series(self, database=None): ) return series + def get_list_servers(self): + """Get the list of servers in InfluxDB cluster. + + :returns: all nodes in InfluxDB cluster + :rtype: list of dictionaries + + :Example: + + :: + + >> servers = client.get_list_servers() + >> servers + [{'cluster_addr': 'server01:8088', + 'id': 1, + 'raft': True, + 'raft-leader': True}] + """ + return list(self.query("SHOW SERVERS").get_points()) + def get_list_users(self): """Get the list of all users in InfluxDB. diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index dc4ab306..ebe140a7 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -485,6 +485,39 @@ def test_get_list_database_fails(self): with _mocked_session(cli, 'get', 401): cli.get_list_database() + def test_get_list_servers(self): + data = {'results': [ + {'series': [ + {'columns': ['id', 'cluster_addr', 'raft', 'raft-leader'], + 'values': [ + [1, 'server01:8088', True, True], + [2, 'server02:8088', True, False], + [3, 'server03:8088', True, False]]}]} + ]} + + with _mocked_session(self.cli, 'get', 200, json.dumps(data)): + self.assertListEqual( + self.cli.get_list_servers(), + [{'cluster_addr': 'server01:8088', + 'id': 1, + 'raft': True, + 'raft-leader': True}, + {'cluster_addr': 'server02:8088', + 'id': 2, + 'raft': True, + 'raft-leader': False}, + {'cluster_addr': 'server03:8088', + 'id': 3, + 'raft': True, + 'raft-leader': False}] + ) + + @raises(Exception) + def test_get_list_servers_fails(self): + cli = InfluxDBClient('host', 8086, 'username', 'password') + with _mocked_session(cli, 'get', 401): + cli.get_list_servers() + def test_get_list_series(self): example_response = \ '{"results": [{"series": [{"name": "cpu_load_short", "columns": ' \
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: