This topic describes how to create a user for a tenant by using obshell-sdk-python.
Note
We recommend that you read through Get started with obshell-sdk-python to learn how to use obshell-sdk-python.
This API is supported starting with obshell V4.2.6.
Considerations
Make sure that obshell is running normally.
Make sure that the node corresponding to the request client is in the initialized cluster.
Sample code
from obshell import ClientSet
from obshell.auth import PasswordAuth
# Create a client instance. The IP address of the node is '10.10.10.1' and the port is 2886.
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
# Create a user named user_1 in the test tenant. If you want to create a user in the sys tenant, you can omit the tenant_name and root_password parameters.
db_priv = {
"db_name": "oceanbase",
"privileges": ["SELECT"]
}
client.v1.create_user(user_name="user_1", password="******", tenant_name="test", root_password="*****", global_privileges=["CREATE", "DELETE"], db_privileges=[db_priv])
References
For more information about the API for creating a user, see Create a user.