diff --git a/influxdb/client.py b/influxdb/client.py index 37abdcf5..80f110ec 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -15,7 +15,8 @@ class InfluxDBClient(object): InfluxDB Client """ - def __init__(self, host, port, username, password, database): + def __init__(self, host='localhost', port=8086, username='root', + password='root', database=None): """ Initialize client """ @@ -243,6 +244,24 @@ def delete_database(self, database): raise Exception( "{0}: {1}".format(response.status_code, response.content)) + # ### get list of databases + # curl -X GET http://localhost:8086/db + + def get_database_list(self): + """ + Get the list of databases + """ + response = session.get("{0}/db?u={1}&p={2}".format( + self._baseurl, + self._username, + self._password)) + + if response.status_code == 200: + return json.loads(response.content) + else: + raise Exception( + "{0}: {1}".format(response.status_code, response.content)) + # Security # get list of cluster admins # curl http://localhost:8086/cluster_admins?u=root&p=root diff --git a/tests/influxdb/client_test.py b/tests/influxdb/client_test.py index 46ea5839..bb4824d4 100644 --- a/tests/influxdb/client_test.py +++ b/tests/influxdb/client_test.py @@ -143,6 +143,21 @@ def test_delete_database_fails(self): cli = InfluxDBClient('host', 8086, 'username', 'password', 'db') cli.delete_database('old_db') + def test_get_database_list(self): + with patch.object(session, 'get') as mocked_get: + mocked_get.return_value = _build_response_object( + status_code=200, content='[{"name": "a_db"}]') + cli = InfluxDBClient('host', 8086, 'username', 'password') + assert len(cli.get_database_list()) == 1 + assert cli.get_database_list()[0]['name'] == 'a_db' + + @raises(Exception) + def test_get_database_list_fails(self): + with patch.object(session, 'get') as mocked_get: + mocked_get.return_value = _build_response_object(status_code=401) + cli = InfluxDBClient('host', 8086, 'username', 'password') + cli.get_database_list() + def test_get_list_cluster_admins(self): pass pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy