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.
Call Method
For details, see Calling APIs.
URI
1
|
POST /v1.0/{project_id}/clusters |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details about how to obtain the ID, see Obtaining Project ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
cluster |
Yes |
CreateClusterInfo object |
Cluster object |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
node_type |
Yes |
String |
Node type. For details, see Data Warehouse Types. |
number_of_node |
Yes |
Integer |
Number of cluster nodes. For a cluster, the value ranges from 3 to 256. For a hybrid data warehouse (standalone), the value is 1. |
subnet_id |
Yes |
String |
Subnet ID, which is used for configuring cluster network. |
security_group_id |
Yes |
String |
ID of a security group, which is used for configuring cluster network. |
vpc_id |
Yes |
String |
VPC ID, which is used for configuring cluster network. |
availability_zone |
No |
String |
AZ of a cluster. For details, see Regions and Endpoints.
NOTE:
Currently, you cannot select multiple AZs at a time. |
port |
No |
Integer |
Service port of a cluster. The value ranges from 8000 to 30000. The default value is 8000. |
name |
Yes |
String |
Cluster name, which must be unique. The cluster name must contain 4 to 64 characters, which must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. |
user_name |
Yes |
String |
Administrator username for logging in to a GaussDB(DWS) cluster. The username must: |
user_pwd |
Yes |
String |
Administrator password for logging in to a GaussDB(DWS) cluster
|
public_ip |
No |
PublicIp object |
Public IP address. If this parameter is not specified, the public network is not used by default. |
number_of_cn |
No |
Integer |
Number of deployed CNs. The value ranges from 3 to the number of cluster nodes. The maximum value is 20 and the default value is 3. |
tags |
No |
Tags object |
Tags |
enterprise_project_id |
No |
String |
Enterprise project ID. If no enterprise project is specified, the ID of the default enterprise project is used, that is, 0. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
public_bind_type |
Yes |
String |
Binding type of an EIP. The value can be one of the following: |
eip_id |
No |
String |
EIP ID |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
Yes |
String |
Key. A tag key can contain a maximum of 128 Unicode characters, which cannot be null. The first and last characters cannot be spaces. Only letters, digits, hyphens (-), and underscores (_) are allowed. It cannot contain the following characters: =*<>\,|/ |
value |
Yes |
String |
Value. A tag value can contain a maximum of 43 characters, which can be an empty string. It cannot start or end with a space. Only letters, digits, hyphens (-), and underscores (_) are allowed. It cannot contain the following characters: =*<>\,|/ |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
cluster |
Cluster object |
Cluster object |
Example Request
Create a data warehouse cluster whose AZ is az1.dc1, node flavor is dws.m1.xlarge.ultrahigh, has three nodes, database port is 8000, and public IP address, security group ID, subnet ID, and VPC ID are as follows:
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 Response
Status code: 200
The cluster has been successfully created.
{ "cluster" : { "id" : "7d85f602-a948-4a30-afd4-e84f47471c15" } }
SDK Sample Code
The sample code is as follows:
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 |
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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); DwsClient client = DwsClient.newBuilder() .withCredential(auth) .withRegion(DwsRegion.valueOf("cn-north-4")) .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()); } } } |
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 |
# coding: utf-8 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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = DwsClient.new_builder() \ .with_credentials(credentials) \ .with_region(DwsRegion.value_of("cn-north-4")) \ .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) |
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 |
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := dws.NewDwsClient( dws.DwsClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.CreateClusterRequest{} eipIdPublicIp:= "" publicIpCluster := &model.PublicIp{ PublicBindType: "auto_assign", 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 more SDK sample codes of programming languages, visit API Explorer and click the Sample Code tab. Example codes can be automatically generated.
Status Code
Status Code |
Description |
---|---|
200 |
The cluster has been successfully created. |
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