创建实例
功能介绍
创建实例。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/instances/{instance_id}/clickhouse
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户在某一Region下的project ID。 获取方法请参见获取项目ID。 |
instance_id |
是 |
String |
TaurusDB实例ID,严格匹配UUID规则。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取。 请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。 |
X-Language |
否 |
String |
请求语言类型。默认en-us。 取值范围:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
ClickHouse实例名称。
|
engine |
是 |
ClickHouseEngineInfo object |
引擎信息。 |
ha |
是 |
ha object |
部署信息。 |
flavor_id |
是 |
String |
节点规格ID,可通过“HTAP查询规格信息”获取。 |
db_root_pwd |
是 |
String |
root账户密码。
|
az_mode |
是 |
String |
可用区类型。 取值范围:
|
volume |
是 |
volume object |
存储规格。 |
az_code |
是 |
String |
可用区码。 当ha中mode为Ha时,需要填写多个可用区,用"," 分隔。例如:cn-southwest-244b,cn-southwest-244a |
time_zone |
否 |
String |
时区。默认为所属TaurusDB实例时区。 |
tags_info |
是 |
tags_info object |
标签值。 |
pay_info |
否 |
pay_info object |
支付信息。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
数据库引擎类型,现在只支持click-house。 |
version |
是 |
String |
数据库版本,可通过“HTAP引擎资源查询”获取。 一位数的大版本号。 |
响应参数
状态码: 202
参数 |
参数类型 |
描述 |
---|---|---|
instance |
CreateChInstanceInfo object |
实例信息。 |
job_id |
String |
工作ID。 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
实例ID。 |
az_code |
String |
可用区。 |
az_mode |
String |
可用区模式。 取值范围:
|
name |
String |
实例名。 |
engine |
ClickHouseEngineInfo object |
引擎信息。 |
vpc_id |
String |
虚拟私有云ID。 |
security_group_id |
String |
安全组ID。 |
subnet_id |
String |
子网ID。 |
db_user |
String |
数据库用户。 |
port |
Integer |
数据库端口。取值范围:0~65535。 |
ha_mode |
String |
部署模式。 取值范围:
|
pay_info |
pay_info object |
计费信息。 |
ssl_option |
Boolean |
SSL开关。 |
status |
String |
实例状态。 取值范围:
|
region |
String |
实例所在区。 |
tags_info |
tags_info object |
实例标签。 |
参数 |
参数类型 |
描述 |
---|---|---|
type |
String |
数据库引擎类型,现在只支持click-house。 |
version |
String |
数据库版本,可通过“HTAP引擎资源查询”获取。 一位数的大版本号。 |
参数 |
参数类型 |
描述 |
---|---|---|
pay_model |
String |
计费模式。默认0。 取值范围:
|
order_id |
String |
包周期计费ID。 |
period |
String |
包周期周期。 |
period_type |
String |
包周期周期类型。 取值范围:
|
is_auto_renew |
String |
包周期是否自动续费。 取值范围:
|
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误描述。 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误描述。 |
请求示例
创建ClickHouse实例
POST https://{endpoint}/v3/23a50154cf494ec9ad6883979a12db0a/instances/40dc4c5729f14aad893e2dcd5baf6a15in07/clickhouse { "name" : "htap-cfd5", "engine" : { "type" : "click-house", "version" : "1" }, "ha" : { "mode" : "Single" }, "flavor_id" : "b44cfde6-d250-313c-8d7a-cd216f071658", "db_root_pwd" : "Rds_1234", "az_mode" : "single", "volume" : { "io_type" : "ESSD", "capacity_in_gb" : 40 }, "az_code" : "cn-southwest-244a", "time_zone" : "UTC+08:00", "tags_info" : { "sys_tags" : [ { "key" : "_sys_enterprise_project_id", "value" : "0" } ] } }
响应示例
状态码: 202
Success.
{ "instance" : { "id" : "2cdec02d8c4a4c88aecae08684dd8076in16", "az_code" : "cn-southwest-244a", "az_mode" : "double", "name" : "htap-cfd5", "engine" : { "type" : "click-house", "version" : "1" }, "vpc_id" : "467f1291-994f-4d3a-9db6-d4c563218df5", "security_group_id" : "3dc780b1-9d92-4850-9b98-be248e1b5962", "subnet_id" : "d99cd68c-0067-436d-869e-d32e902d0074", "db_user" : "root", "port" : null, "ha_mode" : "Single", "pay_info" : { "pay_model" : "0", "order_id" : null, "period" : null, "period_type" : null, "is_auto_renew" : null }, "ssl_option" : false, "status" : "creating", "region" : "cn-southwest-244", "tags_info" : { "tags" : [ ], "sys_tags" : [ { "key" : "_sys_enterprise_project_id", "value" : "0" } ] } }, "job_id" : "76078f0b-5162-45c8-b95f-4c1afd37536c" }
SDK代码示例
SDK代码示例如下。
Java
创建ClickHouse实例
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 67 68 69 70 71 72 73 74 75 76 77 78 |
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.gaussdb.v3.region.GaussDBRegion; import com.huaweicloud.sdk.gaussdb.v3.*; import com.huaweicloud.sdk.gaussdb.v3.model.*; import java.util.List; import java.util.ArrayList; public class CreateClickHouseInstanceSolution { 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); GaussDBClient client = GaussDBClient.newBuilder() .withCredential(auth) .withRegion(GaussDBRegion.valueOf("<YOUR REGION>")) .build(); CreateClickHouseInstanceRequest request = new CreateClickHouseInstanceRequest(); request.withInstanceId("{instance_id}"); CreateChInstanceRequestBody body = new CreateChInstanceRequestBody(); List<CreateChInstanceRequestBodyTagsInfoSysTags> listTagsInfoSysTags = new ArrayList<>(); listTagsInfoSysTags.add( new CreateChInstanceRequestBodyTagsInfoSysTags() .withKey("_sys_enterprise_project_id") .withValue("0") ); CreateChInstanceRequestBodyTagsInfo tagsInfobody = new CreateChInstanceRequestBodyTagsInfo(); tagsInfobody.withSysTags(listTagsInfoSysTags); CreateChInstanceRequestBodyVolume volumebody = new CreateChInstanceRequestBodyVolume(); volumebody.withIoType("ESSD") .withCapacityInGb(40); CreateChInstanceRequestBodyHa habody = new CreateChInstanceRequestBodyHa(); habody.withMode("Single"); ClickHouseEngineInfo enginebody = new ClickHouseEngineInfo(); enginebody.withType("click-house") .withVersion("1"); body.withTagsInfo(tagsInfobody); body.withTimeZone("UTC+08:00"); body.withAzCode("cn-southwest-244a"); body.withVolume(volumebody); body.withAzMode("single"); body.withDbRootPwd("Rds_1234"); body.withFlavorId("b44cfde6-d250-313c-8d7a-cd216f071658"); body.withHa(habody); body.withEngine(enginebody); body.withName("htap-cfd5"); request.withBody(body); try { CreateClickHouseInstanceResponse response = client.createClickHouseInstance(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()); } } } |
Python
创建ClickHouse实例
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkgaussdb.v3 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 = GaussDBClient.new_builder() \ .with_credentials(credentials) \ .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateClickHouseInstanceRequest() request.instance_id = "{instance_id}" listSysTagsTagsInfo = [ CreateChInstanceRequestBodyTagsInfoSysTags( key="_sys_enterprise_project_id", value="0" ) ] tagsInfobody = CreateChInstanceRequestBodyTagsInfo( sys_tags=listSysTagsTagsInfo ) volumebody = CreateChInstanceRequestBodyVolume( io_type="ESSD", capacity_in_gb=40 ) habody = CreateChInstanceRequestBodyHa( mode="Single" ) enginebody = ClickHouseEngineInfo( type="click-house", version="1" ) request.body = CreateChInstanceRequestBody( tags_info=tagsInfobody, time_zone="UTC+08:00", az_code="cn-southwest-244a", volume=volumebody, az_mode="single", db_root_pwd="Rds_1234", flavor_id="b44cfde6-d250-313c-8d7a-cd216f071658", ha=habody, engine=enginebody, name="htap-cfd5" ) response = client.create_click_house_instance(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
创建ClickHouse实例
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 67 68 69 70 71 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient( gaussdb.GaussDBClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateClickHouseInstanceRequest{} request.InstanceId = "{instance_id}" var listSysTagsTagsInfo = []model.CreateChInstanceRequestBodyTagsInfoSysTags{ { Key: "_sys_enterprise_project_id", Value: "0", }, } tagsInfobody := &model.CreateChInstanceRequestBodyTagsInfo{ SysTags: listSysTagsTagsInfo, } volumebody := &model.CreateChInstanceRequestBodyVolume{ IoType: "ESSD", CapacityInGb: int32(40), } habody := &model.CreateChInstanceRequestBodyHa{ Mode: "Single", } enginebody := &model.ClickHouseEngineInfo{ Type: "click-house", Version: "1", } timeZoneCreateChInstanceRequestBody:= "UTC+08:00" request.Body = &model.CreateChInstanceRequestBody{ TagsInfo: tagsInfobody, TimeZone: &timeZoneCreateChInstanceRequestBody, AzCode: "cn-southwest-244a", Volume: volumebody, AzMode: "single", DbRootPwd: "Rds_1234", FlavorId: "b44cfde6-d250-313c-8d7a-cd216f071658", Ha: habody, Engine: enginebody, Name: "htap-cfd5", } response, err := client.CreateClickHouseInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
202 |
Success. |
400 |
Client error. |
500 |
Server error. |
错误码
请参见错误码。