Skip to content

Commit 64a401e

Browse files
authored
chore: update to the latest swagger API, add an example "How to use Templates and Stack API" (influxdata#399)
1 parent 1380242 commit 64a401e

File tree

366 files changed

+19772
-2336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

366 files changed

+19772
-2336
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
## 1.26.0 [unreleased]
22

3+
### Breaking Changes
4+
5+
This release introduces a support for new version of InfluxDB OSS API definitions - [oss.yml](https://github.com/influxdata/openapi/blob/master/contracts/oss.yml). The following breaking changes are in underlying API services and doesn't affect common apis such as - `WriteApi`, `QueryApi`, `BucketsApi`, `OrganizationsApi`...
6+
- Add `LegacyAuthorizationsService` to deal with legacy authorizations
7+
- Add `ResourceService` to retrieve all knows resources
8+
- Add `BackupService` to represents the data backup functions of InfluxDB
9+
- Add `ReplicationsService` to represents the replication functions of InfluxDB
10+
- Add `RestoreService` to represents the data restore functions of InfluxDB
11+
- Add `ConfigService` to retrieve InfluxDB's runtime configuration
12+
- Add `RemoteConnectionsService` to deal with registered remote InfluxDB connections
13+
- Add `TelegrafPluginsService` to retrieve all Telegraf's plugins
14+
- Update `TemplatesService` to deal with `Stack` and `Template` API
15+
- `DBRPsService`:
16+
- doesn't requires `org_id` parameter for operations
17+
- `get_dbr_ps_id` operation uses `DBRPGet` as a type of result
18+
- `patch_dbrpid` operation uses `DBRPGet` as a type of result
19+
- `post_dbrp` operation uses `DBRPCreate` as a type of request
20+
- `DefaultService`:
21+
- `get_routes` operation is moved to `RoutesService`
22+
- `get_telegraf_plugin` operation is moved to `TelegrafsService`
23+
- `post_signin` operation is moved to `SigninService`
24+
- `post_signout` operation is moved to `SignoutService`
25+
- `OrganizationsService`:
26+
- `get_orgs_id_secrets` operation is moved to `SecretsService`
27+
- `patch_orgs_id_secrets` operation is moved to `SecretsService`
28+
- `post_orgs_id_secrets` operation is moved to `SecretsService`
29+
- Remove `DocumentApi` in favour of [InfluxDB Community Templates](https://github.com/influxdata/community-templates). For more info see - [influxdb#19300](https://github.com/influxdata/influxdb/pull/19300), [openapi#192](https://github.com/influxdata/openapi/pull/192)
30+
- `TelegrafsService` uses `TelegrafPluginRequest` to create `Telegraf` configuration
31+
- `TelegrafsService` uses `TelegrafPluginRequest` to update `Telegraf` configuration
32+
33+
### API
34+
1. [#399](https://github.com/influxdata/influxdb-client-python/pull/399): Use the latest InfluxDB OSS API definitions to generated APIs
35+
336
## 1.25.0 [2022-01-20]
437

538
### Features

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [buckets_management.py](buckets_management.py) - How to create, list and delete Buckets
2222
- [monitoring_and_alerting.py](monitoring_and_alerting.py) - How to create the Check with Slack notification.
2323
- [task_example.py](task_example.py) - How to create a Task by API
24+
- [templates_management.py](templates_management.py) - How to use Templates and Stack API
2425

2526
## Others
2627
- [influx_cloud.py](influx_cloud.py) - How to connect to InfluxDB 2 Cloud

examples/templates_management.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
How to use Templates and Stack API.
3+
"""
4+
import datetime
5+
6+
from influxdb_client import InfluxDBClient, TemplatesService, TemplateApply, TemplateApplyRemotes, PatchStackRequest, \
7+
TemplateApplyTemplate
8+
9+
"""
10+
Define credentials
11+
"""
12+
url = 'http://localhost:8086'
13+
token = 'my-token'
14+
bucket_name = 'my-bucket'
15+
org_name = 'my-org'
16+
17+
with InfluxDBClient(url=url, token=token, org=org_name, debug=True) as client:
18+
uniqueId = str(datetime.datetime.now())
19+
"""
20+
Find Organization ID by Organization API.
21+
"""
22+
org = client.organizations_api().find_organizations(org=org_name)[0]
23+
24+
"""
25+
Initialize Template service
26+
"""
27+
templates_service = TemplatesService(api_client=client.api_client)
28+
29+
"""
30+
Apply 'Linux System Monitoring Template'
31+
"""
32+
template_yaml_url = "https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml" # noqa: E501
33+
template_linux = templates_service.apply_template(
34+
template_apply=TemplateApply(dry_run=False,
35+
org_id=org.id,
36+
remotes=[TemplateApplyRemotes(url=template_yaml_url)]))
37+
"""
38+
Set Stack name
39+
"""
40+
templates_service.update_stack(stack_id=template_linux.stack_id,
41+
patch_stack_request=PatchStackRequest(name="linux_system"))
42+
43+
"""
44+
Create template as an inline definition
45+
"""
46+
template_definition = {
47+
"apiVersion": "influxdata.com/v2alpha1",
48+
"kind": "Bucket",
49+
"metadata": {"name": "template-bucket"},
50+
"spec": {"description": "bucket 1 description"}
51+
}
52+
template_inline = templates_service.apply_template(
53+
template_apply=TemplateApply(dry_run=False,
54+
org_id=org.id,
55+
template=TemplateApplyTemplate(content_type="json",
56+
contents=[template_definition])))
57+
"""
58+
Set Stack name
59+
"""
60+
templates_service.update_stack(stack_id=template_inline.stack_id,
61+
patch_stack_request=PatchStackRequest(name="inline_stack"))
62+
63+
"""
64+
List installed stacks
65+
"""
66+
print(f"\n------- List -------\n")
67+
stacks = templates_service.list_stacks(org_id=org.id).stacks
68+
print("\n".join([f" ---\n ID: {it.id}\n Stack: {it}" for it in stacks]))
69+
print("---")
70+
71+
"""
72+
Delete previously created Stack
73+
"""
74+
print(f"------- Delete -------\n")
75+
templates_service.delete_stack(stack_id=template_linux.stack_id, org_id=org.id)
76+
print(f" Successfully deleted stack: '{template_linux.stack_id}'")

0 commit comments

Comments
 (0)
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