英文版 | 中文版
OBShell-SDK-Python 是 OceanBase 社区 为了方便开发者快速使用 OBShell 服务而提供的 SDK,开发者可以使用该 SDK 便捷地调用 OBShell 的接口。
pip install obshell
使用时请确保 OBShell 处于运行状态。
创建指定版本的 client。
from obshell import ClientV1
from obshell.auth import PasswordAuth
def main():
client = ClientV1("11.11.11.1", 2886, PasswordAuth("****"))
创建 client_set。
from obshell import ClientSet
from obshell.auth import PasswordAuth
def main():
client = ClientSet("11.11.11.1", 2886, PasswordAuth("****"))
OBShell-SDK-Python 提供了两类方法来创建一个 OBShell 集群,一是向 OBShell 请求对应的 API 成功后,立刻返回,二是在向 OBShell 请求 API 成功后,等待 OBShell 任务执行完成后再返回。前者任务异步执行,后者任务同步执行。
部署一个 1-1-1 集群:
- 任务异步执行
from obshell import ClientSet
from obshell.auth import PasswordAuth
def main():
client = ClientSet("11.11.11.1", 2886, PasswordAuth("****"))
# join master
dag = client.v1.join("11.11.11.1", 2886, "zone1")
client.v1.wait_dag_succeed(dag.generic_id)
# join follower
dag = client.v1.join("11.11.11.2", 2886, "zone2")
client.v1.wait_dag_succeed(dag.generic_id)
dag = client.v1.join("11.11.11.3", 2886, "zone3")
client.v1.wait_dag_succeed(dag.generic_id)
# configure observer
configs = {
"datafile_size": "24G", "log_disk_size": "24G",
"cpu_count": "16", "memory_limit": "16G", "system_memory": "8G",
"enable_syslog_recycle": "true", "enable_syslog_wf": "true"}
dag = client.v1.config_observer(configs, "GLOBAL", [])
client.v1.wait_dag_succeed(dag.generic_id)
# configure obcluster
dag = client.v1.config_obcluster_sync("test-sdk", 11, "****")
client.v1.wait_dag_succeed(dag.generic_id)
# initialize obcluster
dag = client.v1.init_sync()
client.v1.wait_dag_succeed(dag.generic_id)
# get the status of the cluster
status = client.v1.get_status()
print(status)
- 任务同步执行
from obshell import ClientSet
from obshell.auth import PasswordAuth
def main():
client = ClientSet("11.11.11.1", 2886, PasswordAuth("****"))
# join master
client.v1.join_sync("11.11.11.1", 2886, "zone1")
# join follower
client.v1.join_sync("11.11.11.2", 2886, "zone2")
client.v1.join_sync("11.11.11.3", 2886, "zone3")
# configure observer
configs = {
"datafile_size": "24G", "log_disk_size": "24G",
"cpu_count": "16", "memory_limit": "16G", "system_memory": "8G",
"enable_syslog_recycle": "true", "enable_syslog_wf": "true"}
client.v1.config_observer_sync(configs, "GLOBAL", [])
# configure obcluster
client.v1.config_obcluster_sync("test-sdk", 11, "****")
# initialize obcluster
client.v1.init_sync()
# get the status of the cluster
status = client.v1.get_status()
print(status)
将节点 '11.11.11.4' 扩容到节点 '11.11.11.1' 所在的集群中。
from obshell.service.client_set import ClientSet
from obshell.sdk.auth.password import PasswordAuth
def main():
client = ClientSet("111.11.11.1", 2886, PasswordAuth("****"))
# scale out
configs = {
"datafile_size": "24G", "log_disk_size": "24G",
"cpu_count": "16", "memory_limit": "16G", "system_memory": "8G",
"enable_syslog_recycle": "true", "enable_syslog_wf": "true"}
client.v1.scale_out_sync("11.11.11.4", 2886, "zone3", configs)