0
# Legacy Support
1
2
Backward compatibility support for InfluxDB 0.8.x servers through dedicated client implementations. The `influxdb08` module provides complete API compatibility with older InfluxDB versions, enabling migration and support for legacy deployments.
3
4
## Package Information
5
6
The legacy module is included within the main influxdb package and provides dedicated classes for InfluxDB 0.8.x compatibility.
7
8
```python
9
from influxdb.influxdb08 import InfluxDBClient, DataFrameClient, SeriesHelper
10
```
11
12
## Capabilities
13
14
### Legacy InfluxDBClient
15
16
InfluxDB 0.8.x client with API methods specific to the older server version and data model.
17
18
```python { .api }
19
class InfluxDBClient:
20
"""
21
InfluxDB client for 0.8.x servers with legacy API support.
22
23
Note: This client uses different method signatures and data formats
24
compared to the modern InfluxDBClient for 1.x+ servers.
25
"""
26
27
def __init__(self, host='localhost', port=8086, username='root', password='root',
28
database=None, ssl=False, verify_ssl=False, timeout=None, use_udp=False,
29
udp_port=4444):
30
"""
31
Initialize legacy InfluxDB client.
32
33
Parameters:
34
- host (str): Hostname (default: 'localhost')
35
- port (int): Port number (default: 8086)
36
- username (str): Username (default: 'root')
37
- password (str): Password (default: 'root')
38
- database (str): Database name (default: None)
39
- ssl (bool): Use SSL (default: False)
40
- verify_ssl (bool): Verify SSL certificates (default: False)
41
- timeout (int): Request timeout (default: None)
42
- use_udp (bool): Use UDP (default: False)
43
- udp_port (int): UDP port (default: 4444)
44
"""
45
```
46
47
#### Legacy Database Operations
48
49
Database management operations specific to InfluxDB 0.8.x.
50
51
```python { .api }
52
def create_database(self, database):
53
"""
54
Create a new database in InfluxDB 0.8.x.
55
56
Parameters:
57
- database (str): Database name to create
58
59
Returns:
60
bool: True if successful
61
62
Raises:
63
InfluxDBClientError: If database creation fails
64
"""
65
66
def delete_database(self, database):
67
"""
68
Delete a database in InfluxDB 0.8.x.
69
70
Parameters:
71
- database (str): Database name to delete
72
73
Returns:
74
bool: True if successful
75
76
Raises:
77
InfluxDBClientError: If database deletion fails
78
"""
79
80
def get_list_database(self):
81
"""
82
Get list of databases in InfluxDB 0.8.x format.
83
84
Returns:
85
list: List of database information dictionaries
86
87
Raises:
88
InfluxDBClientError: If unable to retrieve databases
89
"""
90
```
91
92
#### Legacy Data Operations
93
94
Data querying and writing operations for InfluxDB 0.8.x data model.
95
96
```python { .api }
97
def write_points(self, *args, **kwargs):
98
"""
99
Write data points to InfluxDB 0.8.x.
100
101
Note: Uses different data format and parameters compared to 1.x+ client.
102
Consult InfluxDB 0.8.x documentation for specific format requirements.
103
104
Returns:
105
bool: True if successful
106
107
Raises:
108
InfluxDBClientError: If write operation fails
109
"""
110
111
def query(self, query, params=None, expected_response_code=200, database=None,
112
raise_errors=True):
113
"""
114
Execute query against InfluxDB 0.8.x server.
115
116
Parameters:
117
- query (str): InfluxQL query for 0.8.x
118
- params (dict): Query parameters (default: None)
119
- expected_response_code (int): Expected HTTP status (default: 200)
120
- database (str): Database name override (default: None)
121
- raise_errors (bool): Raise exceptions on errors (default: True)
122
123
Returns:
124
Results in InfluxDB 0.8.x format
125
126
Raises:
127
InfluxDBClientError: If query fails
128
"""
129
130
def delete_points(self, name):
131
"""
132
Delete points from a series in InfluxDB 0.8.x.
133
134
Parameters:
135
- name (str): Series name to delete points from
136
137
Returns:
138
bool: True if successful
139
140
Raises:
141
InfluxDBClientError: If deletion fails
142
"""
143
```
144
145
#### Legacy User Management
146
147
User and administrator management for InfluxDB 0.8.x.
148
149
```python { .api }
150
def add_cluster_admin(self, username, password):
151
"""
152
Add cluster administrator in InfluxDB 0.8.x.
153
154
Parameters:
155
- username (str): Admin username
156
- password (str): Admin password
157
158
Returns:
159
bool: True if successful
160
161
Raises:
162
InfluxDBClientError: If admin creation fails
163
"""
164
165
def delete_cluster_admin(self, username):
166
"""
167
Delete cluster administrator in InfluxDB 0.8.x.
168
169
Parameters:
170
- username (str): Admin username to delete
171
172
Returns:
173
bool: True if successful
174
175
Raises:
176
InfluxDBClientError: If admin deletion fails
177
"""
178
179
def get_list_cluster_admins(self):
180
"""
181
Get list of cluster administrators in InfluxDB 0.8.x.
182
183
Returns:
184
list: List of cluster administrator information
185
186
Raises:
187
InfluxDBClientError: If unable to retrieve admin list
188
"""
189
190
def set_database_admin_privilege(self, username, database, is_admin):
191
"""
192
Set database administrator privileges in InfluxDB 0.8.x.
193
194
Parameters:
195
- username (str): Username to modify
196
- database (str): Database name
197
- is_admin (bool): Grant or revoke admin privileges
198
199
Returns:
200
bool: True if successful
201
202
Raises:
203
InfluxDBClientError: If privilege modification fails
204
"""
205
```
206
207
#### Legacy Series Management
208
209
Series operations specific to InfluxDB 0.8.x data model.
210
211
```python { .api }
212
def get_list_series(self, database=None):
213
"""
214
Get list of series in InfluxDB 0.8.x format.
215
216
Parameters:
217
- database (str): Database name (default: current database)
218
219
Returns:
220
list: List of series in 0.8.x format
221
222
Raises:
223
InfluxDBClientError: If unable to retrieve series
224
"""
225
226
def delete_series(self, series):
227
"""
228
Delete a series in InfluxDB 0.8.x.
229
230
Parameters:
231
- series (str): Series name to delete
232
233
Returns:
234
bool: True if successful
235
236
Raises:
237
InfluxDBClientError: If series deletion fails
238
"""
239
```
240
241
#### Legacy Scheduled Operations
242
243
Scheduled operation management for InfluxDB 0.8.x.
244
245
```python { .api }
246
def create_scheduled_delete(self, delete_at, series_name):
247
"""
248
Create scheduled delete operation in InfluxDB 0.8.x.
249
250
Parameters:
251
- delete_at (str): When to execute the deletion
252
- series_name (str): Series name to delete
253
254
Returns:
255
bool: True if successful
256
257
Raises:
258
InfluxDBClientError: If scheduled delete creation fails
259
"""
260
261
def get_list_scheduled_delete(self):
262
"""
263
Get list of scheduled delete operations in InfluxDB 0.8.x.
264
265
Returns:
266
list: List of scheduled deletion information
267
268
Raises:
269
InfluxDBClientError: If unable to retrieve scheduled operations
270
"""
271
272
def remove_scheduled_delete(self, delete_id):
273
"""
274
Remove scheduled delete operation in InfluxDB 0.8.x.
275
276
Parameters:
277
- delete_id (int): ID of scheduled delete to remove
278
279
Returns:
280
bool: True if successful
281
282
Raises:
283
InfluxDBClientError: If scheduled delete removal fails
284
"""
285
```
286
287
### Legacy DataFrameClient
288
289
DataFrame integration for InfluxDB 0.8.x with pandas support.
290
291
```python { .api }
292
class DataFrameClient(InfluxDBClient):
293
"""
294
DataFrame client for InfluxDB 0.8.x with pandas integration.
295
296
Provides similar functionality to the modern DataFrameClient but
297
adapted for InfluxDB 0.8.x data formats and API.
298
"""
299
300
def write_points(self, dataframe, *args, **kwargs):
301
"""
302
Write pandas DataFrame to InfluxDB 0.8.x.
303
304
Note: Uses different parameters and data format compared to 1.x+ client.
305
Consult legacy documentation for specific usage.
306
307
Parameters:
308
- dataframe (pandas.DataFrame): Data to write
309
- *args, **kwargs: Legacy-specific parameters
310
311
Returns:
312
bool: True if successful
313
314
Raises:
315
InfluxDBClientError: If write fails
316
"""
317
318
def query(self, query, *args, **kwargs):
319
"""
320
Query InfluxDB 0.8.x and return results as DataFrame.
321
322
Parameters:
323
- query (str): InfluxQL query for 0.8.x
324
- *args, **kwargs: Legacy-specific parameters
325
326
Returns:
327
pandas.DataFrame: Query results
328
329
Raises:
330
InfluxDBClientError: If query fails
331
"""
332
```
333
334
### Legacy SeriesHelper
335
336
Bulk data operations helper for InfluxDB 0.8.x.
337
338
```python { .api }
339
class SeriesHelper:
340
"""
341
Series helper for bulk data operations in InfluxDB 0.8.x.
342
343
Provides similar functionality to the modern SeriesHelper but
344
adapted for InfluxDB 0.8.x data model and API requirements.
345
"""
346
347
def __init__(self, series_name, columns, points=None):
348
"""
349
Initialize legacy SeriesHelper.
350
351
Parameters:
352
- series_name (str): Name of the series
353
- columns (list): Column names for the series
354
- points (list): Initial data points (default: None)
355
"""
356
357
def add_point(self, point):
358
"""
359
Add a data point to the series.
360
361
Parameters:
362
- point (list): Data point values matching column order
363
"""
364
365
def commit(self, client):
366
"""
367
Commit all data points using the provided client.
368
369
Parameters:
370
- client (InfluxDBClient): Legacy client instance
371
372
Returns:
373
bool: True if successful
374
375
Raises:
376
InfluxDBClientError: If commit fails
377
"""
378
```
379
380
## Usage Examples
381
382
### Basic Legacy Client Usage
383
384
```python
385
from influxdb.influxdb08 import InfluxDBClient
386
from influxdb.exceptions import InfluxDBClientError
387
388
# Connect to InfluxDB 0.8.x server
389
legacy_client = InfluxDBClient(
390
host='legacy-influxdb.example.com',
391
port=8086,
392
username='admin',
393
password='admin'
394
)
395
396
try:
397
# Create database
398
legacy_client.create_database('legacy_metrics')
399
400
# List databases
401
databases = legacy_client.get_list_database()
402
print("Available databases:", databases)
403
404
# Switch to database
405
legacy_client.switch_database('legacy_metrics')
406
407
# Write data (0.8.x format)
408
# Note: Actual data format differs from 1.x+
409
legacy_client.write_points([
410
# 0.8.x specific data format
411
])
412
413
# Query data
414
result = legacy_client.query('list series')
415
416
except InfluxDBClientError as e:
417
print(f"Legacy client error: {e}")
418
```
419
420
### Legacy User Management
421
422
```python
423
# Admin operations for 0.8.x
424
try:
425
# Add cluster admin
426
legacy_client.add_cluster_admin('legacy_admin', 'admin_password')
427
428
# List cluster admins
429
admins = legacy_client.get_list_cluster_admins()
430
print("Cluster admins:", admins)
431
432
# Set database admin privileges
433
legacy_client.set_database_admin_privilege('user1', 'mydb', True)
434
435
# Clean up
436
legacy_client.delete_cluster_admin('old_admin')
437
438
except InfluxDBClientError as e:
439
print(f"Legacy admin operation failed: {e}")
440
```
441
442
### Legacy DataFrame Operations
443
444
```python
445
from influxdb.influxdb08 import DataFrameClient
446
import pandas as pd
447
448
# Legacy DataFrame client
449
legacy_df_client = DataFrameClient(
450
host='legacy-server.example.com',
451
database='legacy_data'
452
)
453
454
# Create DataFrame (adapt to 0.8.x requirements)
455
df = pd.DataFrame({
456
'time': pd.date_range('2023-09-07', periods=10, freq='1H'),
457
'value': range(10)
458
})
459
460
try:
461
# Write DataFrame (0.8.x format)
462
legacy_df_client.write_points(df, 'measurement_name')
463
464
# Query into DataFrame
465
result_df = legacy_df_client.query('select * from measurement_name')
466
print(result_df.head())
467
468
except Exception as e:
469
print(f"Legacy DataFrame operation failed: {e}")
470
```
471
472
### Legacy Series Helper
473
474
```python
475
from influxdb.influxdb08 import SeriesHelper
476
477
# Create series helper for 0.8.x
478
series_helper = SeriesHelper(
479
series_name='cpu_metrics',
480
columns=['time', 'host', 'cpu_usage']
481
)
482
483
# Add data points
484
series_helper.add_point(['2023-09-07T07:18:24Z', 'server01', 75.5])
485
series_helper.add_point(['2023-09-07T07:19:24Z', 'server01', 78.2])
486
487
# Commit to database
488
try:
489
series_helper.commit(legacy_client)
490
print("Legacy series data committed successfully")
491
except InfluxDBClientError as e:
492
print(f"Legacy series commit failed: {e}")
493
```
494
495
## Migration Considerations
496
497
### Upgrading from InfluxDB 0.8.x to 1.x+
498
499
When migrating from legacy InfluxDB 0.8.x to modern versions:
500
501
```python
502
# Legacy 0.8.x client
503
from influxdb.influxdb08 import InfluxDBClient as LegacyClient
504
505
# Modern 1.x+ client
506
from influxdb import InfluxDBClient as ModernClient
507
508
def migrate_data(legacy_host, modern_host, database):
509
"""Example migration helper."""
510
511
# Connect to both versions
512
legacy = LegacyClient(host=legacy_host, database=database)
513
modern = ModernClient(host=modern_host)
514
515
# Create database in modern InfluxDB
516
modern.create_database(database)
517
modern.switch_database(database)
518
519
try:
520
# Get data from legacy system
521
legacy_series = legacy.get_list_series()
522
523
for series in legacy_series:
524
# Query legacy data
525
legacy_data = legacy.query(f'select * from {series}')
526
527
# Transform data format (0.8.x to 1.x+)
528
modern_points = transform_legacy_data(legacy_data)
529
530
# Write to modern InfluxDB
531
modern.write_points(modern_points)
532
533
print(f"Migration completed for database: {database}")
534
535
except Exception as e:
536
print(f"Migration failed: {e}")
537
538
def transform_legacy_data(legacy_data):
539
"""Transform 0.8.x data format to 1.x+ format."""
540
# Implementation depends on specific data structure differences
541
# between 0.8.x and 1.x+ formats
542
modern_points = []
543
544
# Transform each legacy data point
545
for point in legacy_data:
546
modern_point = {
547
"measurement": point.get('series_name'),
548
"tags": extract_tags_from_legacy(point),
549
"fields": extract_fields_from_legacy(point),
550
"time": point.get('time')
551
}
552
modern_points.append(modern_point)
553
554
return modern_points
555
556
# Execute migration
557
migrate_data('legacy.example.com', 'modern.example.com', 'metrics')
558
```
559
560
### Compatibility Notes
561
562
- **Data Model**: InfluxDB 0.8.x uses a different data model (series-based) compared to 1.x+ (measurement/tag/field model)
563
- **Query Language**: InfluxQL syntax differences between versions
564
- **API Endpoints**: Different HTTP API endpoints and response formats
565
- **Authentication**: Different authentication mechanisms and user management
566
- **Performance**: 0.8.x has different performance characteristics and limitations
567
568
### Best Practices for Legacy Support
569
570
1. **Version Detection**: Detect InfluxDB version and use appropriate client
571
2. **Gradual Migration**: Plan phased migration from 0.8.x to modern versions
572
3. **Data Validation**: Validate data integrity during migration
573
4. **Testing**: Thoroughly test legacy compatibility in development environments
574
5. **Documentation**: Maintain separate documentation for legacy and modern APIs