创建缓存实例
功能介绍
创建缓存实例,该接口创建的缓存实例支持按需和包周期两种计费方式。
调用方法
请参见如何调用API。
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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)
|
spec_code |
是 |
String |
产品规格编码。具体查询方法如下:
|
az_codes |
是 |
Array of strings |
创建缓存节点到指定且有资源的可用区Code。具体查询方法,请参考查询可用区信息,在查询时,请注意查看该可用区是否有资源。 如果是创建主备、Proxy集群、Cluster集群实例,支持跨可用区部署,可以为备节点指定备可用区。在为节点指定可用区时,用逗号分隔开,具体请查看示例。 |
vpc_id |
是 |
String |
虚拟私有云ID。 获取方法如下:
|
subnet_id |
是 |
String |
子网的网络ID。 获取方法如下:
|
security_group_id |
否 |
String |
指定实例所属的安全组。 当engine为Redis且engine_version为4.0/5.0/6.0时,该参数为可选。Redis4.0、Redis5.0、Redis6.0版本基础版实例不支持安全组控制访问(会设置为默认参数值securityGroupId),只支持白名单控制。 获取方法如下:
|
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实例,其他版本不涉及。
|
private_ip |
否 |
String |
创建缓存实例手动指定的IP地址。 |
instance_num |
否 |
Integer |
表示批量创建缓存实例时,创建的实例个数。 默认值:1 取值范围:1-100 |
maintain_begin |
否 |
String |
维护时间窗开始时间,为UTC时间,格式为HH:mm:ss
|
maintain_end |
否 |
String |
维护时间窗结束时间,为UTC时间,格式为HH:mm:ss。
|
password |
否 |
String |
缓存实例的认证信息。
说明:
当“no_password_access”配置为“false”或未配置时,请求消息中须包含password参数。 Redis类型的缓存实例密码复杂度要求:
|
no_password_access |
否 |
Boolean |
是否允许免密码访问缓存实例。
|
bss_param |
否 |
BssParam object |
表示计费模式的相关参数。置空时,默认计费模式为按需计费;否则是包周期方式。 |
instance_backup_policy |
否 |
BackupPolicy object |
备份策略,实例类型为主备和集群时支持。 |
tags |
否 |
Array of ResourceTag objects |
实例标签键值。 |
access_user |
否 |
String |
缓存类型为Redis时,不需要设置,保持为空即可。 |
enable_publicip |
否 |
Boolean |
Redis 3.0缓存实例是否开启公网访问功能。
|
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。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
is_auto_renew |
否 |
String |
当选择包年包月时,该字段为必选,表示是否自动续订资源。 取值范围:
|
charging_mode |
是 |
String |
功能说明:付费方式(预付费、按需付费;预付费,即包周期付费)。 取值范围:
|
is_auto_pay |
否 |
String |
功能说明:下单订购后,是否自动从客户的账户中支付;默认是“不自动支付” 。 取值范围:
约束: 自动支付时,只能使用账户的现金支付;如果要使用代金券,请选择不自动支付,然后在用户费用中心,选择代金券支付。 如果包周期购买,没有设置成自动支付,即设置为false时,在变更规格或创建实例之后,用户必须在“费用中心 > 我的订单”,完成订单支付,否则订单一直在支付中,实例没有变更或者创建成功。 |
period_type |
否 |
String |
当选择包年包月时,该字段为必选,表示订购资源的周期类型。 取值范围如下:
|
period_num |
否 |
Integer |
功能说明:订购周期数。 当选择按需时,该字段非必选。 [取值范围:(后续会随运营策略变化)
约束:同period_type约束。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
backup_type |
是 |
String |
备份类型。
|
save_days |
否 |
Integer |
当backup_type设置为auto时,该参数为必填。 保留天数,单位:天,取值范围:1-7。由自动切换为手动时,保留自动备份策略信息。 |
periodical_backup_plan |
否 |
BackupPlan object |
备份计划,当backup_type设置为auto时,该参数为必填。由自动切换为手动时,保留自动备份策略信息。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
timezone_offset |
否 |
String |
备份的时区。该参数已废弃,没有实际作用。 |
backup_at |
是 |
Array of integers |
每周的周几开始备份,取值1-7,1代表周一,7代表周日。由自动切换为手动时,保留自动备份策略信息。 |
period_type |
是 |
String |
备份周期类型,目前支持“weekly”。由自动切换为手动时,保留自动备份策略信息。 |
begin_at |
是 |
String |
备份开始执行时间,该时间为UTC时间,例如“00:00-01:00”代表UTC时间0点开始执行备份。只能是整点时间段,间隔时间限定为一个小时。由自动切换为手动时,保留自动备份策略信息。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
order_id |
String |
订单ID,仅在创建包周期实例时返回。 |
instances |
Array of Instances objects |
缓存实例ID和名称,如果批量创建实例,则会返回多个。 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_msg |
String |
错误信息。 |
error_code |
String |
错误码。 |
error_ext_msg |
String |
扩展错误信息(暂未使用,赋值为null)。 |
状态码: 401
参数 |
参数类型 |
描述 |
---|---|---|
error_msg |
String |
错误信息。 |
error_code |
String |
错误码。 |
error_ext_msg |
String |
扩展错误信息(暂未使用,赋值为null)。 |
状态码: 403
参数 |
参数类型 |
描述 |
---|---|---|
error_msg |
String |
错误信息。 |
error_code |
String |
错误码。 |
error_ext_msg |
String |
扩展错误信息(暂未使用,赋值为null)。 |
状态码: 404
参数 |
参数类型 |
描述 |
---|---|---|
error_msg |
String |
错误信息。 |
error_code |
String |
错误码。 |
error_ext_msg |
String |
扩展错误信息(暂未使用,赋值为null)。 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
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代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
下发创建缓存实例任务成功。
说明:
查看实例状态为RUNNING时,即缓存实例创建成功。 |
400 |
非法请求。 |
401 |
认证信息非法。 |
403 |
请求被拒绝访问。 |
404 |
所请求的资源不存在。 |
500 |
内部服务错误。 |
错误码
请参见错误码。