Creating a DCS Instance
Function
This API is used to create a DCS instance which is billed in pay-per-use mode or yearly/monthly mode.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
dcs:instance:create
Write
-
-
g:EnterpriseProjectId
-
g:RequestTag/<tag-key>
-
g:TagKeys
-
dcs:backupEnabled
-
- vpc:ports:get
- vpc:ports:create
- vpc:ports:update
- vpc:ports:delete
- vpc:subnets:get
- vpc:securityGroupRules:get
- vpc:securityGroups:get
-
URI
POST /v2/{project_id}/instances
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Definition: Project ID. For details, see Obtaining a Project ID. Constraints: N/A Range: N/A Default Value: N/A |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
name |
Yes |
String |
Definition: An instance name can contain letters, digits, underscores (_), and hyphens (-) and must start with a letter. Constraints: When you create only one instance at a time, the value of this parameter can contain 4 to 64 characters. When you create multiple instances at a time, the value of this parameter can contain 4 to 56 characters. The instances are named in the format of custom name-n, where n starts from 000 and is incremented by 1. For example, if you create two instances and set the custom name to dcs_demo, the two instances are respectively named dcs_demo-000 and dcs_demo-001. Range: N/A Default Value: N/A |
|
engine |
Yes |
String |
Definition Cache engine: Redis. Constraints N/A Range Redis Default Value N/A |
|
engine_version |
No |
String |
Definition Redis cache engine. Constraints N/A Range 4.0, 5.0, 6.0, 7.0 Default Value N/A |
|
capacity |
Yes |
Float |
Definition Cache capacity (GB). Constraints N/A Range
Default Value N/A |
|
spec_code |
Yes |
String |
Definition: Product flavor. The query method is as follows:
Constraints: N/A Range: N/A Default Value: N/A |
|
az_codes |
Yes |
Array of strings |
Definition: ID of the AZ where the cache node resides and which has available resources. For details, see Querying AZs. Check whether the desired AZ has available resources. Master/standby, Proxy Cluster, and Redis Cluster DCS instances support cross-AZ deployment. You can specify an AZ for the standby node. When specifying AZs for nodes, use commas (,) to separate multiple AZs. For details, see the example request. Constraints: N/A |
|
vpc_id |
Yes |
String |
Definition: ID of the VPC where the DCS instance is located. You can obtain the value as follows:
Constraints: N/A Range: N/A Default Value: N/A |
|
subnet_id |
Yes |
String |
Definition Network ID of the subnet. To obtain the value:
Constraints N/A Range N/A Default Value N/A |
|
security_group_id |
No |
String |
Definition Security group to which the instance belongs. This parameter is optional when the engine is Redis and the version is 4.0 or later basic edition. DCS Redis 4.0 and later basic edition instances do not support security groups (default value securityGroupId will be used). They support only whitelist-based access control. To obtain the value:
Constraints N/A Range N/A Default Value N/A |
|
publicip_id |
No |
String |
Definition ID of the EIP bound to the DCS Redis instance. This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true). Constraints N/A Range N/A Default Value N/A |
|
enterprise_project_id |
No |
String |
Definition: Enterprise project ID. Constraints: N/A Range: N/A Default Value: N/A |
|
description |
No |
String |
Definition: Description of an instance. The backslash () and quotation mark (") are special characters for JSON messages. When using these characters in a parameter value, add the escape character () before the characters, for example, \ and ". Constraints: 0–1,024 characters Range: N/A Default Value: N/A |
|
enable_ssl |
No |
Boolean |
Definition Whether to enable SSL for public access to DCS Redis 3.0 instances. This parameter is available only for DCS Redis 3.0 instances. Constraints 0–1024 characters. Range
Default Value false |
|
enable_ipv6 |
No |
Boolean |
Definition Whether IPv4/IPv6 dual-stack access is enabled. Note that IPv6 must also be enabled for the subnet. Constraints 0–1024 characters. Range true: Yes false: No Default Value false |
|
private_ip |
No |
String |
Definition IP address that is specified for a DCS instance. Constraints N/A Range N/A Default Value N/A |
|
instance_num |
No |
Integer |
Definition: Number of instances to be created in batches. Constraints: N/A Range: 1–100 Default Value: 1 |
|
maintain_begin |
No |
String |
Definition Start time of the maintenance time window. Constraints The value must be a UTC time in the format of HH:mm:ss. - The start time and end time of the maintenance time window must indicate the time segment of a supported maintenance time window. For details, see [Listing Maintenance Time Windows] (ListMaintenanceWindows.xml).
Range N/A Default Value 18:00:00 |
|
maintain_end |
No |
String |
Definition End time of the maintenance time window. Constraints The value must be a UTC time in the format of HH:mm:ss. - The start time and end time of the maintenance time window must indicate the time segment of a supported maintenance time window. For details, see [Listing Maintenance Time Windows] (ListMaintenanceWindows.xml).
Range N/A Default Value 19:00:00 |
|
password |
No |
String |
Definition Password of a DCS instance. When no_password_access is set to false or not specified, the request must contain the password parameter. Constraints The password of a DCS Redis instance must meet the following complexity requirements:
N/A Default Value N/A |
|
no_password_access |
No |
Boolean |
Definition: Indicates whether password-protected access is enabled for the instance. Constraints: N/A Range:
Default Value: false |
|
bss_param |
No |
BssParam object |
Definition: Parameter related to the billing mode. If this parameter is left blank, the billing mode is pay-per-use by default. If this parameter is not left blank, the billing mode is yearly/monthly. Constraints: This parameter is mandatory for yearly/monthly instances. |
|
instance_backup_policy |
No |
BackupPolicy object |
Definition: Backup policy. Constraints: This parameter is supported when the instance type is master/standby or cluster. |
|
tags |
No |
Array of ResourceTag objects |
Definition: Instance tag key and value. Constraints: N/A |
|
access_user |
No |
String |
Definition: If the cache engine is Redis, you do not need to set this parameter. Constraints: N/A Range: N/A Default Value: N/A |
|
enable_publicip |
No |
Boolean |
Definition Whether public access is enabled for a DCS Redis 3.0 instance. Constraints N/A Range
Default Value false |
|
port |
No |
Integer |
Definition Port customization. Constraints Supported only by Redis 4.0 and later basic edition instances and not by professional edition instances. The default port 6379 is used. If this parameter is not sent or is left empty when you create a Redis instance, the default port 6379 will be used. To customize a port, specify a port number in the range from 1 to 65535. Range 1–65535 Default Value 6379 |
|
rename_commands |
No |
Object |
Definition Critical commands can be renamed. If this parameter is not sent or is left empty when you create a Redis instance, no critical command will be renamed. Constraints This is supported only by Redis 4.0 and later instances Range Currently, you can only rename the COMMAND, KEYS, FLUSHDB, FLUSHALL, HGETALL, SCAN, HSCAN, SSCAN, and ZSCAN commands. For Proxy Cluster instances, you can also rename the DBSIZE and DBSTATS commands. Default Value N/A |
|
template_id |
No |
String |
Definition: Parameter template ID. The default template is used when no ID is specified. To specify a custom parameter template, obtain the template ID by referring to Viewing Parameter Templates. Constraints: N/A Range: N/A Default Value: N/A |
|
spec_param |
No |
SpecParam object |
Parameter description: Specification parameter. Mandatory when a linear specification of node spec_type is created. Constraints: N/A |
|
backup_id |
No |
String |
Definition: Backup ID, which is used to restore an instance. Constraints: N/A Range: N/A Default Value: N/A |
|
recover_instance_id |
No |
String |
Definition: ID of the instance restored from the recycle bin. Constraints: N/A Range: N/A Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
is_auto_renew |
No |
String |
Definition Whether to automatically renew resources. This parameter is mandatory when the billing mode is yearly/monthly. Constraints If this parameter is set to true, when the subscription expires, the system automatically renews it for one month by default (the length of the renewal is subject to changes). For details, contact customer service. Range
Default Value false |
|
charging_mode |
Yes |
String |
Definition This parameter specifies a payment mode. If this parameter is set to postPaid, other fields of the bss_param parameter are left unspecified. Constraints N/A Range prePaid: yearly/monthly billing mode postPaid: pay-per-use Default Value postPaid |
|
is_auto_pay |
No |
String |
Definition Whether the payment will be automatically deducted from customer's account balance when an order is submitted. Constraints If this parameter is set to true, the automatic payment can only be completed with the account balance. If you want to use cash coupons, set this parameter to false and go to the Billing Center to make the payment. If this parameter is set to false, go to Billing Center > Orders to pay for the order after modifying specifications or creating an instance. Otherwise, the order is always pending payment and the instance modification or creation is not considered successful. Range
Default Value false |
|
period_type |
No |
String |
Definition: Subscription period type. Constraints: This parameter is mandatory when you select the yearly/monthly billing mode. Range:
Default Value: N/A |
|
period_num |
No |
Integer |
Definition: Number of subscription periods. Constraints: This parameter is mandatory when you select the yearly/monthly billing mode. Range: (subject to change due to operation policy change)
Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
backup_type |
Yes |
String |
Definition: Backup type. Constraints: N/A Range:
Default Value: N/A |
|
save_days |
No |
Integer |
Definition: This parameter is mandatory when backup_type is set to manual. Retention period, in days. The value ranges from 1 to 7. The automatic backup policy is retained when automatic backup is switched to manual backup. Constraints: N/A Range: N/A Default Value: N/A |
|
periodical_backup_plan |
No |
BackupPlanRequst object |
Definition: Backup plan. Constraints: This parameter is mandatory when backup_type is set to manual. The automatic backup policy is retained when automatic backup is switched to manual backup. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
timezone_offset |
No |
String |
Definition: Time zone of the backup. This parameter is no longer used. Constraints: N/A Range: N/A Default Value: N/A |
|
backup_at |
Yes |
Array of integers |
Definition: Day on which the backup starts every week. The automatic backup policy is retained when automatic backup is switched to manual backup. 1–7: Monday to Sunday Constraints: N/A |
|
period_type |
Yes |
String |
Definition: Interval at which backup is performed, which supports only weekly currently. The automatic backup policy is retained when automatic backup is switched to manual backup. Constraints: N/A Range: N/A Default Value: N/A |
|
begin_at |
Yes |
String |
Definition: UTC time when the backup starts. For example, 00:00–01:00 indicates that the backup starts at 00:00 (UTC time). The value must be on the hour. The backup interval is 1 hour. The automatic backup policy is retained when automatic backup is switched to manual backup. Constraints: N/A Range: N/A Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
key |
Yes |
String |
Definition: Tag key. Constraints:
Range: N/A Default Value: N/A |
|
value |
No |
String |
Definition: Tag value. Constraints:
Range: N/A Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
sharding_count |
No |
Integer |
Parameter description: Number of instance shards. Constraints: N/A Value range: 1–128 Default value: N/A |
|
replica_count |
No |
Integer |
Definition: Number of instance replicas. Constraints: N/A Range: 1–10 Default Value: N/A |
|
cache_mode |
No |
String |
Definition DCS instance type. Constraints N/A Range
Default Value N/A |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
instances |
Array of Instances objects |
Definition: DCS instance ID and name. If multiple DCS instances are created at a time, multiple DCS instance IDs and names will be returned. |
|
Parameter |
Type |
Description |
|---|---|---|
|
instance_id |
String |
Definition: DCS instance ID. Range: N/A |
|
instance_name |
String |
Definition: DCS instance name. Range: N/A |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_msg |
String |
Parameter description: Error message. Value range: N/A. |
|
error_code |
String |
Parameter description: Error code. Value range: For details, see Error Codes. |
|
error_ext_msg |
String |
Parameter description: Extended error information. This parameter is not used currently and is set to null. Value range: N/A. |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
error_msg |
String |
Parameter description: Error message. Value range: N/A. |
|
error_code |
String |
Parameter description: Error code. Value range: For details, see Error Codes. |
|
error_ext_msg |
String |
Parameter description: Extended error information. This parameter is not used currently and is set to null. Value range: N/A. |
Status code: 403
|
Parameter |
Type |
Description |
|---|---|---|
|
error_msg |
String |
Parameter description: Error message. Value range: N/A. |
|
error_code |
String |
Parameter description: Error code. Value range: For details, see Error Codes. |
|
error_ext_msg |
String |
Parameter description: Extended error information. This parameter is not used currently and is set to null. Value range: N/A. |
Status code: 404
|
Parameter |
Type |
Description |
|---|---|---|
|
error_msg |
String |
Parameter description: Error message. Value range: N/A. |
|
error_code |
String |
Parameter description: Error code. Value range: For details, see Error Codes. |
|
error_ext_msg |
String |
Parameter description: Extended error information. This parameter is not used currently and is set to null. Value range: N/A. |
Status code: 500
|
Parameter |
Type |
Description |
|---|---|---|
|
error_msg |
String |
Parameter description: Error message. Value range: N/A. |
|
error_code |
String |
Parameter description: Error code. Value range: For details, see Error Codes. |
|
error_ext_msg |
String |
Parameter description: Extended error information. This parameter is not used currently and is set to null. Value range: N/A. |
Example Requests
-
Creating a 0.125 GB single-node DCS Redis 5.0 instance billed in pay-per-use mode
POST https://{dcs_endpoint}/v2/{project_id}/instances { "name" : "dcs-APITest", "description" : "Test", "engine" : "Redis", "engine_version" : 5.0, "enterprise_project_id" : 0, "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" } -
Creating a 2 GB master/standby DCS Redis instance, which is billed in pay-per-use mode and with tags configured, a port customized, high-risk commands renamed, and cross-AZ deployment
{ "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 } ] } -
Creating a 0.125 GB master/standby DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy and cross-AZ deployment
{ "publicip_id" : "", "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 } } -
Creating a 4 GB Redis Cluster DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy
{ "publicip_id" : "", "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 ] } } }
Example Responses
Status code: 200
The DCS instance creation task is delivered successfully.
-
Example 1
{ "instances" : [ { "instance_id" : "3c49fd6b-fc7c-419e-9644-b6cce008653f", "instance_name" : "dcs-test005" } ] } -
Example 2
{ "order_id" : "CS2005091653L2DAM", "instances" : [ { "instance_id" : "77284d69-cd51-4bf1-aa30-2e60f055800c", "instance_name" : "dcs-APITest1" } ] }
SDK Sample Code
The SDK sample code is as follows.
-
Creating a 0.125 GB single-node DCS Redis 5.0 instance billed in pay-per-use mode
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
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.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()); } } }
-
Creating a 2 GB master/standby DCS Redis instance, which is billed in pay-per-use mode and with tags configured, a port customized, high-risk commands renamed, and cross-AZ deployment
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
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.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()); } } }
-
Creating a 0.125 GB master/standby DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy and cross-AZ deployment
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 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.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()); } } }
-
Creating a 4 GB Redis Cluster DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
package 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.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()); } } }
-
Creating a 0.125 GB single-node DCS Redis 5.0 instance billed in pay-per-use mode
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
# 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_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)
-
Creating a 2 GB master/standby DCS Redis instance, which is billed in pay-per-use mode and with tags configured, a port customized, high-risk commands renamed, and cross-AZ deployment
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
# 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_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)
-
Creating a 0.125 GB master/standby DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy and cross-AZ deployment
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
# 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_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)
-
Creating a 4 GB Redis Cluster DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy
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
# 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_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)
-
Creating a 0.125 GB single-node DCS Redis 5.0 instance billed in pay-per-use mode
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
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" 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, 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) } }
-
Creating a 2 GB master/standby DCS Redis instance, which is billed in pay-per-use mode and with tags configured, a port customized, high-risk commands renamed, and cross-AZ deployment
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
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" 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, 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) } }
-
Creating a 0.125 GB master/standby DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy and cross-AZ deployment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" 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" 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, 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) } }
-
Creating a 4 GB Redis Cluster DCS Redis 4.0 instance billed in yearly/monthly mode with a backup policy
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), 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" 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, 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) } }
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
The DCS instance creation task is delivered successfully.
NOTE:
If the instance status is RUNNING, the DCS instance has been successfully created.
|
|
400 |
Invalid request. |
|
401 |
Invalid authentication information. |
|
403 |
Request rejected. |
|
404 |
The requested resource is not found. |
|
500 |
Internal service error. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot