This topic describes how to modify the primary zone of a tenant by using obshell-sdk-go.
Note
We recommend that you read Get started with obshell-sdk-go to learn how to use obshell-sdk-go.
Considerations
Make sure that obshell is running.
Make sure that the tenant exists and is in the NORMAL state.
The node corresponding to the client in the request must be in an initialized cluster.
Sample code
package main
import (
"fmt"
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
// Create a client instance, specifying the node address as '10.10.10.1' and the port as 2886.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
fmt.Print(err)
return
}
req := client.V1().NewSetTenantPrimaryZoneRequest("t1", "RANDOM")
if _, err := client.V1().SetTenantPrimaryZoneSyncWithRequest(req); err != nil {
fmt.Print(err)
return
}
}
package main
import (
"fmt"
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
// Create a client instance, specifying the node address as '10.10.10.1' and the port as 2886.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
fmt.Print(err)
return
}
req := client.V1().NewSetTenantPrimaryZoneRequest("t1", "RANDOM")
dag, err := client.V1().SetTenantPrimaryZoneWithRequest(req)
if err != nil {
fmt.Print(err)
return
}
// Wait for the task to succeed.
if dag != nil && dag.GenericDTO != nil {
if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil {
fmt.Print(err)
return
}
}
}
References
For more information about the API for modifying the primary zone of a tenant, see Modify the primary zone of a tenant.
For more information about how to request API methods by using obshell-sdk-python, see Modify the primary zone of a tenant.