创建集群
功能介绍
该接口用于创建集群。
调用方法
请参见如何调用API。
URI
POST /v1.0/{project_id}/clusters
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。获取方法请参见获取项目ID和名称。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cluster |
是 |
CreateClusterBody object |
集群对象。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
instance |
是 |
CreateClusterInstanceBody object |
实例对象。 |
datastore |
是 |
CreateClusterDatastoreBody object |
数据搜索引擎类型。 |
name |
是 |
String |
集群名称。4~32个字符,只能包含数字、字母、中划线和下划线,且必须以字母开头。 |
instanceNum |
是 |
Integer |
集群实例个数,取值范围为1~32。 |
backupStrategy |
否 |
开启自动创建快照策略,默认关闭。 当backupStrategy参数配置不为空时,才会开启自动创建快照策略。 |
|
httpsEnable |
否 |
Boolean |
设置是否进行通信加密。取值范围为true或false。默认关闭通信加密功能。当httpsEnable设置为true时,authorityEnable字段需要设置为true。
说明:
此参数只有6.5.4及之后版本支持。 |
authorityEnable |
否 |
Boolean |
是否开启认证,取值范围为true或false。默认关闭认证功能。
说明:
此参数只有6.5.4及之后版本支持。 |
adminPwd |
否 |
String |
安全模式下集群管理员admin的密码,只有在创建集群时authorityEnable设置为true时需要设置此参数。
|
enterprise_project_id |
否 |
String |
企业项目ID。创建集群时,给集群绑定企业项目ID。最大长度36个字符,带"-"连字符的UUID格式,或者是字符串"0"。"0"表示默认企业项目。 |
tags |
否 |
Array of CreateClusterTagsBody objects |
集群标签。 |
payInfo |
否 |
payInfoBody object |
包周期集群相关参数订购包周期集群时使用。 |
ipv6_enable |
否 |
Boolean |
集群是否开启自动分配IPv6地址,默认值为false。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
flavorRef |
是 |
String |
实例规格名称。可以使用获取实例规格列表的name属性确认当前拥有的规格信息。 |
volume |
是 |
volume信息。当flavorRef选择的是本地盘规格时不需要填写,目前支持的本地盘规格有:
|
|
nics |
是 |
子网信息。 |
|
availability_zone |
是 |
String |
可用区。需要指定可用区的名称(可用分区名称)。 默认指定单AZ。指定多AZ时,各个可用分区名称需要使用英文逗号(,)分隔,以“华北-北京四”为例,选择三AZ时,availability_zone取值为cn-north-4a,cn-north-4b,cn-north-4c。如果使用单AZ,availability_zone默认取值为空。
说明:
说明 - 选择多AZ时,各个可用分区名称不能重复输入,并且要求节点个数大于等于AZ个数。 - 如果节点个数为AZ个数的倍数,节点将会均匀的分布到各个AZ。 - 如果节点个数不为AZ个数的倍数时,各个AZ分布的节点数量之差的绝对值小于等于1。 - 可用分区名称,请在地区和终端节点获取。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
volume_type |
是 |
String |
卷类型。
|
size |
是 |
Integer |
卷大小,必须大于0且为4和10的公倍数,磁盘规格大小可以通过获取实例规格列表中diskrange属性获得。 单位:GB。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
vpcId |
是 |
String |
指定虚拟私有云ID,用于集群网络配置。 |
netId |
是 |
String |
子网ID(网络ID)。 |
securityGroupId |
是 |
String |
安全组ID。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
version |
是 |
String |
Elasticsearch/Logstash引擎版本号。详细请参考CSS使用前必读中支持的版本。 |
type |
是 |
String |
引擎类型,支持elasticsearch、logstash和opensearch。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
period |
是 |
String |
每天创建快照的时刻,只支持整点,后面需加上时区,格式为“HH:mm z”,“HH:mm”表示整点时间,“z”表示时区。 比如“00:00 GMT+08:00”、“01:00 GMT+08:00”等。
说明:
默认值“00:00 GMT+08:00”,当frequency取值HOUR时,无需指定period值,默认从设置成功的下一整点创建。 |
prefix |
是 |
String |
自动创建的快照的前缀,需要用户自己手动输入。只能包含1~32位小写字母、数字、中划线或者下划线,并且以小写字母开头。 |
keepday |
是 |
Integer |
自定义设置快照保留的个数,范围是1~90。系统在半点时刻会自动删除超过保留个数的快照。过期删除策略只针对与当前自动创建快照策略相同执行频次的自动快照。 |
bucket |
否 |
String |
备份使用的OBS桶名称。 |
basePath |
否 |
String |
快照在OBS桶中的存放路径。 |
agency |
否 |
String |
委托名称,委托给CSS,允许CSS调用您的其他云服务。
说明:
如果bucket、basePath和agency三个参数同时为空,则系统会自动创建OBS桶和IAM代理(若创建失败,则需要手工配置正确的参数)。 |
frequency |
否 |
String |
自动创建快照的执行频次。
说明:
默认值DAY,取值HOUR时,表示每小时整点执行一次;取值DAY时,表示每天执行一次;取值SUN、MON、TUE、WED、THU、FRI、SAT时,表示在每周对应时间执行一次。比如SUN表示每周日执行一次。保留快照个数与自动创建快照策略中设置的执行频次和索引有关。当执行频次间隔时间短或索引数据量大,保留自动快照可能会达不到设置的个数,请谨慎选择! |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
集群标签的key值。可输入的字符串长度为1~36个字符。只能包含数字、字母、中划线"-"和下划线"_"。 |
value |
是 |
String |
集群标签的value值。可输入的字符串长度为0~43个字符。只能包含数字、字母、中划线"-"和下划线"_"。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
payModel |
是 |
Integer |
订购周期类型。
|
period |
是 |
Integer |
订购周期数。
|
isAutoRenew |
否 |
Integer |
是否自动续订,为空时表示不自动续订。
|
isAutoPay |
否 |
Integer |
是否自动支付。下单订购后,是否自动从客户的华为云账户中支付,而不需要客户手动去进行支付。该参数适用于包周期集群。
|
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
cluster |
CreateClusterClusterResponse object |
集群对象。若创建的是按需集群,则只返回cluster参数。 |
orderId |
String |
订单号。只有创建包周期集群时才会返回orderld参数。 |
请求示例
-
创建包周期集群请求示例。
POST /v1.0/6204a5bd270343b5885144cf9c8c158d/clusters { "cluster" : { "instance" : { "flavorRef" : "ess.spec-4u16g", "volume" : { "volume_type" : "COMMON", "size" : 120 }, "nics" : { "vpcId" : "{VPC ID}", "netId" : "{NET ID}", "securityGroupId" : "{Security group ID}" }, "availability_zone" : "{AZ CODE}" }, "datastore" : { "version" : "{cluster-version}", "type" : "elasticsearch" }, "name" : "cluster-name", "instanceNum" : 3, "backupStrategy" : { "period" : "16:00 GMT+08:00", "prefix" : "snapshot", "keepday" : 7, "frequency" : "DAY", "bucket" : "css-obs-backup", "basePath" : "css_repository/obs-path", "agency" : "css_obs_agency" }, "httpsEnable" : true, "authorityEnable" : true, "adminPwd" : "{password}", "enterprise_project_id" : "0", "tags" : [ { "key" : "k1", "value" : "v1" }, { "key" : "k2", "value" : "v2" } ], "payInfo" : { "payModel" : 2, "period" : 1, "isAutoRenew" : 1, "isAutoPay" : 1 } } }
-
创建按需集群请求示例。
POST /v1.0/6204a5bd270343b5885144cf9c8c158d/clusters { "cluster" : { "instance" : { "flavorRef" : "ess.spec-4u16g", "volume" : { "volume_type" : "COMMON", "size" : 120 }, "nics" : { "vpcId" : "{VPC ID}", "netId" : "{NET ID}", "securityGroupId" : "{Security group ID}" }, "availability_zone" : "{AZ CODE}" }, "datastore" : { "version" : "{cluster-version}", "type" : "elasticsearch" }, "name" : "cluster-name", "instanceNum" : 3, "backupStrategy" : { "period" : "16:00 GMT+08:00", "prefix" : "snapshot", "keepday" : 7, "frequency" : "DAY", "bucket" : "css-obs-backup", "basePath" : "css_repository/obs-path", "agency" : "css_obs_agency" }, "httpsEnable" : true, "authorityEnable" : true, "adminPwd" : "{password}", "enterprise_project_id" : "0", "tags" : [ { "key" : "k1", "value" : "v1" }, { "key" : "k2", "value" : "v2" } ] } }
响应示例
状态码: 200
请求已成功。
-
创建按需期集群响应示例。
{ "cluster" : { "id" : "ef683016-871e-48bc-bf93-74a29d60d214", "name" : "ES-Test" } }
-
创建包周期集群响应示例。
{ "cluster" : { "id" : "ef683016-871e-48bc-bf93-74a29d60d214", "name" : "ES-Test" }, "orderId" : "CS2208241141LY94J" }
SDK代码示例
SDK代码示例如下。
-
创建包周期集群请求示例。
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
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.css.v1.region.CssRegion; import com.huaweicloud.sdk.css.v1.*; import com.huaweicloud.sdk.css.v1.model.*; import java.util.List; import java.util.ArrayList; 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); CssClient client = CssClient.newBuilder() .withCredential(auth) .withRegion(CssRegion.valueOf("<YOUR REGION>")) .build(); CreateClusterRequest request = new CreateClusterRequest(); CreateClusterReq body = new CreateClusterReq(); PayInfoBody payInfoCluster = new PayInfoBody(); payInfoCluster.withPayModel(2) .withPeriod(1) .withIsAutoRenew(1) .withIsAutoPay(1); List<CreateClusterTagsBody> listClusterTags = new ArrayList<>(); listClusterTags.add( new CreateClusterTagsBody() .withKey("k1") .withValue("v1") ); listClusterTags.add( new CreateClusterTagsBody() .withKey("k2") .withValue("v2") ); CreateClusterBackupStrategyBody backupStrategyCluster = new CreateClusterBackupStrategyBody(); backupStrategyCluster.withPeriod("16:00 GMT+08:00") .withPrefix("snapshot") .withKeepday(7) .withBucket("css-obs-backup") .withBasePath("css_repository/obs-path") .withAgency("css_obs_agency"); CreateClusterDatastoreBody datastoreCluster = new CreateClusterDatastoreBody(); datastoreCluster.withVersion("{cluster-version}") .withType("elasticsearch"); CreateClusterInstanceNicsBody nicsInstance = new CreateClusterInstanceNicsBody(); nicsInstance.withVpcId("{VPC ID}") .withNetId("{NET ID}") .withSecurityGroupId("{Security group ID}"); CreateClusterInstanceVolumeBody volumeInstance = new CreateClusterInstanceVolumeBody(); volumeInstance.withVolumeType("COMMON") .withSize(120); CreateClusterInstanceBody instanceCluster = new CreateClusterInstanceBody(); instanceCluster.withFlavorRef("ess.spec-4u16g") .withVolume(volumeInstance) .withNics(nicsInstance) .withAvailabilityZone("{AZ CODE}"); CreateClusterBody clusterbody = new CreateClusterBody(); clusterbody.withInstance(instanceCluster) .withDatastore(datastoreCluster) .withName("cluster-name") .withInstanceNum(3) .withBackupStrategy(backupStrategyCluster) .withHttpsEnable(true) .withAuthorityEnable(true) .withAdminPwd("{password}") .withEnterpriseProjectId("0") .withTags(listClusterTags) .withPayInfo(payInfoCluster); 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 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
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.css.v1.region.CssRegion; import com.huaweicloud.sdk.css.v1.*; import com.huaweicloud.sdk.css.v1.model.*; import java.util.List; import java.util.ArrayList; 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); CssClient client = CssClient.newBuilder() .withCredential(auth) .withRegion(CssRegion.valueOf("<YOUR REGION>")) .build(); CreateClusterRequest request = new CreateClusterRequest(); CreateClusterReq body = new CreateClusterReq(); List<CreateClusterTagsBody> listClusterTags = new ArrayList<>(); listClusterTags.add( new CreateClusterTagsBody() .withKey("k1") .withValue("v1") ); listClusterTags.add( new CreateClusterTagsBody() .withKey("k2") .withValue("v2") ); CreateClusterBackupStrategyBody backupStrategyCluster = new CreateClusterBackupStrategyBody(); backupStrategyCluster.withPeriod("16:00 GMT+08:00") .withPrefix("snapshot") .withKeepday(7) .withBucket("css-obs-backup") .withBasePath("css_repository/obs-path") .withAgency("css_obs_agency"); CreateClusterDatastoreBody datastoreCluster = new CreateClusterDatastoreBody(); datastoreCluster.withVersion("{cluster-version}") .withType("elasticsearch"); CreateClusterInstanceNicsBody nicsInstance = new CreateClusterInstanceNicsBody(); nicsInstance.withVpcId("{VPC ID}") .withNetId("{NET ID}") .withSecurityGroupId("{Security group ID}"); CreateClusterInstanceVolumeBody volumeInstance = new CreateClusterInstanceVolumeBody(); volumeInstance.withVolumeType("COMMON") .withSize(120); CreateClusterInstanceBody instanceCluster = new CreateClusterInstanceBody(); instanceCluster.withFlavorRef("ess.spec-4u16g") .withVolume(volumeInstance) .withNics(nicsInstance) .withAvailabilityZone("{AZ CODE}"); CreateClusterBody clusterbody = new CreateClusterBody(); clusterbody.withInstance(instanceCluster) .withDatastore(datastoreCluster) .withName("cluster-name") .withInstanceNum(3) .withBackupStrategy(backupStrategyCluster) .withHttpsEnable(true) .withAuthorityEnable(true) .withAdminPwd("{password}") .withEnterpriseProjectId("0") .withTags(listClusterTags); 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 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 79 80 81 82 83 84 85 86 87 88 89 90
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcss.v1.region.css_region import CssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcss.v1 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 = CssClient.new_builder() \ .with_credentials(credentials) \ .with_region(CssRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateClusterRequest() payInfoCluster = PayInfoBody( pay_model=2, period=1, is_auto_renew=1, is_auto_pay=1 ) listTagsCluster = [ CreateClusterTagsBody( key="k1", value="v1" ), CreateClusterTagsBody( key="k2", value="v2" ) ] backupStrategyCluster = CreateClusterBackupStrategyBody( period="16:00 GMT+08:00", prefix="snapshot", keepday=7, bucket="css-obs-backup", base_path="css_repository/obs-path", agency="css_obs_agency" ) datastoreCluster = CreateClusterDatastoreBody( version="{cluster-version}", type="elasticsearch" ) nicsInstance = CreateClusterInstanceNicsBody( vpc_id="{VPC ID}", net_id="{NET ID}", security_group_id="{Security group ID}" ) volumeInstance = CreateClusterInstanceVolumeBody( volume_type="COMMON", size=120 ) instanceCluster = CreateClusterInstanceBody( flavor_ref="ess.spec-4u16g", volume=volumeInstance, nics=nicsInstance, availability_zone="{AZ CODE}" ) clusterbody = CreateClusterBody( instance=instanceCluster, datastore=datastoreCluster, name="cluster-name", instance_num=3, backup_strategy=backupStrategyCluster, https_enable=True, authority_enable=True, admin_pwd="{password}", enterprise_project_id="0", tags=listTagsCluster, pay_info=payInfoCluster ) request.body = CreateClusterReq( 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcss.v1.region.css_region import CssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcss.v1 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 = CssClient.new_builder() \ .with_credentials(credentials) \ .with_region(CssRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateClusterRequest() listTagsCluster = [ CreateClusterTagsBody( key="k1", value="v1" ), CreateClusterTagsBody( key="k2", value="v2" ) ] backupStrategyCluster = CreateClusterBackupStrategyBody( period="16:00 GMT+08:00", prefix="snapshot", keepday=7, bucket="css-obs-backup", base_path="css_repository/obs-path", agency="css_obs_agency" ) datastoreCluster = CreateClusterDatastoreBody( version="{cluster-version}", type="elasticsearch" ) nicsInstance = CreateClusterInstanceNicsBody( vpc_id="{VPC ID}", net_id="{NET ID}", security_group_id="{Security group ID}" ) volumeInstance = CreateClusterInstanceVolumeBody( volume_type="COMMON", size=120 ) instanceCluster = CreateClusterInstanceBody( flavor_ref="ess.spec-4u16g", volume=volumeInstance, nics=nicsInstance, availability_zone="{AZ CODE}" ) clusterbody = CreateClusterBody( instance=instanceCluster, datastore=datastoreCluster, name="cluster-name", instance_num=3, backup_strategy=backupStrategyCluster, https_enable=True, authority_enable=True, admin_pwd="{password}", enterprise_project_id="0", tags=listTagsCluster ) request.body = CreateClusterReq( 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/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 := css.NewCssClient( css.CssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateClusterRequest{} isAutoRenewPayInfo:= int32(1) isAutoPayPayInfo:= int32(1) payInfoCluster := &model.PayInfoBody{ PayModel: int32(2), Period: int32(1), IsAutoRenew: &isAutoRenewPayInfo, IsAutoPay: &isAutoPayPayInfo, } var listTagsCluster = []model.CreateClusterTagsBody{ { Key: "k1", Value: "v1", }, { Key: "k2", Value: "v2", }, } bucketBackupStrategy:= "css-obs-backup" basePathBackupStrategy:= "css_repository/obs-path" agencyBackupStrategy:= "css_obs_agency" backupStrategyCluster := &model.CreateClusterBackupStrategyBody{ Period: "16:00 GMT+08:00", Prefix: "snapshot", Keepday: int32(7), Bucket: &bucketBackupStrategy, BasePath: &basePathBackupStrategy, Agency: &agencyBackupStrategy, } datastoreCluster := &model.CreateClusterDatastoreBody{ Version: "{cluster-version}", Type: "elasticsearch", } nicsInstance := &model.CreateClusterInstanceNicsBody{ VpcId: "{VPC ID}", NetId: "{NET ID}", SecurityGroupId: "{Security group ID}", } volumeInstance := &model.CreateClusterInstanceVolumeBody{ VolumeType: "COMMON", Size: int32(120), } availabilityZoneInstance:= "{AZ CODE}" instanceCluster := &model.CreateClusterInstanceBody{ FlavorRef: "ess.spec-4u16g", Volume: volumeInstance, Nics: nicsInstance, AvailabilityZone: &availabilityZoneInstance, } httpsEnableCluster:= true authorityEnableCluster:= true adminPwdCluster:= "{password}" enterpriseProjectIdCluster:= "0" clusterbody := &model.CreateClusterBody{ Instance: instanceCluster, Datastore: datastoreCluster, Name: "cluster-name", InstanceNum: int32(3), BackupStrategy: backupStrategyCluster, HttpsEnable: &httpsEnableCluster, AuthorityEnable: &authorityEnableCluster, AdminPwd: &adminPwdCluster, EnterpriseProjectId: &enterpriseProjectIdCluster, Tags: &listTagsCluster, PayInfo: payInfoCluster, } request.Body = &model.CreateClusterReq{ Cluster: clusterbody, } response, err := client.CreateCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建按需集群请求示例。
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/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 := css.NewCssClient( css.CssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateClusterRequest{} var listTagsCluster = []model.CreateClusterTagsBody{ { Key: "k1", Value: "v1", }, { Key: "k2", Value: "v2", }, } bucketBackupStrategy:= "css-obs-backup" basePathBackupStrategy:= "css_repository/obs-path" agencyBackupStrategy:= "css_obs_agency" backupStrategyCluster := &model.CreateClusterBackupStrategyBody{ Period: "16:00 GMT+08:00", Prefix: "snapshot", Keepday: int32(7), Bucket: &bucketBackupStrategy, BasePath: &basePathBackupStrategy, Agency: &agencyBackupStrategy, } datastoreCluster := &model.CreateClusterDatastoreBody{ Version: "{cluster-version}", Type: "elasticsearch", } nicsInstance := &model.CreateClusterInstanceNicsBody{ VpcId: "{VPC ID}", NetId: "{NET ID}", SecurityGroupId: "{Security group ID}", } volumeInstance := &model.CreateClusterInstanceVolumeBody{ VolumeType: "COMMON", Size: int32(120), } availabilityZoneInstance:= "{AZ CODE}" instanceCluster := &model.CreateClusterInstanceBody{ FlavorRef: "ess.spec-4u16g", Volume: volumeInstance, Nics: nicsInstance, AvailabilityZone: &availabilityZoneInstance, } httpsEnableCluster:= true authorityEnableCluster:= true adminPwdCluster:= "{password}" enterpriseProjectIdCluster:= "0" clusterbody := &model.CreateClusterBody{ Instance: instanceCluster, Datastore: datastoreCluster, Name: "cluster-name", InstanceNum: int32(3), BackupStrategy: backupStrategyCluster, HttpsEnable: &httpsEnableCluster, AuthorityEnable: &authorityEnableCluster, AdminPwd: &adminPwdCluster, EnterpriseProjectId: &enterpriseProjectIdCluster, Tags: &listTagsCluster, } request.Body = &model.CreateClusterReq{ Cluster: clusterbody, } response, err := client.CreateCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求已成功。 |
400 |
非法请求。 建议直接修改该请求,不要重试该请求。 |
409 |
服务器在完成请求时发生冲突。 返回该状态码,表明客户端尝试创建的资源已经存在,或者由于冲突请求的更新操作不能被完成。 |
412 |
未满足前提条件,服务器未满足请求者在请求中设置的其中一个前提条件。 |
错误码
请参见错误码。