Skip to content

Commit

Permalink
Merge pull request #1 from Oreoxmt/tidbcloudy/020
Browse files Browse the repository at this point in the history
tidbcloudy v0.2.0
  • Loading branch information
Oreoxmt authored Aug 14, 2022
2 parents 0f75881 + ffe5d85 commit 2d940eb
Show file tree
Hide file tree
Showing 15 changed files with 1,737 additions and 43 deletions.
97 changes: 57 additions & 40 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
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"
Expand Down
10 changes: 9 additions & 1 deletion tidbcloudy/__init__.py
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
87 changes: 87 additions & 0 deletions tidbcloudy/backup.py
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)
Loading

0 comments on commit 2d940eb

Please sign in to comment.