网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 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
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 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
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 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
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 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
医疗智能体 EIHealth
企业级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
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务

创建缓存实例

更新时间:2024-12-27 GMT+08:00
分享

功能介绍

创建缓存实例,该接口创建的缓存实例支持按需和包周期两种计费方式。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。获取方法请参见获取项目ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

name

String

实例名称。

由英文字符开头,只能由英文字母、数字、中划线和下划线组成。

创建单个实例时,名称长度为4到64位的字符串。批量创建实例时,名称长度为4到56位的字符串,且实例名称格式为“自定义名称-n”,其中n从000开始,依次递增。例如,批量创建两个实例,自定义名称为dcs_demo,则两个实例的名称为dcs_demo-000和dcs_demo-001。

engine

String

缓存引擎:Redis。

engine_version

String

缓存版本。

Redis缓存引擎,取值为4.0、5.0、6.0。

capacity

Float

缓存容量(G Byte)

  • Redis4.0、Redis5.0和Redis6.0基础版:单机和主备类型实例取值:0.125、0.25、0.5、1、2、4、8、16、24、32、48、64。集群实例规格支持:4、8、16、24、32、48、64、96、128、192、256、384、512、768、1024。读写分离实例规格:1、2、4、8、16、32、64。

spec_code

String

产品规格编码。具体查询方法如下:

  • 方法一:登录分布式缓存的控制台,在创建缓存实例页面,查找对应的实例规格名称。

  • 方法二:调用查询产品规格接口查询。

az_codes

Array of strings

创建缓存节点到指定且有资源的可用区Code。具体查询方法,请参考查询可用区信息,在查询时,请注意查看该可用区是否有资源。

如果是创建主备、Proxy集群、Cluster集群实例,支持跨可用区部署,可以为备节点指定备可用区。在为节点指定可用区时,用逗号分隔开,具体请查看示例。

vpc_id

String

缓存实例所在的虚拟私有云ID。

获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,在虚拟私有云的详情页面查找VPC ID。

  • 方法2:通过虚拟私有云服务的查询VPC列表API接口查询。

subnet_id

String

子网的网络ID。

获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,单击VPC下的子网,进入子网详情页面,查找网络ID。

  • 方法2:通过虚拟私有云服务的查询子网列表API接口查询。

security_group_id

String

指定实例所属的安全组。

当engine为Redis且engine_version为4.0/5.0/6.0时,该参数为可选。Redis4.0、Redis5.0、Redis6.0版本基础版实例不支持安全组控制访问(会设置为默认参数值securityGroupId),只支持白名单控制。

获取方法如下:

  • 方法1:登录虚拟私有云服务的控制台界面,在安全组的详情页面查找安全组ID。

  • 方法2:通过虚拟私有云服务的查询安全组列表API接口查询。

publicip_id

String

Redis缓存实例绑定的弹性IP地址的id。

如果开启了公网访问功能(即enable_publicip为true),该字段为必选。

enterprise_project_id

String

企业项目ID。

enterprise_project_name

String

企业项目名称。

description

String

实例的描述信息。

长度不超过1024的字符串。

说明:

\与"在json报文中属于特殊字符,如果参数值中需要显示\或者"字符,请在字符前增加转义字符\,比如\或者"。

enable_ssl

Boolean

Redis 3.0缓存实例开启公网访问功能时,是否选择支持ssl。该参数仅针对Redis 3.0实例,其他版本不涉及。

  • true:开启

  • false:不开启

enable_ipv6

Boolean

是否开启ipv4/ipv6双栈访问,请注意:子网需要同步开启ipv6。

private_ip

String

创建缓存实例手动指定的IP地址。

instance_num

Integer

表示批量创建缓存实例时,创建的实例个数。

默认值:1

取值范围:1-100

maintain_begin

String

维护时间窗开始时间,为UTC时间,格式为HH:mm:ss

  • 维护时间窗开始和结束时间必须为指定的时间段,可参考查询维护时间窗时间段获取。

  • 开始时间必须为18:00:00、19:00:00等。

  • 该参数不能单独为空,若该值为空,则结束时间也为空。系统分配一个默认开始时间18:00:00。

maintain_end

String

维护时间窗结束时间,为UTC时间,格式为HH:mm:ss。

  • 维护时间窗开始和结束时间必须为指定的时间段,可参考查询维护时间窗时间段获取。

  • 结束时间在开始时间基础上加一个小时,即当开始时间为18:00:00时,结束时间为19:00:00。

  • 该参数不能单独为空,若该值为空,则开始时间也为空,系统分配一个默认结束时间19:00:00。

password

String

缓存实例的认证信息。

说明:

当“no_password_access”配置为“false”或未配置时,请求消息中须包含password参数。

Redis类型的缓存实例密码复杂度要求:

  • 输入长度为8到64位的字符串。

  • 不能使用正序或逆序用户名作为密码。

  • 必须包含如下四种字符中的三种组合:

    • 小写字母

    • 大写字母

    • 数字

    • 特殊字符包括(`~!@#$^&*()-_=+\|{}'",<.>/?)

no_password_access

Boolean

是否允许免密码访问缓存实例。

  • true:该实例无需密码即可访问。

  • false:该实例必须通过密码认证才能访问。

    若未配置该参数则默认值为“false”。

bss_param

BssParam object

表示计费模式的相关参数。置空时,默认计费模式为按需计费;否则是包周期方式。

instance_backup_policy

BackupPolicy object

备份策略,实例类型为主备和集群时支持。

tags

Array of ResourceTag objects

实例标签键值。

access_user

String

缓存类型为Redis时,不需要设置,保持为空即可。

enable_publicip

Boolean

Redis 3.0缓存实例是否开启公网访问功能。

  • true:开启

  • false:不开启

port

Integer

实例自定义端口。只有创建Redis4.0及以上版本的基础版实例才支持自定义端口,企业版实例不支持自定义端口,默认端口为6379。

创建Redis实例时,如果没发送该参数或该参数为空,表示实例使用默认端口6379。如果自定义端口,端口范围为1~65535的任意数字。

rename_commands

Object

支持自定义重命名高危命令。仅创建Redis4.0及以上版本的实例支持重命名高危命令。

创建Redis实例,如果没发送该参数或该参数为空,表示没有需要重命名的命令。当前支持重命名的高危命令有command、keys、flushdb、flushall、hgetall、scan、hscan、sscan、和zscan,Proxy集群实例还支持dbsize和dbstats命令重命名,其他命令暂不支持重命名。

template_id

String

参数模板ID,不配置时使用默认参数模板,如需指定自定义参数模板,请参见查询参数模板列表获取模板ID。

表3 BssParam

参数

是否必选

参数类型

描述

is_auto_renew

String

当选择包年包月时,该字段为必选,表示是否自动续订资源。

取值范围:

  • false:不自动续订。

  • true:自动续订。

    默认值为:false

    约束:

    如果设置为自动续订,到期后,会自动续订一个月(自动续订时间后续可能会变化),详情可联系客服咨询。

charging_mode

String

功能说明:付费方式(预付费、按需付费;预付费,即包周期付费)。

取值范围:

  • prePaid:预付费,即包年包月;

  • postPaid:后付费,即按需付费;

    默认值是postPaid。

    后付费的场景下,bss_param参数的其他字段都会被忽略。

is_auto_pay

String

功能说明:下单订购后,是否自动从客户的账户中支付;默认是“不自动支付” 。

取值范围:

  • true:是(自动支付,从账户余额自动扣费)

  • false:否(默认值,只提交订单不支付,需要客户手动去支付)

约束:

自动支付时,只能使用账户的现金支付;如果要使用代金券,请选择不自动支付,然后在用户费用中心,选择代金券支付。

如果包周期购买,没有设置成自动支付,即设置为false时,在变更规格或创建实例之后,用户必须在“费用中心 > 我的订单”,完成订单支付,否则订单一直在支付中,实例没有变更或者创建成功

period_type

String

当选择包年包月时,该字段为必选,表示订购资源的周期类型。

取值范围如下:

  • month:表示包月

  • year:表示包年

period_num

Integer

功能说明:订购周期数。

当选择按需时,该字段非必选。

[取值范围:(后续会随运营策略变化)

  • period_type为month时,为[1,9],

  • period_type为year时,为[1,3]

约束:同period_type约束。

表4 BackupPolicy

参数

是否必选

参数类型

描述

backup_type

String

备份类型。

  • auto:自动备份。

  • manual:手动备份。

save_days

Integer

当backup_type设置为auto时,该参数为必填。

保留天数,单位:天,取值范围:1-7。由自动切换为手动时,保留自动备份策略信息。

periodical_backup_plan

BackupPlan object

备份计划,当backup_type设置为auto时,该参数为必填。由自动切换为手动时,保留自动备份策略信息。

表5 BackupPlan

参数

是否必选

参数类型

描述

timezone_offset

String

参数解释

备份的时区。该参数已废弃,没有实际作用。

取值范围

不涉及。

backup_at

Array of integers

参数解释

每周的周几开始备份。由自动切换为手动时,保留自动备份策略信息。

取值范围

1-7,分别表示星期一到星期日。

period_type

String

参数解释

备份周期类型,目前支持“weekly”。由自动切换为手动时,保留自动备份策略信息。

取值范围

不涉及。

begin_at

String

参数解释

备份开始执行时间,该时间为UTC时间,例如“00:00-01:00”代表UTC时间0点开始执行备份。只能是整点时间段,间隔时间限定为一个小时。由自动切换为手动时,保留自动备份策略信息。

取值范围

不涉及。

表6 ResourceTag

参数

是否必选

参数类型

描述

key

String

参数解释

标签键。

  • 不能为空。

  • 对于同一资源键值唯一。

  • 长度不超过36个字符。

  • 标签的键必须唯一且输入不能为空。

取值范围

不涉及。

value

String

参数解释

标签值。

  • action为create时必选。action为delete时非必选。

  • 长度不超过43个字符。

取值范围

不涉及。

响应参数

状态码: 200

表7 响应Body参数

参数

参数类型

描述

order_id

String

订单ID,仅在创建包周期实例时返回。

instances

Array of Instances objects

缓存实例ID和名称,如果批量创建实例,则会返回多个。

表8 Instances

参数

参数类型

描述

instance_id

String

缓存实例ID。

instance_name

String

缓存实例名称。

状态码: 400

表9 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 401

表10 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 403

表11 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 404

表12 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 500

表13 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

请求示例

  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

    POST https://{dcs_endpoint}/v2/{project_id}/instances
    
    {
      "name" : "dcs-APITest",
      "description" : "Test",
      "engine" : "Redis",
      "engine_version" : 5.0,
      "enterprise_project_id" : 0,
      "enterprise_project_name" : "default",
      "vpc_id" : "5e37b3be-950a-48e1-b498-65b63d336481",
      "security_group_id" : "securityGroupId",
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01" ],
      "capacity" : 0,
      "access_user" : "",
      "maintain_begin" : "18:00:00",
      "maintain_end" : "19:00:00",
      "password" : "********",
      "enable_publicip" : false,
      "spec_code" : "redis.single.xu1.tiny.128",
      "subnet_id" : "a4112635-3ec0-471c-95c3-5cf49b9533af",
      "no_password_access" : false,
      "template_id" : "b3ecc9c7-1133-4c47-a06a-21366e227d61"
    }
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

    {
      "enterprise_project_name" : "default",
      "vpc_id" : "c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
      "description" : "Test",
      "security_group_id" : "d57fad27-e3e9-43b7-9498-0a698ab63b27",
      "port" : 4040,
      "maintain_end" : "19:00:00",
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01", "region02" ],
      "capacity" : 2,
      "access_user" : "",
      "instance_num" : 1,
      "maintain_begin" : "18:00:00",
      "enterprise_project_id" : 0,
      "password" : "********",
      "enable_publicip" : false,
      "engine" : "Redis",
      "spec_code" : "redis.ha.au1.large.2",
      "name" : "dcs-demo",
      "subnet_id" : "7e95c4d6-d7af-424c-a3cf-2be10968fe81",
      "engine_version" : 4.0,
      "no_password_access" : false,
      "rename_commands" : {
        "keys" : "keys001",
        "flushdb" : "flushdb001",
        "flushall" : "flushall001"
      },
      "tags" : [ {
        "key" : "dcs001",
        "value" : 2
      }, {
        "key" : "dcs003",
        "value" : 4
      } ]
    }
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

    {
      "publicip_id" : "",
      "enterprise_project_name" : "default",
      "vpc_id" : "5e37b3be-950a-48e1-b498-65b63d336481",
      "description" : "Test",
      "security_group_id" : "securityGroupId",
      "maintain_begin" : "18:00:00",
      "maintain_end" : "19:00:00",
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01", "region02" ],
      "capacity" : 0,
      "access_user" : "",
      "enterprise_project_id" : 0,
      "password" : "********",
      "enable_publicip" : false,
      "engine" : "Redis",
      "spec_code" : "redis.ha.xu1.tiny.r2.128",
      "name" : "dcs-APITest1",
      "subnet_id" : "a4112635-3ec0-471c-95c3-5cf49b9533af",
      "engine_version" : 4.0,
      "no_password_access" : false,
      "instance_backup_policy" : {
        "save_days" : 3,
        "backup_type" : "auto",
        "periodical_backup_plan" : {
          "begin_at" : "16:00-17:00",
          "period_type" : "weekly",
          "backup_at" : [ 1, 2, 3, 4 ]
        }
      },
      "bss_param" : {
        "charging_mode" : "prePaid",
        "is_auto_pay" : true,
        "period_type" : "month",
        "period_num" : 1,
        "is_auto_renew" : false
      }
    }
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

    {
      "publicip_id" : "",
      "enterprise_project_name" : "default",
      "vpc_id" : "5e37b3be-950a-48e1-b498-65b63d336481",
      "description" : "Test",
      "security_group_id" : "securityGroupId",
      "maintain_end" : "19:00:00",
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01" ],
      "capacity" : 4,
      "access_user" : "",
      "maintain_begin" : "18:00:00",
      "enterprise_project_id" : 0,
      "password" : "********",
      "enable_publicip" : false,
      "engine" : "Redis",
      "spec_code" : "redis.cluster.xu1.large.r2.4",
      "name" : "dcs-APITest2",
      "subnet_id" : "a4112635-3ec0-471c-95c3-5cf49b9533af",
      "engine_version" : 4.0,
      "no_password_access" : false,
      "bss_param" : {
        "charging_mode" : "prePaid",
        "is_auto_pay" : true,
        "period_type" : "month",
        "period_num" : 1,
        "is_auto_renew" : false
      },
      "instance_backup_policy" : {
        "save_days" : 3,
        "backup_type" : "auto",
        "periodical_backup_plan" : {
          "begin_at" : "16:00-17:00",
          "period_type" : "weekly",
          "backup_at" : [ 1, 2, 3, 4, 5, 6, 7 ]
        }
      }
    }

响应示例

状态码: 200

下发创建缓存实例任务成功。

说明:

查看实例状态为RUNNING时,即缓存实例创建成功。

  • 示例 1

    {
      "instances" : [ {
        "instance_id" : "3c49fd6b-fc7c-419e-9644-b6cce008653f",
        "instance_name" : "dcs-test005"
      } ]
    }
  • 示例 2

    {
      "order_id" : "CS2005091653L2DAM",
      "instances" : [ {
        "instance_id" : "77284d69-cd51-4bf1-aa30-2e60f055800c",
        "instance_name" : "dcs-APITest1"
      } ]
    }

SDK代码示例

SDK代码示例如下。

  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            body.withTemplateId("b3ecc9c7-1133-4c47-a06a-21366e227d61");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.single.xu1.tiny.128");
            body.withCapacity(0f);
            body.withEngineVersion("5.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<ResourceTag> listbodyTags = new ArrayList<>();
            listbodyTags.add(
                new ResourceTag()
                    .withKey("dcs001")
                    .withValue("2")
            );
            listbodyTags.add(
                new ResourceTag()
                    .withKey("dcs003")
                    .withValue("4")
            );
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            listbodyAzCodes.add("region02");
            body.withRenameCommands("{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}");
            body.withPort(4040);
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withTags(listbodyTags);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withInstanceNum(1);
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withSecurityGroupId("d57fad27-e3e9-43b7-9498-0a698ab63b27");
            body.withSubnetId("7e95c4d6-d7af-424c-a3cf-2be10968fe81");
            body.withVpcId("c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.ha.au1.large.2");
            body.withCapacity(2f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-demo");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

     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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<Integer> listPeriodicalBackupPlanBackupAt = new ArrayList<>();
            listPeriodicalBackupPlanBackupAt.add(1);
            listPeriodicalBackupPlanBackupAt.add(2);
            listPeriodicalBackupPlanBackupAt.add(3);
            listPeriodicalBackupPlanBackupAt.add(4);
            BackupPlan periodicalBackupPlanInstanceBackupPolicy = new BackupPlan();
            periodicalBackupPlanInstanceBackupPolicy.withBackupAt(listPeriodicalBackupPlanBackupAt)
                .withPeriodType("weekly")
                .withBeginAt("16:00-17:00");
            BackupPolicy instanceBackupPolicybody = new BackupPolicy();
            instanceBackupPolicybody.withBackupType("auto")
                .withSaveDays(3)
                .withPeriodicalBackupPlan(periodicalBackupPlanInstanceBackupPolicy);
            BssParam bssParambody = new BssParam();
            bssParambody.withIsAutoRenew(BssParam.IsAutoRenewEnum.fromValue("false"))
                .withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(BssParam.IsAutoPayEnum.fromValue("true"))
                .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1);
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            listbodyAzCodes.add("region02");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withInstanceBackupPolicy(instanceBackupPolicybody);
            body.withBssParam(bssParambody);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withPublicipId("");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.ha.xu1.tiny.r2.128");
            body.withCapacity(0f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest1");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<Integer> listPeriodicalBackupPlanBackupAt = new ArrayList<>();
            listPeriodicalBackupPlanBackupAt.add(1);
            listPeriodicalBackupPlanBackupAt.add(2);
            listPeriodicalBackupPlanBackupAt.add(3);
            listPeriodicalBackupPlanBackupAt.add(4);
            listPeriodicalBackupPlanBackupAt.add(5);
            listPeriodicalBackupPlanBackupAt.add(6);
            listPeriodicalBackupPlanBackupAt.add(7);
            BackupPlan periodicalBackupPlanInstanceBackupPolicy = new BackupPlan();
            periodicalBackupPlanInstanceBackupPolicy.withBackupAt(listPeriodicalBackupPlanBackupAt)
                .withPeriodType("weekly")
                .withBeginAt("16:00-17:00");
            BackupPolicy instanceBackupPolicybody = new BackupPolicy();
            instanceBackupPolicybody.withBackupType("auto")
                .withSaveDays(3)
                .withPeriodicalBackupPlan(periodicalBackupPlanInstanceBackupPolicy);
            BssParam bssParambody = new BssParam();
            bssParambody.withIsAutoRenew(BssParam.IsAutoRenewEnum.fromValue("false"))
                .withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(BssParam.IsAutoPayEnum.fromValue("true"))
                .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1);
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withInstanceBackupPolicy(instanceBackupPolicybody);
            body.withBssParam(bssParambody);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withPublicipId("");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.cluster.xu1.large.r2.4");
            body.withCapacity(4f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest2");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listAzCodesbody = [
                "region01"
            ]
            request.body = CreateInstanceBody(
                template_id="b3ecc9c7-1133-4c47-a06a-21366e227d61",
                enable_publicip=False,
                access_user="",
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.single.xu1.tiny.128",
                capacity=0,
                engine_version="5.0",
                engine="Redis",
                name="dcs-APITest"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listTagsbody = [
                ResourceTag(
                    key="dcs001",
                    value="2"
                ),
                ResourceTag(
                    key="dcs003",
                    value="4"
                )
            ]
            listAzCodesbody = [
                "region01",
                "region02"
            ]
            request.body = CreateInstanceBody(
                rename_commands="{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}",
                port=4040,
                enable_publicip=False,
                access_user="",
                tags=listTagsbody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                instance_num=1,
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                security_group_id="d57fad27-e3e9-43b7-9498-0a698ab63b27",
                subnet_id="7e95c4d6-d7af-424c-a3cf-2be10968fe81",
                vpc_id="c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
                az_codes=listAzCodesbody,
                spec_code="redis.ha.au1.large.2",
                capacity=2,
                engine_version="4.0",
                engine="Redis",
                name="dcs-demo"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

     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 huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listBackupAtPeriodicalBackupPlan = [
                1,
                2,
                3,
                4
            ]
            periodicalBackupPlanInstanceBackupPolicy = BackupPlan(
                backup_at=listBackupAtPeriodicalBackupPlan,
                period_type="weekly",
                begin_at="16:00-17:00"
            )
            instanceBackupPolicybody = BackupPolicy(
                backup_type="auto",
                save_days=3,
                periodical_backup_plan=periodicalBackupPlanInstanceBackupPolicy
            )
            bssParambody = BssParam(
                is_auto_renew="false",
                charging_mode="prePaid",
                is_auto_pay="true",
                period_type="month",
                period_num=1
            )
            listAzCodesbody = [
                "region01",
                "region02"
            ]
            request.body = CreateInstanceBody(
                enable_publicip=False,
                access_user="",
                instance_backup_policy=instanceBackupPolicybody,
                bss_param=bssParambody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                publicip_id="",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.ha.xu1.tiny.r2.128",
                capacity=0,
                engine_version="4.0",
                engine="Redis",
                name="dcs-APITest1"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listBackupAtPeriodicalBackupPlan = [
                1,
                2,
                3,
                4,
                5,
                6,
                7
            ]
            periodicalBackupPlanInstanceBackupPolicy = BackupPlan(
                backup_at=listBackupAtPeriodicalBackupPlan,
                period_type="weekly",
                begin_at="16:00-17:00"
            )
            instanceBackupPolicybody = BackupPolicy(
                backup_type="auto",
                save_days=3,
                periodical_backup_plan=periodicalBackupPlanInstanceBackupPolicy
            )
            bssParambody = BssParam(
                is_auto_renew="false",
                charging_mode="prePaid",
                is_auto_pay="true",
                period_type="month",
                period_num=1
            )
            listAzCodesbody = [
                "region01"
            ]
            request.body = CreateInstanceBody(
                enable_publicip=False,
                access_user="",
                instance_backup_policy=instanceBackupPolicybody,
                bss_param=bssParambody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                publicip_id="",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.cluster.xu1.large.r2.4",
                capacity=4,
                engine_version="4.0",
                engine="Redis",
                name="dcs-APITest2"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listAzCodesbody = []string{
            "region01",
        }
    	templateIdCreateInstanceBody:= "b3ecc9c7-1133-4c47-a06a-21366e227d61"
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "5.0"
    	request.Body = &model.CreateInstanceBody{
    		TemplateId: &templateIdCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.single.xu1.tiny.128",
    		Capacity: float32(0),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	valueTags:= "2"
    	valueTags1:= "4"
    	var listTagsbody = []model.ResourceTag{
            {
                Key: "dcs001",
                Value: &valueTags,
            },
            {
                Key: "dcs003",
                Value: &valueTags1,
            },
        }
    	var listAzCodesbody = []string{
            "region01",
    	    "region02",
        }
    	var renameCommandsCreateInstanceBody interface{} = "{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}"
    	portCreateInstanceBody:= int32(4040)
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	instanceNumCreateInstanceBody:= int32(1)
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	securityGroupIdCreateInstanceBody:= "d57fad27-e3e9-43b7-9498-0a698ab63b27"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		RenameCommands: &renameCommandsCreateInstanceBody,
    		Port: &portCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		Tags: &listTagsbody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		InstanceNum: &instanceNumCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "7e95c4d6-d7af-424c-a3cf-2be10968fe81",
    		VpcId: "c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.ha.au1.large.2",
    		Capacity: float32(2),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-demo",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

      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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listBackupAtPeriodicalBackupPlan = []int32{
            int32(1),
    	    int32(2),
    	    int32(3),
    	    int32(4),
        }
    	periodicalBackupPlanInstanceBackupPolicy := &model.BackupPlan{
    		BackupAt: listBackupAtPeriodicalBackupPlan,
    		PeriodType: "weekly",
    		BeginAt: "16:00-17:00",
    	}
    	saveDaysInstanceBackupPolicy:= int32(3)
    	instanceBackupPolicybody := &model.BackupPolicy{
    		BackupType: "auto",
    		SaveDays: &saveDaysInstanceBackupPolicy,
    		PeriodicalBackupPlan: periodicalBackupPlanInstanceBackupPolicy,
    	}
    	isAutoRenewBssParam:= model.GetBssParamIsAutoRenewEnum().FALSE
    	isAutoPayBssParam:= model.GetBssParamIsAutoPayEnum().TRUE
    	periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH
    	periodNumBssParam:= int32(1)
    	bssParambody := &model.BssParam{
    		IsAutoRenew: &isAutoRenewBssParam,
    		ChargingMode: model.GetBssParamChargingModeEnum().PRE_PAID,
    		IsAutoPay: &isAutoPayBssParam,
    		PeriodType: &periodTypeBssParam,
    		PeriodNum: &periodNumBssParam,
    	}
    	var listAzCodesbody = []string{
            "region01",
    	    "region02",
        }
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	publicipIdCreateInstanceBody:= ""
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		InstanceBackupPolicy: instanceBackupPolicybody,
    		BssParam: bssParambody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		PublicipId: &publicipIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.ha.xu1.tiny.r2.128",
    		Capacity: float32(0),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest1",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

      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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listBackupAtPeriodicalBackupPlan = []int32{
            int32(1),
    	    int32(2),
    	    int32(3),
    	    int32(4),
    	    int32(5),
    	    int32(6),
    	    int32(7),
        }
    	periodicalBackupPlanInstanceBackupPolicy := &model.BackupPlan{
    		BackupAt: listBackupAtPeriodicalBackupPlan,
    		PeriodType: "weekly",
    		BeginAt: "16:00-17:00",
    	}
    	saveDaysInstanceBackupPolicy:= int32(3)
    	instanceBackupPolicybody := &model.BackupPolicy{
    		BackupType: "auto",
    		SaveDays: &saveDaysInstanceBackupPolicy,
    		PeriodicalBackupPlan: periodicalBackupPlanInstanceBackupPolicy,
    	}
    	isAutoRenewBssParam:= model.GetBssParamIsAutoRenewEnum().FALSE
    	isAutoPayBssParam:= model.GetBssParamIsAutoPayEnum().TRUE
    	periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH
    	periodNumBssParam:= int32(1)
    	bssParambody := &model.BssParam{
    		IsAutoRenew: &isAutoRenewBssParam,
    		ChargingMode: model.GetBssParamChargingModeEnum().PRE_PAID,
    		IsAutoPay: &isAutoPayBssParam,
    		PeriodType: &periodTypeBssParam,
    		PeriodNum: &periodNumBssParam,
    	}
    	var listAzCodesbody = []string{
            "region01",
        }
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	publicipIdCreateInstanceBody:= ""
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		InstanceBackupPolicy: instanceBackupPolicybody,
    		BssParam: bssParambody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		PublicipId: &publicipIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.cluster.xu1.large.r2.4",
    		Capacity: float32(4),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest2",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            body.withTemplateId("b3ecc9c7-1133-4c47-a06a-21366e227d61");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.single.xu1.tiny.128");
            body.withCapacity(0f);
            body.withEngineVersion("5.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<ResourceTag> listbodyTags = new ArrayList<>();
            listbodyTags.add(
                new ResourceTag()
                    .withKey("dcs001")
                    .withValue("2")
            );
            listbodyTags.add(
                new ResourceTag()
                    .withKey("dcs003")
                    .withValue("4")
            );
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            listbodyAzCodes.add("region02");
            body.withRenameCommands("{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}");
            body.withPort(4040);
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withTags(listbodyTags);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withInstanceNum(1);
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withSecurityGroupId("d57fad27-e3e9-43b7-9498-0a698ab63b27");
            body.withSubnetId("7e95c4d6-d7af-424c-a3cf-2be10968fe81");
            body.withVpcId("c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.ha.au1.large.2");
            body.withCapacity(2f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-demo");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

     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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<Integer> listPeriodicalBackupPlanBackupAt = new ArrayList<>();
            listPeriodicalBackupPlanBackupAt.add(1);
            listPeriodicalBackupPlanBackupAt.add(2);
            listPeriodicalBackupPlanBackupAt.add(3);
            listPeriodicalBackupPlanBackupAt.add(4);
            BackupPlan periodicalBackupPlanInstanceBackupPolicy = new BackupPlan();
            periodicalBackupPlanInstanceBackupPolicy.withBackupAt(listPeriodicalBackupPlanBackupAt)
                .withPeriodType("weekly")
                .withBeginAt("16:00-17:00");
            BackupPolicy instanceBackupPolicybody = new BackupPolicy();
            instanceBackupPolicybody.withBackupType("auto")
                .withSaveDays(3)
                .withPeriodicalBackupPlan(periodicalBackupPlanInstanceBackupPolicy);
            BssParam bssParambody = new BssParam();
            bssParambody.withIsAutoRenew(BssParam.IsAutoRenewEnum.fromValue("false"))
                .withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(BssParam.IsAutoPayEnum.fromValue("true"))
                .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1);
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            listbodyAzCodes.add("region02");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withInstanceBackupPolicy(instanceBackupPolicybody);
            body.withBssParam(bssParambody);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withPublicipId("");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.ha.xu1.tiny.r2.128");
            body.withCapacity(0f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest1");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

     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
    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.dcs.v2.region.DcsRegion;
    import com.huaweicloud.sdk.dcs.v2.*;
    import com.huaweicloud.sdk.dcs.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            DcsClient client = DcsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstanceBody body = new CreateInstanceBody();
            List<Integer> listPeriodicalBackupPlanBackupAt = new ArrayList<>();
            listPeriodicalBackupPlanBackupAt.add(1);
            listPeriodicalBackupPlanBackupAt.add(2);
            listPeriodicalBackupPlanBackupAt.add(3);
            listPeriodicalBackupPlanBackupAt.add(4);
            listPeriodicalBackupPlanBackupAt.add(5);
            listPeriodicalBackupPlanBackupAt.add(6);
            listPeriodicalBackupPlanBackupAt.add(7);
            BackupPlan periodicalBackupPlanInstanceBackupPolicy = new BackupPlan();
            periodicalBackupPlanInstanceBackupPolicy.withBackupAt(listPeriodicalBackupPlanBackupAt)
                .withPeriodType("weekly")
                .withBeginAt("16:00-17:00");
            BackupPolicy instanceBackupPolicybody = new BackupPolicy();
            instanceBackupPolicybody.withBackupType("auto")
                .withSaveDays(3)
                .withPeriodicalBackupPlan(periodicalBackupPlanInstanceBackupPolicy);
            BssParam bssParambody = new BssParam();
            bssParambody.withIsAutoRenew(BssParam.IsAutoRenewEnum.fromValue("false"))
                .withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(BssParam.IsAutoPayEnum.fromValue("true"))
                .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1);
            List<String> listbodyAzCodes = new ArrayList<>();
            listbodyAzCodes.add("region01");
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withInstanceBackupPolicy(instanceBackupPolicybody);
            body.withBssParam(bssParambody);
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withMaintainEnd("19:00:00");
            body.withMaintainBegin("18:00:00");
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withPublicipId("");
            body.withSecurityGroupId("securityGroupId");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.cluster.xu1.large.r2.4");
            body.withCapacity(4f);
            body.withEngineVersion("4.0");
            body.withEngine("Redis");
            body.withName("dcs-APITest2");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listAzCodesbody = [
                "region01"
            ]
            request.body = CreateInstanceBody(
                template_id="b3ecc9c7-1133-4c47-a06a-21366e227d61",
                enable_publicip=False,
                access_user="",
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.single.xu1.tiny.128",
                capacity=0,
                engine_version="5.0",
                engine="Redis",
                name="dcs-APITest"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listTagsbody = [
                ResourceTag(
                    key="dcs001",
                    value="2"
                ),
                ResourceTag(
                    key="dcs003",
                    value="4"
                )
            ]
            listAzCodesbody = [
                "region01",
                "region02"
            ]
            request.body = CreateInstanceBody(
                rename_commands="{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}",
                port=4040,
                enable_publicip=False,
                access_user="",
                tags=listTagsbody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                instance_num=1,
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                security_group_id="d57fad27-e3e9-43b7-9498-0a698ab63b27",
                subnet_id="7e95c4d6-d7af-424c-a3cf-2be10968fe81",
                vpc_id="c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
                az_codes=listAzCodesbody,
                spec_code="redis.ha.au1.large.2",
                capacity=2,
                engine_version="4.0",
                engine="Redis",
                name="dcs-demo"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

     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 huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listBackupAtPeriodicalBackupPlan = [
                1,
                2,
                3,
                4
            ]
            periodicalBackupPlanInstanceBackupPolicy = BackupPlan(
                backup_at=listBackupAtPeriodicalBackupPlan,
                period_type="weekly",
                begin_at="16:00-17:00"
            )
            instanceBackupPolicybody = BackupPolicy(
                backup_type="auto",
                save_days=3,
                periodical_backup_plan=periodicalBackupPlanInstanceBackupPolicy
            )
            bssParambody = BssParam(
                is_auto_renew="false",
                charging_mode="prePaid",
                is_auto_pay="true",
                period_type="month",
                period_num=1
            )
            listAzCodesbody = [
                "region01",
                "region02"
            ]
            request.body = CreateInstanceBody(
                enable_publicip=False,
                access_user="",
                instance_backup_policy=instanceBackupPolicybody,
                bss_param=bssParambody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                publicip_id="",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.ha.xu1.tiny.r2.128",
                capacity=0,
                engine_version="4.0",
                engine="Redis",
                name="dcs-APITest1"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(DcsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listBackupAtPeriodicalBackupPlan = [
                1,
                2,
                3,
                4,
                5,
                6,
                7
            ]
            periodicalBackupPlanInstanceBackupPolicy = BackupPlan(
                backup_at=listBackupAtPeriodicalBackupPlan,
                period_type="weekly",
                begin_at="16:00-17:00"
            )
            instanceBackupPolicybody = BackupPolicy(
                backup_type="auto",
                save_days=3,
                periodical_backup_plan=periodicalBackupPlanInstanceBackupPolicy
            )
            bssParambody = BssParam(
                is_auto_renew="false",
                charging_mode="prePaid",
                is_auto_pay="true",
                period_type="month",
                period_num=1
            )
            listAzCodesbody = [
                "region01"
            ]
            request.body = CreateInstanceBody(
                enable_publicip=False,
                access_user="",
                instance_backup_policy=instanceBackupPolicybody,
                bss_param=bssParambody,
                no_password_access=False,
                password="********",
                maintain_end="19:00:00",
                maintain_begin="18:00:00",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                publicip_id="",
                security_group_id="securityGroupId",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.cluster.xu1.large.r2.4",
                capacity=4,
                engine_version="4.0",
                engine="Redis",
                name="dcs-APITest2"
            )
            response = client.create_instance(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个按需计费的Redis单机实例,缓存版本是5.0,缓存容量是0.125GB。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listAzCodesbody = []string{
            "region01",
        }
    	templateIdCreateInstanceBody:= "b3ecc9c7-1133-4c47-a06a-21366e227d61"
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "5.0"
    	request.Body = &model.CreateInstanceBody{
    		TemplateId: &templateIdCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.single.xu1.tiny.128",
    		Capacity: float32(0),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个按需计费的Redis主备实例,缓存容量2GB,设置了标签、自定义端口、高危命令重命名和跨可用区部署。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	valueTags:= "2"
    	valueTags1:= "4"
    	var listTagsbody = []model.ResourceTag{
            {
                Key: "dcs001",
                Value: &valueTags,
            },
            {
                Key: "dcs003",
                Value: &valueTags1,
            },
        }
    	var listAzCodesbody = []string{
            "region01",
    	    "region02",
        }
    	var renameCommandsCreateInstanceBody interface{} = "{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}"
    	portCreateInstanceBody:= int32(4040)
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	instanceNumCreateInstanceBody:= int32(1)
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	securityGroupIdCreateInstanceBody:= "d57fad27-e3e9-43b7-9498-0a698ab63b27"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		RenameCommands: &renameCommandsCreateInstanceBody,
    		Port: &portCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		Tags: &listTagsbody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		InstanceNum: &instanceNumCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "7e95c4d6-d7af-424c-a3cf-2be10968fe81",
    		VpcId: "c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.ha.au1.large.2",
    		Capacity: float32(2),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-demo",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个包周期的Redis主备实例,缓存版本是4.0,缓存容量是0.125GB,设置了备份策略和跨可用区部署。

      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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listBackupAtPeriodicalBackupPlan = []int32{
            int32(1),
    	    int32(2),
    	    int32(3),
    	    int32(4),
        }
    	periodicalBackupPlanInstanceBackupPolicy := &model.BackupPlan{
    		BackupAt: listBackupAtPeriodicalBackupPlan,
    		PeriodType: "weekly",
    		BeginAt: "16:00-17:00",
    	}
    	saveDaysInstanceBackupPolicy:= int32(3)
    	instanceBackupPolicybody := &model.BackupPolicy{
    		BackupType: "auto",
    		SaveDays: &saveDaysInstanceBackupPolicy,
    		PeriodicalBackupPlan: periodicalBackupPlanInstanceBackupPolicy,
    	}
    	isAutoRenewBssParam:= model.GetBssParamIsAutoRenewEnum().FALSE
    	isAutoPayBssParam:= model.GetBssParamIsAutoPayEnum().TRUE
    	periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH
    	periodNumBssParam:= int32(1)
    	bssParambody := &model.BssParam{
    		IsAutoRenew: &isAutoRenewBssParam,
    		ChargingMode: model.GetBssParamChargingModeEnum().PRE_PAID,
    		IsAutoPay: &isAutoPayBssParam,
    		PeriodType: &periodTypeBssParam,
    		PeriodNum: &periodNumBssParam,
    	}
    	var listAzCodesbody = []string{
            "region01",
    	    "region02",
        }
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	publicipIdCreateInstanceBody:= ""
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		InstanceBackupPolicy: instanceBackupPolicybody,
    		BssParam: bssParambody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		PublicipId: &publicipIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.ha.xu1.tiny.r2.128",
    		Capacity: float32(0),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest1",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个包周期的Redis Cluster集群实例,缓存版本是4.0,缓存容量是4GB,设置了备份策略。

      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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
            dcs.DcsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	var listBackupAtPeriodicalBackupPlan = []int32{
            int32(1),
    	    int32(2),
    	    int32(3),
    	    int32(4),
    	    int32(5),
    	    int32(6),
    	    int32(7),
        }
    	periodicalBackupPlanInstanceBackupPolicy := &model.BackupPlan{
    		BackupAt: listBackupAtPeriodicalBackupPlan,
    		PeriodType: "weekly",
    		BeginAt: "16:00-17:00",
    	}
    	saveDaysInstanceBackupPolicy:= int32(3)
    	instanceBackupPolicybody := &model.BackupPolicy{
    		BackupType: "auto",
    		SaveDays: &saveDaysInstanceBackupPolicy,
    		PeriodicalBackupPlan: periodicalBackupPlanInstanceBackupPolicy,
    	}
    	isAutoRenewBssParam:= model.GetBssParamIsAutoRenewEnum().FALSE
    	isAutoPayBssParam:= model.GetBssParamIsAutoPayEnum().TRUE
    	periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH
    	periodNumBssParam:= int32(1)
    	bssParambody := &model.BssParam{
    		IsAutoRenew: &isAutoRenewBssParam,
    		ChargingMode: model.GetBssParamChargingModeEnum().PRE_PAID,
    		IsAutoPay: &isAutoPayBssParam,
    		PeriodType: &periodTypeBssParam,
    		PeriodNum: &periodNumBssParam,
    	}
    	var listAzCodesbody = []string{
            "region01",
        }
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	maintainEndCreateInstanceBody:= "19:00:00"
    	maintainBeginCreateInstanceBody:= "18:00:00"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	publicipIdCreateInstanceBody:= ""
    	securityGroupIdCreateInstanceBody:= "securityGroupId"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		InstanceBackupPolicy: instanceBackupPolicybody,
    		BssParam: bssParambody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		MaintainEnd: &maintainEndCreateInstanceBody,
    		MaintainBegin: &maintainBeginCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		PublicipId: &publicipIdCreateInstanceBody,
    		SecurityGroupId: &securityGroupIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.cluster.xu1.large.r2.4",
    		Capacity: float32(4),
    		EngineVersion: &engineVersionCreateInstanceBody,
    		Engine: "Redis",
    		Name: "dcs-APITest2",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

下发创建缓存实例任务成功。

说明:

查看实例状态为RUNNING时,即缓存实例创建成功。

400

非法请求。

401

认证信息非法。

403

请求被拒绝访问。

404

所请求的资源不存在。

500

内部服务错误。

错误码

请参见错误码

提示

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

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容