文档首页/ 云搜索服务 CSS/ API参考/ API V1/ 集群管理/ 创建集群(已废弃)
更新时间:2025-08-22 GMT+08:00
分享

创建集群(已废弃)

功能介绍

该接口只能创建单一类型节点的集群,如需要创建多种不同节点类型(ess,ess-cold,ess-client,ess-master)组合的集群,建议使用创建集群v2接口。

调用方法

请参见如何调用API

URI

POST /v1.0/{project_id}/clusters

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目ID。获取方法请参见获取项目ID和名称

约束限制

不涉及

取值范围

账户的项目ID。

默认取值

不涉及

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

cluster

CreateClusterBody object

参数解释

集群对象。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表3 CreateClusterBody

参数

是否必选

参数类型

描述

instance

CreateClusterInstanceBody object

参数解释

实例对象。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

datastore

CreateClusterDatastoreBody object

参数解释

数据搜索引擎类型。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

name

String

参数解释

集群名称。

约束限制

不涉及

取值范围

4~32个字符,只能包含数字、字母、中划线和下划线,且必须以字母开头。

默认取值

不涉及

desc

String

参数解释

集群描述。

约束限制

不超过128个字符。

取值范围

数字、字母、点(.)、中划线和下划线和其他特殊字符均可。

默认取值

不涉及

instanceNum

Integer

参数解释

集群实例个数。

约束限制

不涉及

取值范围

1~32。

默认取值

不涉及

backupStrategy

CreateClusterBackupStrategyBody object

参数解释

开启自动创建快照策略,默认关闭。

当backupStrategy参数配置不为空时,才会开启自动创建快照策略。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

httpsEnable

Boolean

参数解释

设置是否进行通信加密。取值范围为true或false。默认关闭通信加密功能。当httpsEnable设置为true时,authorityEnable字段需要设置为true。

约束限制

Elasticsearch安全集群只有6.5.4及之后版本支持。

OpenSearch安全集群只有1.3.6和2.19.0版本支持关闭HTTPS访问,其他版本均强制启用HTTPS访问,不可关闭。

取值范围

  • true:表示集群进行通信加密。

  • false:表示集群不进行通信加密。

默认取值

false

authorityEnable

Boolean

参数解释

是否开启认证,取值范围为true或false。默认关闭认证功能。

约束限制

Elasticsearch安全集群只有6.5.4及之后版本支持。

取值范围

  • true:表示集群开启认证。

  • false:表示集群不开启认证。

默认取值

false

adminPwd

String

参数解释

安全模式下集群管理员admin的密码,只有在创建集群时authorityEnable设置为true时需要设置此参数。安全集群的密码会进行弱口令校验,建议设置安全性高的密码。

约束限制

管理员密码需要满足规则:

  • 可输入的字符串长度为8-32个字符。

  • 密码至少包含大写字母,小写字母,数字和特殊字符中的三类,其中可输入的特殊字符为:~!@#$%^&*()-_=+\|[{}];:,<.>/?。

取值范围

参考约束限制

默认取值

不涉及

enterprise_project_id

String

参数解释

企业项目ID。创建集群时,给集群绑定企业项目ID。最大长度36个字符,带"-"连字符的UUID格式,或者是字符串"0"。"0"表示默认企业项目。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

tags

Array of CreateClusterTagsBody objects

参数解释

集群标签。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

payInfo

payInfoBody object

参数解释

包周期集群相关参数订购包周期集群时使用。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

ipv6_enable

Boolean

参数解释

集群是否开启自动分配IPv6地址,默认值为false。

约束限制

不涉及

取值范围

不涉及

默认取值

false

diskEncryption

diskEncryptionInfo object

参数解释

磁盘加密信息。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表4 CreateClusterInstanceBody

参数

是否必选

参数类型

描述

flavorRef

String

参数解释

实例规格名称。可以使用获取实例规格列表的name属性确认当前拥有的规格信息。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

volume

CreateClusterInstanceVolumeBody object

参数解释

volume信息。当flavorRef选择的是本地盘规格时不需要填写,目前支持的本地盘规格有:

  • ess.spec-i3small

  • ess.spec-i3medium

  • ess.spec-i3.8xlarge.8

  • ess.spec-ds.xlarge.8

  • ess.spec-ds.2xlarge.8

  • ess.spec-ds.4xlarge.8

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

nics

CreateClusterInstanceNicsBody object

参数解释

子网信息。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

availability_zone

String

参数解释

节点所在的可用区,需要指定可用区的名称(可用分区名称)。

约束限制

指定节点所在的可用区时,各个可用区名称需要使用英文逗号(,)分隔,以“通用可用区”为例,选择多可用区时,availability_zone取值为region-1a,region-1b,region-1c。

取值范围

不涉及

默认取值

availability_zone默认为空,表示使用单个可用分区。

说明:
选择多个可用区时,各个可用区名称不能重复输入,并且要求节点个数大于等于可用区个数。

若节点个数为可用区个数的倍数,节点将会均匀分布于各个可用区。

若节点个数非可用区个数的倍数,各可用区分布的节点数量之差的绝对值不大于1。

可用区名称,请在使用前必读中的地区和终端节点中获取。

表5 CreateClusterInstanceVolumeBody

参数

是否必选

参数类型

描述

volume_type

String

参数解释

卷类型。

约束限制

不涉及

取值范围

  • COMMON:普通I/O。

  • HIGH:高I/O。

  • ULTRAHIGH:超高I/O。

  • ESSD:极速SSD。

默认取值

不涉及

size

Integer

参数解释

磁盘大小。

约束限制

必须为大于0且为4和10的公倍数,单位:GB。

取值范围

磁盘规格大小可以通过获取实例规格列表中diskrange属性获得。

默认取值

  • ess节点和ess-cold节点:默认100G与节点规格支持的最小磁盘容量取较大者。

  • ess-master节点和ess-client节点:默认大小为40G,且不可更改。

说明:
ess节点和ess-cold节点,推荐大于100G。
表6 CreateClusterInstanceNicsBody

参数

是否必选

参数类型

描述

vpcId

String

参数解释

指定虚拟私有云ID,用于集群网络配置。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

netId

String

参数解释

子网ID(网络ID)。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

securityGroupId

String

参数解释

安全组ID。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表7 CreateClusterDatastoreBody

参数

是否必选

参数类型

描述

version

String

参数解释

Elasticsearch/Logstash引擎版本号。详细请参考CSS使用前必读中支持的版本。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

type

String

参数解释

要创建的集群的引擎类型。

约束限制

不涉及

取值范围

  • elasticsearch:Elasticsearch集群。

  • opensearch:Opensearch集群。

  • logstash:Logstash集群。

默认取值

不涉及

表8 CreateClusterBackupStrategyBody

参数

是否必选

参数类型

描述

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调用您的其他云服务。无法配置含特殊字符和中文字符的委托。

约束限制

不涉及

取值范围

允许使用的委托名称仅可包含a-zA-Z0-9-_字符。

默认取值

不涉及

说明:
如果bucket、basePath和agency三个参数同时为空,则系统会自动创建OBS桶和IAM代理(若创建失败,则需要手工配置正确的参数)。

frequency

String

参数解释

自动创建快照的执行频次。

约束限制

不涉及

取值范围

  • HOUR:表示每小时整点执行一次。

  • DAY:表示每天执行一次。

  • SUN、MON、TUE、WED、THU、FRI、SAT:表示在每周对应时间执行一次。比如SUN表示每周日执行一次。

  • 保留快照个数与自动创建快照策略中设置的执行频次和索引有关。当执行频次间隔时间短或索引数据量大,保留自动快照可能会达不到设置的个数,请谨慎选择!

默认取值

DAY

maxSnapshotBytesPerSeconds

String

参数解释

配置每个节点的最大备份速率(每秒),即当备份的速率超过该值时会被限流,避免速率太大导致资源占用过高,影响系统稳定性。实际备份速率不一定能达到该值,会受OBS、磁盘等影响。

约束限制

不涉及

取值范围

有以下3种填写规则:

  • 数字+单位

    数字部分支持0~9999。

    单位部分支持k、kb、m、mb、g、gb、t、tb、p、pb、b,且不区分大小写。

    当填写0mb时,表示不限速,当备份速率过大时,可能导致备份占用资源过高,影响系统稳定性,请谨慎配置该值。

  • 0

    表示不限速,当备份速率过大时,可能导致备份占用资源过高,影响系统稳定性,请谨慎配置该值。

  • -1

    表示不限速,当备份速率过大时,可能导致备份占用资源过高,影响系统稳定性,请谨慎配置该值。

默认取值

默认值是40mb,不填写时表示使用默认值。

maxRestoreBytesPerSeconds

String

参数解释

配置每个节点的最大恢复速率(每秒),即当恢复的速率超过该值时会被限流,避免速率太大导致资源占用过高,影响系统稳定性。实际恢复速率不一定能达到该值,会受OBS、磁盘等影响。

约束限制

OpenSearch集群和版本是7.6.2以后的Elasticsearch集群,恢复速率还受限于“indices.recovery.max_bytes_per_sec”参数。当“最大恢复速率(每秒)”小于“indices.recovery.max_bytes_per_sec”的参数值时,恢复速率达到“最大恢复速率(每秒)”参数值时就会被限流。当“最大恢复速率(每秒)”大于“indices.recovery.max_bytes_per_sec”的参数值时,恢复速率达到“indices.recovery.max_bytes_per_sec”参数值时就会被限流。

取值范围

有以下3种填写规则:

  • 数字+单位

    数字部分支持0~9999。

    单位部分支持k、kb、m、mb、g、gb、t、tb、p、pb、b,且不区分大小写。

    当填写0mb时,表示不限速(但OpenSearch集群和7.6.2以上版本的Elasticsearch集群,恢复速率还受限于“indices.recovery.max_bytes_per_sec”参数),当恢复速率过大时,可能导致恢复占用资源过高,影响系统稳定性,请谨慎配置该值。

  • 0

    表示不限速(但OpenSearch集群和7.6.2以上版本的Elasticsearch集群,恢复速率还受限于“indices.recovery.max_bytes_per_sec”参数),当恢复速率过大时,可能导致恢复占用资源过高,影响系统稳定性,请谨慎配置该值。

  • -1

    表示不限速(但OpenSearch集群和7.6.2以上版本的Elasticsearch集群,恢复速率还受限于“indices.recovery.max_bytes_per_sec”参数),当恢复速率过大时,可能导致恢复占用资源过高,影响系统稳定性,请谨慎配置该值。

默认取值

7.6.2及以下版本的Elasticsearch集群,默认值是40mb。

OpenSearch集群和7.6.2以上版本的Elasticsearch集群,默认值是不限制,但还受限于“indices.recovery.max_bytes_per_sec”参数。

不填写时表示使用默认值。

表9 CreateClusterTagsBody

参数

是否必选

参数类型

描述

key

String

参数解释

集群标签的key值。

约束限制

不涉及

取值范围

可输入的字符串长度为1~36个字符。只能包含数字、字母、中划线"-"和下划线"_"。

默认取值

不涉及

value

String

参数解释

集群标签的value值。

约束限制

不涉及

取值范围

  • 长度0~255个字符

  • 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格,以及以下字符: _.://=+-@

默认取值

不涉及

表10 payInfoBody

参数

是否必选

参数类型

描述

payModel

Integer

参数解释

订购周期类型。

约束限制

不涉及

取值范围

  • 2: 包月。

  • 3: 包年。

默认取值

不涉及

period

Integer

参数解释

订购周期数。

约束限制

不涉及

取值范围

  • 若payModel为2,则有效值为1-9。

  • 若payModel为3,则有效值为1-3。

默认取值

不涉及

isAutoRenew

Integer

参数解释

是否自动续订,为空时表示不自动续订。

约束限制

不涉及

取值范围

  • 1: 自动续订。

  • 0:不自动续订。

默认取值

0

isAutoPay

Integer

参数解释

是否自动支付。下单订购后,是否自动从客户的华为云账户中支付,而不需要客户手动去进行支付。该参数适用于包周期集群

约束限制

不涉及

取值范围

  • 1:是(会自动选择折扣和优惠券进行优惠,然后自动从客户华为云账户中支付),自动支付失败后会生成订单成功(该订单应付金额是优惠后金额)、但订单状态为“待支付”,等待客户手动支付(手动支付时,客户还可以修改系统自动选择的折扣和优惠券)。

  • 0:否(需要客户手动去支付,客户可以选择折扣和优惠券)。默认值为“0”

默认取值

0

表11 diskEncryptionInfo

参数

是否必选

参数类型

描述

systemEncrypted

String

是否开启磁盘加密,可选值:0和1,默认为0。

0:不开启磁盘加密

1:开启磁盘加密

systemCmkid

String

KMS密钥ID,systemEncrypted为1时有效。

响应参数

状态码:200

表12 响应Body参数

参数

参数类型

描述

cluster

CreateClusterClusterResponse object

参数解释

集群对象。若创建的是按需集群,则只返回cluster参数。

取值范围

不涉及

orderId

String

参数解释

订单号。只有创建包周期集群时才会返回orderld参数。

取值范围

不涉及

表13 CreateClusterClusterResponse

参数

参数类型

描述

id

String

参数解释

集群ID。

取值范围

不涉及

name

String

参数解释

集群名称。

取值范围

不涉及

请求示例

  • 创建包周期集群请求示例。

    POST https://{Endpoint}/v1.0/{project_id}/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",
        "desc" : "测试集群",
        "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",
          "maxSnapshotBytesPerSeconds" : 40,
          "maxRestoreBytesPerSeconds" : 40
        },
        "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 https://{Endpoint}/v1.0/{project_id}/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",
        "desc" : "测试集群",
        "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",
          "maxSnapshotBytesPerSeconds" : 40,
          "maxRestoreBytesPerSeconds" : 40
        },
        "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
    103
    104
    105
    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)
                .withFrequency("DAY")
                .withBucket("css-obs-backup")
                .withBasePath("css_repository/obs-path")
                .withAgency("css_obs_agency")
                .withMaxSnapshotBytesPerSeconds("40")
                .withMaxRestoreBytesPerSeconds("40");
            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
    97
    98
    99
    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)
                .withFrequency("DAY")
                .withBucket("css-obs-backup")
                .withBasePath("css_repository/obs-path")
                .withAgency("css_obs_agency")
                .withMaxSnapshotBytesPerSeconds("40")
                .withMaxRestoreBytesPerSeconds("40");
            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
    91
    92
    93
    # 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,
                frequency="DAY",
                bucket="css-obs-backup",
                base_path="css_repository/obs-path",
                agency="css_obs_agency",
                max_snapshot_bytes_per_seconds="40",
                max_restore_bytes_per_seconds="40"
            )
            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
    84
    85
    86
    # 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,
                frequency="DAY",
                bucket="css-obs-backup",
                base_path="css_repository/obs-path",
                agency="css_obs_agency",
                max_snapshot_bytes_per_seconds="40",
                max_restore_bytes_per_seconds="40"
            )
            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
    107
    108
    109
    110
    111
    112
    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",
            },
        }
    	frequencyBackupStrategy:= "DAY"
    	bucketBackupStrategy:= "css-obs-backup"
    	basePathBackupStrategy:= "css_repository/obs-path"
    	agencyBackupStrategy:= "css_obs_agency"
    	maxSnapshotBytesPerSecondsBackupStrategy:= "40"
    	maxRestoreBytesPerSecondsBackupStrategy:= "40"
    	backupStrategyCluster := &model.CreateClusterBackupStrategyBody{
    		Period: "16:00 GMT+08:00",
    		Prefix: "snapshot",
    		Keepday: int32(7),
    		Frequency: &frequencyBackupStrategy,
    		Bucket: &bucketBackupStrategy,
    		BasePath: &basePathBackupStrategy,
    		Agency: &agencyBackupStrategy,
    		MaxSnapshotBytesPerSeconds: &maxSnapshotBytesPerSecondsBackupStrategy,
    		MaxRestoreBytesPerSeconds: &maxRestoreBytesPerSecondsBackupStrategy,
    	}
    	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
     98
     99
    100
    101
    102
    103
    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",
            },
        }
    	frequencyBackupStrategy:= "DAY"
    	bucketBackupStrategy:= "css-obs-backup"
    	basePathBackupStrategy:= "css_repository/obs-path"
    	agencyBackupStrategy:= "css_obs_agency"
    	maxSnapshotBytesPerSecondsBackupStrategy:= "40"
    	maxRestoreBytesPerSecondsBackupStrategy:= "40"
    	backupStrategyCluster := &model.CreateClusterBackupStrategyBody{
    		Period: "16:00 GMT+08:00",
    		Prefix: "snapshot",
    		Keepday: int32(7),
    		Frequency: &frequencyBackupStrategy,
    		Bucket: &bucketBackupStrategy,
    		BasePath: &basePathBackupStrategy,
    		Agency: &agencyBackupStrategy,
    		MaxSnapshotBytesPerSeconds: &maxSnapshotBytesPerSecondsBackupStrategy,
    		MaxRestoreBytesPerSeconds: &maxRestoreBytesPerSecondsBackupStrategy,
    	}
    	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

未满足前提条件,服务器未满足请求者在请求中设置的其中一个前提条件。

错误码

请参见错误码

相关文档