Skip to content

Commit d4e0cea

Browse files
committed
PullRequest: 25 feat: add param of import script from init and create tenant
Merge branch import_script of [email protected]:oceanbase/OBShell-SDK-Python.git into master https://code.alipay.com/oceanbase/OBShell-SDK-Python/pull_requests/25?tab=comment Signed-off-by: 玉楼 <[email protected]> * feat: add param of import script from init and create tenant * chore: optz the comment for import_script
1 parent d4d0a63 commit d4e0cea

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

obshell/service/client_v1.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,29 @@ def config_obcluster_sync(self,
364364
self._set_password_candidate_auth(root_pwd)
365365
return self.wait_dag_succeed(dag.generic_id)
366366

367-
def init(self) -> task.DagDetailDTO:
367+
def init(self, import_script=False) -> task.DagDetailDTO:
368368
"""Initializes the cluster.
369369
370370
Return as soon as request successfully.
371371
You can use wait_dag_succeed to wait for the init task to succeed or
372372
use init_sync to initialize synchronously instead.
373373
374+
Args:
375+
import_script (bool, optional):
376+
Whether need to import the observer's script. Defaults to False.
377+
Support from OBShell V4.2.4.2.
378+
374379
Returns:
375380
Task detail as task.DagDetailDTO.
376381
377382
Raises:
378383
OBShellHandleError: error message return by OBShell server.
379384
"""
380-
req = self.create_request("/api/v1/ob/init", "POST")
385+
req = self.create_request(
386+
"/api/v1/ob/init", "POST", data={"import_script": import_script})
381387
return self.__handle_task_ret_request(req)
382388

383-
def init_sync(self) -> task.DagDetailDTO:
389+
def init_sync(self, import_script=False) -> task.DagDetailDTO:
384390
"""Initializes the cluster synchronously.
385391
386392
Seealso init.
@@ -391,7 +397,7 @@ def init_sync(self) -> task.DagDetailDTO:
391397
TaskExecuteFailedError: raise when the task failed,
392398
include the failed task detail and logs.
393399
"""
394-
dag = self.init()
400+
dag = self.init(import_script)
395401
return self.wait_dag_succeed(dag.generic_id)
396402

397403
def start(self, level: str, target: list, force_pass_dag=None) -> task.DagDetailDTO:
@@ -1023,7 +1029,8 @@ def get_resource_unit_config(self, unit_config_name: str) -> unit.UnitConfig:
10231029

10241030
def create_tenant(
10251031
self, tenant_name: str, zone_list: List[tenant.ZoneParam], mode: str = 'MYSQL', primary_zone: str = None, whitelist: str = None,
1026-
root_password: str = None, scenario: str = None, charset: str = None, collation: str = None, read_only: bool = False,
1032+
root_password: str = None, scenario: str = None, import_script: bool = False,
1033+
charset: str = None, collation: str = None, read_only: bool = False,
10271034
comment: str = None, variables: dict = None, parameters: dict = None) -> task.DagDetailDTO:
10281035
"""Creates a tenant.
10291036
@@ -1042,7 +1049,8 @@ def create_tenant(
10421049
"zone_list": [zone.__dict__ for zone in zone_list],
10431050
}
10441051
options = ['mode', 'primary_zone', 'whitelist', 'root_password', 'charset',
1045-
'collation', 'read_only', 'comment', 'variables', 'parameters', 'scenario']
1052+
"import_script", 'collation', 'read_only', 'comment', 'variables',
1053+
'parameters', 'scenario']
10461054
mydict = locals()
10471055
for k, v in mydict.items():
10481056
if k in options and v is not None:
@@ -1052,8 +1060,8 @@ def create_tenant(
10521060

10531061
def create_tenant_sync(
10541062
self, tenant_name: str, zone_list: List[tenant.ZoneParam], mode: str = 'MYSQL',
1055-
primary_zone: str = "RANDOM", whitelist: str = None, root_password: str = None,
1056-
scenario: str = None,
1063+
primary_zone: str = "RANDOM", whitelist: str = None,
1064+
root_password: str = None, scenario: str = None, import_script: bool = False,
10571065
charset: str = None, collation: str = None, read_only: bool = False,
10581066
comment: str = None, variables: dict = None, parameters: dict = None) -> task.DagDetailDTO:
10591067
"""Create a tenant synchronously.
@@ -1076,6 +1084,9 @@ def create_tenant_sync(
10761084
Defaults to 'oltp'.
10771085
root_password (str, optional):
10781086
The root password of the tenant. Defaults to Empty.
1087+
import_script (bool, optional):
1088+
Whether need to import the observer's script. Defaults to False.
1089+
Support from OBShell V4.2.4.2.
10791090
charset (str, optional): The charset of the tenant.
10801091
If not set, the charset will be set to default value by observer.
10811092
collation (str, optional): The collation of the tenant.
@@ -1095,7 +1106,8 @@ def create_tenant_sync(
10951106
include the failed task detail and logs.
10961107
"""
10971108
dag = self.create_tenant(
1098-
tenant_name, zone_list, mode, primary_zone, whitelist, root_password, scenario, charset, collation, read_only, comment, variables, parameters)
1109+
tenant_name, zone_list, mode, primary_zone, whitelist, root_password,
1110+
scenario, import_script, charset, collation, read_only, comment, variables, parameters)
10991111
return self.wait_dag_succeed(dag.generic_id)
11001112

11011113
def drop_tenant(self, tenant_name: str, need_recycle: bool = False) -> task.DagDetailDTO:

0 commit comments

Comments
 (0)