Creating a Cluster
Function
This API is used to create a cluster.
The cluster must run in a VPC. Before creating a cluster, you need to create a VPC and obtain the VPC and subnet IDs.
This API is an asynchronous API. It takes 10 to 15 minutes to create a cluster.
Calling Method
For details, see Calling APIs.
URI
POST /v1.0/{project_id}/clusters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Project ID. To obtain the value, see Obtaining a Project ID. Constraints N/A Range N/A Default Value N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| cluster | Yes | CreateClusterInfo object | Definition Cluster object. Range Non-null object. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| node_type | Yes | String | Definition Node flavor ID. To obtain the value, call the API for querying flavors and view the id field in the API response. Constraints N/A Range The value must be the flavor ID returned by the API for querying flavors. Default Value N/A |
| number_of_node | Yes | Integer | Definition Number of nodes. Constraints N/A Range For a cluster, the value is from 3 to 256. For a hybrid data warehouse (standalone), the value is 1. Default Value N/A |
| subnet_id | Yes | String | Definition Subnet ID, which is used for configuring the cluster network. Constraints N/A Range The value must be a subnet in the VPC ID. Default Value N/A |
| security_group_id | Yes | String | Definition Security group ID, which is used for configuring the cluster network. Constraints N/A Range If this parameter is not left blank, it must be a valid security group ID. If this parameter is left blank, the system automatically creates a security group. Default Value null |
| vpc_id | Yes | String | Definition VPC ID, which is used for configuring cluster network. Constraints N/A Range The value must be a valid VPC ID. Default Value N/A |
| availability_zone | No | String | Definition AZ of the cluster. Constraints N/A Range The AZ code must be valid at the current region and visible to the current user. Default Value AZ code of the first available AZ. |
| port | No | Integer | Definition Cluster database port. Constraints N/A Range 8000 to 30000 Default Value 8000 |
| name | Yes | String | Definition Cluster name. Constraints The value must be unique. It must contain 4 to 64 characters and start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. Range 4 to 64 characters Default Value 8000 |
| user_name | Yes | String | Definition Administrator username for logging in to a GaussDB(DWS) cluster. Constraints
Range 1 to 63 characters Default Value dbadmin |
| user_pwd | Yes | String | Definition Administrator password for logging in to a GaussDB(DWS) cluster. Constraints N/A Range The value can contain 12 to 32 characters. The value can contain at least three types of the following characters: uppercase letters, lowercase letters, numbers, and special characters (~!?,.:;_(){}[]/<>@#%^&*+|\=-). The value must be different from the username or the username spelled backwards. Default Value N/A |
| public_ip | No | PublicIp object | Definition Public IP address. If the parameter is not specified, public connection is not used by default. Constraints N/A Range N/A Default Value null |
| number_of_cn | No | Integer | Definition Number of CNs deployed. Constraints N/A Range 2 to Number of cluster nodes. The maximum value is 20. Default Value 3 |
| enterprise_project_id | No | String | Definition Enterprise project ID for a cluster. If this parameter is not specified, the default value 0 (indicating that the ID of the default enterprise project) is used. Constraints N/A Range N/A Default Value 0 |
| tags | No | Tags object | Definition Tag. By default, no tags are specified for the cluster. Constraints N/A Range N/A Default Value null |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| public_bind_type | No | String | Definition EIP binding type. Constraints N/A Range auto_assign not_use bind_existing Default Value null |
| eip_id | No | String | Definition EIP ID. Constraints N/A Range N/A Default Value null |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| key | Yes | String | Definition Tag key. Constraints N/A Range
Default Value N/A |
| value | Yes | String | Definition Tag value. Constraints N/A Range
Default Value N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| cluster | Cluster object | Definition Cluster object. Range N/A |
Example Requests
Create a data warehouse cluster (AZ: az1.dc1. Node flavor: dws.m1.xlarge.ultrahigh. Nodes: 3. Database port: 8000. The public IP address, the security group ID, subnet ID, and VPC ID are configured.)
POST https://{Endpoint}/v1.0/89cd04f168b84af6be287f71730fdb4b/clusters
{
"cluster" : {
"node_type" : "dws.m1.xlarge.ultrahigh",
"number_of_node" : 3,
"subnet_id" : "374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
"security_group_id" : "dc3ec145-9029-4b39-b5a3-ace5a01f772b",
"vpc_id" : "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
"availability_zone" : "az1.dc1",
"port" : 8000,
"name" : "dws-1",
"user_name" : "dbadmin",
"user_pwd" : "Passw0rd!",
"public_ip" : {
"public_bind_type" : "auto_assign",
"eip_id" : ""
},
"enterprise_project_id" : "aca4e50a-266f-4786-827c-f8d6cc3fbada"
}
} Example Responses
Status code: 200
Request for creating a cluster submitted.
{
"cluster" : {
"id" : "7d85f602-a948-4a30-afd4-e84f47471c15"
}
} SDK Sample Code
The SDK sample code is as follows.
Create a data warehouse cluster (AZ: az1.dc1. Node flavor: dws.m1.xlarge.ultrahigh. Nodes: 3. Database port: 8000. The public IP address, the security group ID, subnet ID, and VPC ID are configured.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dws.v2.region.DwsRegion; import com.huaweicloud.sdk.dws.v2.*; import com.huaweicloud.sdk.dws.v2.model.*; public class CreateClusterSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); DwsClient client = DwsClient.newBuilder() .withCredential(auth) .withRegion(DwsRegion.valueOf("<YOUR REGION>")) .build(); CreateClusterRequest request = new CreateClusterRequest(); CreateClusterRequestBody body = new CreateClusterRequestBody(); PublicIp publicIpCluster = new PublicIp(); publicIpCluster.withPublicBindType("auto_assign") .withEipId(""); CreateClusterInfo clusterbody = new CreateClusterInfo(); clusterbody.withNodeType("dws.m1.xlarge.ultrahigh") .withNumberOfNode(3) .withSubnetId("374eca02-cfc4-4de7-8ab5-dbebf7d9a720") .withSecurityGroupId("dc3ec145-9029-4b39-b5a3-ace5a01f772b") .withVpcId("85b20d7e-9eb7-4b2a-98f3-3c8843ea3574") .withAvailabilityZone("az1.dc1") .withPort(8000) .withName("dws-1") .withUserName("dbadmin") .withUserPwd("Passw0rd!") .withPublicIp(publicIpCluster) .withEnterpriseProjectId("aca4e50a-266f-4786-827c-f8d6cc3fbada"); body.withCluster(clusterbody); request.withBody(body); try { CreateClusterResponse response = client.createCluster(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Create a data warehouse cluster (AZ: az1.dc1. Node flavor: dws.m1.xlarge.ultrahigh. Nodes: 3. Database port: 8000. The public IP address, the security group ID, subnet ID, and VPC ID are configured.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdws.v2.region.dws_region import DwsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdws.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = DwsClient.new_builder() \ .with_credentials(credentials) \ .with_region(DwsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateClusterRequest() publicIpCluster = PublicIp( public_bind_type="auto_assign", eip_id="" ) clusterbody = CreateClusterInfo( node_type="dws.m1.xlarge.ultrahigh", number_of_node=3, subnet_id="374eca02-cfc4-4de7-8ab5-dbebf7d9a720", security_group_id="dc3ec145-9029-4b39-b5a3-ace5a01f772b", vpc_id="85b20d7e-9eb7-4b2a-98f3-3c8843ea3574", availability_zone="az1.dc1", port=8000, name="dws-1", user_name="dbadmin", user_pwd="Passw0rd!", public_ip=publicIpCluster, enterprise_project_id="aca4e50a-266f-4786-827c-f8d6cc3fbada" ) request.body = CreateClusterRequestBody( cluster=clusterbody ) response = client.create_cluster(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Create a data warehouse cluster (AZ: az1.dc1. Node flavor: dws.m1.xlarge.ultrahigh. Nodes: 3. Database port: 8000. The public IP address, the security group ID, subnet ID, and VPC ID are configured.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dws "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := dws.NewDwsClient( dws.DwsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateClusterRequest{} publicBindTypePublicIp:= "auto_assign" eipIdPublicIp:= "" publicIpCluster := &model.PublicIp{ PublicBindType: &publicBindTypePublicIp, EipId: &eipIdPublicIp, } availabilityZoneCluster:= "az1.dc1" portCluster:= int32(8000) enterpriseProjectIdCluster:= "aca4e50a-266f-4786-827c-f8d6cc3fbada" clusterbody := &model.CreateClusterInfo{ NodeType: "dws.m1.xlarge.ultrahigh", NumberOfNode: int32(3), SubnetId: "374eca02-cfc4-4de7-8ab5-dbebf7d9a720", SecurityGroupId: "dc3ec145-9029-4b39-b5a3-ace5a01f772b", VpcId: "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574", AvailabilityZone: &availabilityZoneCluster, Port: &portCluster, Name: "dws-1", UserName: "dbadmin", UserPwd: "Passw0rd!", PublicIp: publicIpCluster, EnterpriseProjectId: &enterpriseProjectIdCluster, } request.Body = &model.CreateClusterRequestBody{ Cluster: clusterbody, } response, err := client.CreateCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | Request for creating a cluster submitted. |
| 400 | Request error. |
| 401 | Authentication failed. |
| 403 | You do not have required permissions. |
| 500 | Internal server error. |
| 503 | Service unavailable. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot