-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Oreoxmt/tidbcloudy/020
tidbcloudy v0.2.0
- Loading branch information
Showing
15 changed files
with
1,737 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
[tool.poetry] | ||
name = "tidbcloudy" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
description = "" | ||
authors = ["Aolin <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.6" | ||
python = "^3.7" | ||
requests = "^2.27.1" | ||
mysqlclient = "^2.1.1" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^5.2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
__version__ = '0.1.0' | ||
from tidbcloudy.tidbcloud import TiDBCloud | ||
from tidbcloudy.context import Context | ||
from tidbcloudy.project import Project | ||
from tidbcloudy.cluster import Cluster | ||
from tidbcloudy.backup import Backup | ||
from tidbcloudy.restore import Restore | ||
from tidbcloudy.exception import TiDBCloudException | ||
from tidbcloudy.util.log import log | ||
from tidbcloudy.util.timestamp import timestamp_to_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from tidbcloudy.specification import BackupType, BackupStatus | ||
from tidbcloudy.context import Context | ||
from tidbcloudy.util.log import log | ||
|
||
|
||
# noinspection PyShadowingBuiltins | ||
class Backup: | ||
def __init__(self, | ||
context: Context, | ||
id: str = None, | ||
*, | ||
cluster_id: str = None, | ||
project_id: str = None, | ||
name: str = None, | ||
description: str = None, | ||
type: BackupType = None, | ||
create_timestamp: str = None, | ||
size: str = None, | ||
status: BackupStatus = None, | ||
_from: str = None | ||
): | ||
""" | ||
Args: | ||
id: the id of the backup | ||
cluster_id: the id of the cluster | ||
name: the name of the backup | ||
description: the description of the backup | ||
type: the type of the backup | ||
create_timestamp: the created timestamp of the backup | ||
size: the size of the backup | ||
status: the status of the backup | ||
_from: internal use only | ||
""" | ||
self._context = context | ||
self._from = _from | ||
if self._from is None: | ||
if id is None: | ||
raise TypeError("id") | ||
if cluster_id is None: | ||
raise TypeError("cluster_id") | ||
elif self._from == "create": | ||
# When init a backup instance from create_backup endpoint, the id and cluster_id is required | ||
if id is None: | ||
raise TypeError("id") | ||
if cluster_id is None: | ||
raise TypeError("cluster_id") | ||
elif self._from == "object": | ||
pass | ||
else: | ||
raise ValueError("_from") | ||
self._id = id | ||
self._cluster_id = cluster_id | ||
self._project_id = project_id | ||
self._name = name | ||
self._description = description | ||
self._type = type | ||
self._create_timestamp = create_timestamp | ||
self._size = size | ||
self._status = status | ||
|
||
def assign_object(self, obj: dict): | ||
self._id = obj["id"] | ||
self._cluster_id = obj["cluster_id"] | ||
self._project_id = obj["project_id"] | ||
self._name = obj["name"] | ||
self._description = obj["description"] | ||
self._type = obj["type"] | ||
self._create_timestamp = obj["create_timestamp"] | ||
self._size = obj["size"] | ||
self._status = obj["status"] | ||
|
||
@classmethod | ||
def from_object(cls, context: Context, obj: dict): | ||
new_backup = cls( | ||
context=context, | ||
_from="object" | ||
) | ||
new_backup.assign_object(obj) | ||
return new_backup | ||
|
||
def delete(self): | ||
path = "projects/{}/clusters/{}/backups/{}".format(self._project_id, self._cluster_id, self._id) | ||
self._context.call_delete(path=path) | ||
log("backup task id={} has been deleted".format(self._id)) | ||
|
||
def __repr__(self): | ||
return "<backup id={} name={} create_at= {}>".format(self._id, self._name, self._create_timestamp) |
Oops, something went wrong.