@@ -30,10 +30,17 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
30
30
:param str, Organization org: specifies the organization for create the bucket;
31
31
Take the ``ID``, ``Name`` or ``Organization``.
32
32
If not specified the default value from ``InfluxDBClient.org`` is used.
33
- :return: Bucket or the request thread when falling back.
33
+ :return: Bucket
34
34
If the method is called asynchronously,
35
- returns also the request thread.
35
+ returns the request thread.
36
36
"""
37
+ if self ._buckets_service ._is_below_v2 ():
38
+ # Fall back to v1 API if buckets are not supported
39
+ warnings .warn ("InfluxDB versions below v2.0 are deprecated. " + \
40
+ "Falling back to CREATE DATABASE statement" , DeprecationWarning )
41
+ database_name = bucket_name if bucket_name is not None else bucket
42
+ return self ._create_database (database = database_name )
43
+
37
44
if retention_rules is None :
38
45
retention_rules = []
39
46
@@ -55,19 +62,13 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
55
62
client = self ._influxdb_client ,
56
63
required_id = True ))
57
64
58
- try :
59
- return self ._buckets_service .post_buckets (post_bucket_request = bucket )
60
- except ApiException :
61
- # Fall back to v1 API if buckets are not supported
62
- database_name = bucket_name if bucket_name is not None else bucket
63
- return self .create_database (database = database_name , retention_rules = retention_rules )
65
+ return self ._buckets_service .post_buckets (post_bucket_request = bucket )
64
66
65
- def create_database (self , database = None , retention_rules = None ):
67
+ def _create_database (self , database = None ):
66
68
"""Create a database at the v1 api (legacy).
67
69
68
70
:param database_name: name of the new database
69
- :param retention_rules: retention rules array or single BucketRetentionRules
70
- :return: Tuple (response body, status code, header dict)
71
+ :return: tuple(response body, status code, header dict)
71
72
"""
72
73
if database is None :
73
74
raise ValueError ("Invalid value for `database`, must be defined." )
@@ -114,24 +115,26 @@ def delete_bucket(self, bucket):
114
115
"""Delete a bucket. Delete a database via v1 API as fallback.
115
116
116
117
:param bucket: bucket id or Bucket
117
- :return: Bucket or the request thread when falling back
118
+ :return: Bucket
118
119
"""
119
120
if isinstance (bucket , Bucket ):
120
121
bucket_id = bucket .id
121
122
else :
122
123
bucket_id = bucket
123
124
124
- try :
125
- return self ._buckets_service .delete_buckets_id (bucket_id = bucket_id )
126
- except ApiException :
127
- return self .delete_database (database = bucket_id )
125
+ if self ._buckets_service ._is_below_v2 ():
126
+ # Fall back to v1 API if buckets are not supported
127
+ warnings .warn ("InfluxDB versions below v2.0 are deprecated. " + \
128
+ "Falling back to DROP DATABASE statement" , DeprecationWarning )
129
+ return self ._delete_database (database = bucket_id )
128
130
129
- def delete_database (self , database = None ):
131
+ return self ._buckets_service .delete_buckets_id (bucket_id = bucket_id )
132
+
133
+ def _delete_database (self , database = None ):
130
134
"""Delete a database at the v1 api (legacy).
131
135
132
136
:param database_name: name of the database to delete
133
- :param retention_rules: retention rules array or single BucketRetentionRules
134
- :return: Tuple (response body, status code, header dict)
137
+ :return: tuple(response body, status code, header dict)
135
138
"""
136
139
if database is None :
137
140
raise ValueError ("Invalid value for `database`, must be defined." )
0 commit comments