Skip to content

Commit

Permalink
Merge pull request #18 from Oreoxmt/release/v1.0.5
Browse files Browse the repository at this point in the history
- Support TiDB Cloud API [Release 20230602](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230602): rename "Serverless Tier" to "TiDB Serverless" and "Dedicated Tier" to "TiDB Dedicated"
- Support TiDB Cloud API [Release 20230801](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230801): add cluster status: MAINTAINING and PAUSING
- Improvements:
    - Decrease the `interval_sec` when creating a TiDB Serverless cluster
    - Remove the `add_ip_access` and `add_current_ip_access` config in README: they are ignored when creating a TiDB Serverless cluster
    - Use raise_for_status instead of status_code to get the current IP address
    - Use HTTPS to get the current IP address
- Bug fixes:
    - Fix the issue that `AttributeError: 'NoneType' object has no attribute 'cluster_status'` error is reported when running `examples/2_1_create_serverless_cluster.py`
  • Loading branch information
Oreoxmt authored Oct 2, 2023
2 parents f1edbd0 + cf4ffed commit 9a5f88b
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 257 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ You can use this SDK to access [TiDB Cloud](https://tidbcloud.com) and manage yo

- manage your TiDB Cloud **projects** (only _list_ is supported now)
- list all available cloud providers (AWS and GCP), regions and specifications before creating or modifying a cluster
- manage your Serverless Tier or Dedicated Tier **clusters** (_create_, _modify_, _pause_, _resume_, _get_, _list_, _delete_)
- manage your TiDB Serverless or TiDB Dedicated **clusters** (_create_, _modify_, _pause_, _resume_, _get_, _list_, _delete_)
- manage your **backups** of a cluster (_create_, _get_, _list_, _delete_)
- manage your **restores** of a project (_create_, _get_, _list_)

### Compatibility with TiDB Cloud API

`tidbcloudy` is compatible with [TiDB Cloud API](https://docs.pingcap.com/tidbcloud/api/v1beta). **Endpoints added in [Release 20230228](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230228) and [Release 20230328](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230328) are not supported for now**. The following table lists the supported API versions:

| tidbcloudy | TiDB Cloud API |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [1.0.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.1), [1.0.2](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.2), [1.0.3](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.3) | v1beta [Release 20220906](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220906), [Release 20220920](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220920), [Release 20221028](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20221028), [Release 20230104](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230104), [Release 20230214](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230214), [Release 20230321](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230321)|
| tidbcloudy | TiDB Cloud API |
|---|---|
| [1.0.5](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.5) | v1beta [Release 20230602](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230602), [Release 20230801](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230801) |
| [1.0.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.1), [1.0.2](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.2), [1.0.3](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.3), [1.0.4](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.4) | v1beta [Release 20220906](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220906), [Release 20220920](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220920), [Release 20221028](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20221028), [Release 20230104](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230104), [Release 20230214](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230214), [Release 20230321](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230321) |
| [1.0.0](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.0) | v1beta [Release 20220823](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220823) |
| [0.2.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v0.2.1) | v1beta [Release 20220809](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220809) | |
| [0.2.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v0.2.1) | v1beta [Release 20220809](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220809) |

### Enhancements comparing to original [TiDB Cloud API](https://docs.pingcap.com/tidbcloud/api/v1beta)

Expand Down Expand Up @@ -150,11 +151,11 @@ for spec in api.list_provider_regions():
>
> Creating a cluster might cost money. For more details, see [TiDB Cloud pricing details](https://www.pingcap.com/tidb-cloud-pricing-details).
To create a Serverless Tier cluster, run the [`2_1_create_serverless_cluster.py`](https://github.com/Oreoxmt/tidbcloudy/tree/main/examples/2_1_create_serverless_cluster.py).
To create a TiDB Serverless cluster, run the [`2_1_create_serverless_cluster.py`](https://github.com/Oreoxmt/tidbcloudy/tree/main/examples/2_1_create_serverless_cluster.py).
To create a Dedicated Tier cluster, run the [`2_2_create_dedicated_cluster.py`](https://github.com/Oreoxmt/tidbcloudy/tree/main/examples/2_2_create_dedicated_cluster.py).
To create a TiDB Dedicated cluster, run the [`2_2_create_dedicated_cluster.py`](https://github.com/Oreoxmt/tidbcloudy/tree/main/examples/2_2_create_dedicated_cluster.py).
The following takes creating a Serverless Tier cluster as an example:
The following takes creating a TiDB Serverless cluster as an example:
```python
import os
Expand All @@ -175,13 +176,12 @@ config\
.set_cluster_type("DEVELOPER") \
.set_cloud_provider("AWS") \
.set_region("us-west-2") \
.set_root_password("your_root_password") \
.add_ip_access(cidr="0.0.0.0/0") \
.add_current_ip_access()
.set_root_password("your_root_password")
cluster = project.create_cluster(config)
print(cluster)
cluster.wait_for_available()
cluster.wait_for_available(interval_sec=1)
print(cluster)
```
### Connect to TiDB
Expand Down
7 changes: 4 additions & 3 deletions examples/2_1_create_serverless_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
project_id = "1372813089206751385"

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)

config = CreateClusterConfig()
config\
.set_name("serverless-0") \
.set_name("serverless-test") \
.set_cluster_type("DEVELOPER") \
.set_cloud_provider("AWS") \
.set_region("us-west-2") \
Expand All @@ -23,4 +23,5 @@
cluster = project.create_cluster(config)
print(cluster)

cluster.wait_for_available()
cluster.wait_for_available(interval_sec=1)
print(cluster)
6 changes: 3 additions & 3 deletions examples/2_2_create_dedicated_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
project_id = "1372813089206751385"

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand All @@ -19,8 +19,8 @@
.set_region("us-west-2") \
.set_port(4399) \
.set_root_password("your_root_password") \
.set_component("tidb", "8C16G", 1) \
.set_component("tikv", "8C32G", 3, 500) \
.set_component("tidb", "4C16G", 1) \
.set_component("tikv", "4C16G", 3, 200) \
.add_current_ip_access()
cluster = project.create_cluster(config)
print(cluster)
Expand Down
6 changes: 3 additions & 3 deletions examples/3_connect_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = "1372813089206751385"
cluster_id = "10912822641423447137"

print("Connecting to TiDB Cloud...")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
Expand All @@ -17,7 +17,7 @@

if cluster.status.cluster_status == ClusterStatus.AVAILABLE:
connection_strings = cluster.status.connection_strings
connection = cluster.connect(type="standard", database="test", password="your_root_password")
connection = cluster.connect(type="standard", database="test", password="xQXacEZAoomvb9BN")
print(connection)
with connection:
with connection.cursor() as cursor:
Expand Down
4 changes: 2 additions & 2 deletions examples/6_pause_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = "1372813089206751385"
cluster_id = "1379661944646412338"

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
Loading

0 comments on commit 9a5f88b

Please sign in to comment.