切换产品类型

您可以点击下拉框切换本产品的不同产品类型,帮助您更高效地阅读文档。

网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
解决方案工作台
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts 盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
数智融合计算服务 DataArtsFabric
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
解决方案工作台
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts 盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务
文档首页/ 云搜索服务 CSS/ API参考/ API V1/ 集群管理/ 创建集群(已废弃)

创建集群(已废弃)

更新时间:2025-05-26 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个字符,只能包含数字、字母、中划线和下划线,且必须以字母开头。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

instanceNum

Integer

参数解释

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

约束限制

不涉及

取值范围

1~32。

默认取值

不涉及

backupStrategy

CreateClusterBackupStrategyBody object

参数解释

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

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

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

httpsEnable

Boolean

参数解释

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

约束限制

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

取值范围

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

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

默认取值

false

authorityEnable

Boolean

参数解释

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

约束限制

此参数只有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

表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时,各个可用分区名称需要使用英文逗号(,)分隔,以“region-1”为例,选择三AZ时,availability_zone取值为region-1a,region-1b,region-1c。如果使用单AZ,availability_zone默认取值为空。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

说明:
选择多AZ时

1、各个可用分区名称不能重复输入,并且要求节点个数大于等于AZ个数。

2、如果节点个数为AZ个数的倍数,节点将会均匀的分布到各个AZ。

3、如果节点个数不为AZ个数的倍数时,各个AZ分布的节点数量之差的绝对值小于等于1。

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

表5 CreateClusterInstanceVolumeBody

参数

是否必选

参数类型

描述

volume_type

String

参数解释

卷类型。

约束限制

不涉及

取值范围

  • COMMON:普通I/O。

  • HIGH:高I/O。

  • ULTRAHIGH:超高I/O。

  • ESSD:极速SSD。

默认取值

不涉及

size

Integer

参数解释

卷大小。

单位:GB。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

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

参数

是否必选

参数类型

描述

vpcId

String

参数解释

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

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

netId

String

参数解释

子网ID(网络ID)。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

securityGroupId

String

参数解释

安全组ID。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表7 CreateClusterDatastoreBody

参数

是否必选

参数类型

描述

version

String

参数解释

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

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

type

String

参数解释

引擎类型,支持elasticsearch、logstash和opensearch。

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表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

参数解释

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

约束限制

不涉及

取值范围

不涉及

默认取值

DAY

说明:
取值HOUR时,表示每小时整点执行一次;取值DAY时,表示每天执行一次;取值SUN、MON、TUE、WED、THU、FRI、SAT时,表示在每周对应时间执行一次。比如SUN表示每周日执行一次。保留快照个数与自动创建快照策略中设置的执行频次和索引有关。当执行频次间隔时间短或索引数据量大,保留自动快照可能会达不到设置的个数,请谨慎选择!

maxSnapshotBytesPerSeconds

String

参数解释

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

约束限制

不涉及

取值范围

有以下3种填写规则:

  • 数字+单位

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

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

  • 0

  • -1

数字部分支持0~9999。

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

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

默认取值

默认值是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种填写规则:

  • 数字+单位

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

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

  • 0

  • -1

数字部分支持0~9999。

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

表示不限速(但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~43个字符。只能包含数字、字母、中划线"-"和下划线"_"。

默认取值

不涉及

表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

响应参数

状态码:200

表11 响应Body参数

参数

参数类型

描述

cluster

CreateClusterClusterResponse object

参数解释

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

取值范围

不涉及

orderId

String

参数解释

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

取值范围

不涉及

表12 CreateClusterClusterResponse

参数

参数类型

描述

id

String

参数解释

集群ID。

取值范围

不涉及

name

String

参数解释

集群名称。

取值范围

不涉及

请求示例

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

    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代码示例。

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

      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

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

错误码

请参见错误码

提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容