更新时间:2024-02-26 GMT+08:00
分享

创建集群

功能介绍

该接口用于创建集群。

调用方法

请参见如何调用API

URI

POST /v1.0/{project_id}/clusters

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

cluster

CreateClusterBody object

集群对象。

表3 CreateClusterBody

参数

是否必选

参数类型

描述

instance

CreateClusterInstanceBody object

实例对象。

datastore

CreateClusterDatastoreBody object

数据搜索引擎类型。

name

String

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

instanceNum

Integer

集群实例个数,取值范围为1~32。

backupStrategy

CreateClusterBackupStrategyBody object

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

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

httpsEnable

Boolean

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

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

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

说明:

此参数只有6.5.4及之后版本支持。

authorityEnable

Boolean

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

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

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

说明:

此参数只有6.5.4及之后版本支持。

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

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

表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

可用区。需要指定可用区的名称(可用分区名称)。 默认指定单AZ。指定多AZ时,各个可用分区名称需要使用英文逗号(,)分隔,以“华北-北京四”为例,选择三AZ时,availability_zone取值为cn-north-4a,cn-north-4b,cn-north-4c。如果使用单AZ,availability_zone默认取值为空。

说明:

说明 - 选择多AZ时,各个可用分区名称不能重复输入,并且要求节点个数大于等于AZ个数。 - 如果节点个数为AZ个数的倍数,节点将会均匀的分布到各个AZ。 - 如果节点个数不为AZ个数的倍数时,各个AZ分布的节点数量之差的绝对值小于等于1。 - 可用分区名称,请在地区和终端节点获取。

表5 CreateClusterInstanceVolumeBody

参数

是否必选

参数类型

描述

volume_type

String

卷类型。

  • COMMON:普通I/O。

  • HIGH:高I/O。

  • ULTRAHIGH:超高I/O。

  • ESSD:极速SSD。

size

Integer

卷大小,必须大于0且为4和10的公倍数,磁盘规格大小可以通过获取实例规格列表中diskrange属性获得。 单位:GB。

表6 CreateClusterInstanceNicsBody

参数

是否必选

参数类型

描述

vpcId

String

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

netId

String

子网ID(网络ID)。

securityGroupId

String

安全组ID。

表7 CreateClusterDatastoreBody

参数

是否必选

参数类型

描述

version

String

Esasticsearch/Logstash引擎版本号。详细请参考CSS支持的集群版本

type

String

引擎类型,支持elasticsearch和logstash。

表8 CreateClusterBackupStrategyBody

参数

是否必选

参数类型

描述

period

String

每天自动创建快照的时间点。只支持整点,后面需加上时区,格式为“HH:mm z”,“HH:mm”表示整点时间,“z”表示时区。比如“00:00 GMT+08:00”、“01:00 GMT+08:00”等。

prefix

String

自动创建的快照的前缀,需要用户自己手动输入。只能包含1~32位小写字母、数字、中划线或者下划线,并且以小写字母开头。

keepday

Integer

自动创建快照的保留天数。取值范围:1-90。

bucket

String

备份使用的OBS桶名称。

basePath

String

快照在OBS桶中的存放路径。

agency

String

委托名称,委托给CSS,允许CSS调用您的其他云服务。

说明:

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

表9 CreateClusterTagsBody

参数

是否必选

参数类型

描述

key

String

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

value

String

集群标签的value值。可输入的字符串长度为0~43个字符。只能包含数字、字母、中划线"-"和下划线"_"。

表10 payInfoBody

参数

是否必选

参数类型

描述

payModel

Integer

订购周期类型。

  • 2: 包月。

  • 3: 包年。

period

Integer

订购周期数。

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

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

isAutoRenew

Integer

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

  • 1: 自动续订。

  • 0:不自动续订(默认)。

isAutoPay

Integer

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

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

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

响应参数

状态码: 200

表11 响应Body参数

参数

参数类型

描述

cluster

CreateClusterClusterResponse object

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

orderId

String

订单号。若创建的是包周期集群,则只返回ordeld参数。

表12 CreateClusterClusterResponse

参数

参数类型

描述

id

String

集群ID。

name

String

集群名称。

请求示例

创建包周期集群请求示例。若需要创建按需集群,删掉请求体中的payInfo字段即可。

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,
      "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
    }
  }
}

响应示例

状态码: 200

请求已成功。

  • 创建按需期集群响应示例。

    {
      "cluster" : {
        "id" : "ef683016-871e-48bc-bf93-74a29d60d214",
        "name" : "ES-Test"
      }
    }
  • 创建包周期集群响应示例。

    {
      "orderId" : "CS2208241141LY94J"
    }

SDK代码示例

SDK代码示例如下。

创建包周期集群请求示例。若需要创建按需集群,删掉请求体中的payInfo字段即可。

  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
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");

        ICredential auth = new BasicCredentials()
                .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());
        }
    }
}

创建包周期集群请求示例。若需要创建按需集群,删掉请求体中的payInfo字段即可。

 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
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    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)

创建包周期集群请求示例。若需要创建按需集群,删掉请求体中的payInfo字段即可。

  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
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        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)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求已成功。

400

非法请求。

建议直接修改该请求,不要重试该请求。

409

服务器在完成请求时发生冲突。

返回该状态码,表明客户端尝试创建的资源已经存在,或者由于冲突请求的更新操作不能被完成。

412

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

错误码

请参见错误码

分享:

    相关文档

    相关产品