Updated on 2024-11-06 GMT+08:00

Creating a DCS Instance

Function

This API is used to create a DCS instance which is billed in pay-per-use mode.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/instances

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Instance name.

An instance name can contain letters, digits, underscores (_), and hyphens (-) and must start with a letter or digit.

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.

engine

Yes

String

Cache engine: Redis or Memcached.

engine_version

No

String

Cache version.

If the cache engine is Redis, this parameter is mandatory. The version can be 3.0/4.0/5.0/6.0.

If the cache engine is Memcached, this parameter is optional and can be left blank.

capacity

Yes

Float

Cache capacity (GB).

  • For a single-node or master/standby DCS Redis 3.0 instance, the value can be 2, 4, 8, 16, 32, or 64. For a Proxy Cluster DCS Redis instance, the value can be 64, 128, 256, 512, or 1024.

  • For a single-node or master/standby DCS Redis 4.0/5.0/6.0 instance, the value can be 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, or 64. For a cluster instance, the value can be 4, 8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, or 1024. For a read/write splitting DCS Redis 4.0/5.0 instance, the value can be 8, 16, 32, or 64.

  • For a single-node or master/standby DCS Memcached instance, the value can be 2, 4, 8, 16, 32, or 64.

spec_code

Yes

String

Product flavor. The query method is as follows:

az_codes

Yes

Array of strings

Code 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, read/write splitting, 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.

vpc_id

Yes

String

VPC ID.

To obtain it, do as follows:

  • Method 1: Log in to the VPC console and view the VPC ID on the My VPCs page.

  • Method 2: Call the VPC API. For details, see Querying VPCs.

subnet_id

Yes

String

Network ID of the subnet.

To obtain it, do as follows:

  • Method 1: Log in to VPC console and click the target subnet on the Subnets tab page. You can view the network ID on the displayed page.

  • Method 2: Call the VPC API. For details, see Querying Subnets.

security_group_id

No

String

Security group to which the instance belongs.

This parameter is mandatory only when engine is set to Memcached. Memcached instances support access control based on security groups.

Basic edition DCS Redis 4.0 and later instances do not support security groups but whitelists.

You can obtain it in either of the following ways:

  • Method 1: Log in to the VPC console and view the security group ID on the security group details page.

  • Method 2: Call the API used to query security group details. For details, see Querying Security Group Details.

publicip_id

No

String

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

enterprise_project_id

No

String

Enterprise project ID.

enterprise_project_name

No

String

Enterprise project name.

description

No

String

Instance description.

The description can contain a maximum of 1024 characters.

NOTE:

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 \".

enable_ssl

No

Boolean

Whether to enable SSL for public access to a DCS Redis instance. This parameter is only supported by DCS Redis 3.0 instances.

  • true: enable

  • false: disable

private_ip

No

String

IP address that is specified for a DCS instance.

instance_num

No

Integer

Number of instances to be created in batches. This parameter is available for DCS Redis and Memcached instances.

Default value: 1.

Value range: 1 to 100

maintain_begin

No

String

UTC time when the maintenance time window starts. The format is HH:mm:ss.

  • The start time and end time of the maintenance window must be within the time segment of a supported maintenance window. For details, see Listing Maintenance Time Windows.

  • For example, the start time must be on the hour, such as 18:00:00 and 19:00:00.

  • The start time and end time must be set in pairs. If the start time is left blank, the end time must also be left blank. In this case, the system automatically sets the start time to 18:00:00.

maintain_end

No

String

UTC time when the maintenance time window ends. The format is HH:mm:ss.

  • The start time and end time of the maintenance window must be within the time segment of a supported maintenance window. For details, see Listing Maintenance Time Windows.

  • The end time is one hour later than the start time. For example, if the start time is 18:00:00, the end time is 19:00:00.

  • The start time and end time must be set in pairs. If the end time is left blank, the start time is also left blank. In this case, the system automatically sets the end time to 19:00:00.

password

No

String

Password of a DCS instance.

NOTE:

When no_password_access is set to false or not specified, the request must contain the password parameter.

The password of a DCS Redis instance must meet the following complexity requirements:

  • Can contain 8 to 64 characters.

  • The new password must be different from the old password.

  • Must contain at least three of the following character types:

    • Lowercase letters

    • Uppercase letters

    • Digits

    • Special characters `~!@#$^&*()-_=+\|{},<.>/?

no_password_access

No

Boolean

Whether the instance can be accessed without a password.

  • true: The instance can be accessed without a password.

  • false: The instance can be accessed only after password authentication.

    If this parameter is not set, the default value false is used.

bss_param

No

BssParam object

Parameter related to the billing mode. If this parameter is left blank, the default billing mode is pay-per-use. Other billing modes are not supported.

instance_backup_policy

No

BackupPolicy object

Backup policy. This parameter is supported when the instance type is master/standby or cluster.

tags

No

Array of ResourceTag objects

Instance tag key and value.

access_user

No

String

If the cache engine is Redis, leave this parameter empty.

If the cache engine is Memcached and no_password_access is set to false, this parameter is required, indicating that you need to access the DCS instance in password mode.

A username can contain 1 to 64 characters and must start with a letter. Only letters, digits, underscores (_), and hyphens (-) are allowed.

  • This parameter is optional if the cache engine is Memcached.

enable_publicip

No

Boolean

Indicates whether to enable public access for DCS Redis 3.0 instances.

  • true: enable

  • false: disable

port

No

Integer

Port customization. This parameter is supported only by Redis 4.0 and later instances and not by Redis 3.0 and Memcached instances.

If this parameter is not sent or is left empty when you create a Redis 4.0 or later instance, the default port 6379 will be used. To customize a port, specify a port number in the range from 1 to 65535.

rename_commands

No

Object

Critical commands can be renamed.

If this parameter is not sent or is left empty when you create a Redis 4.0 or later instance, no critical command will be renamed. Currently, only COMMAND, KEYS, FLUSHDB, FLUSHALL, SCAN, HSCAN, SSCAN, ZSCAN, and HGETALL commands can be renamed.

template_id

No

String

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.

Table 3 BssParam

Parameter

Mandatory

Type

Description

is_auto_renew

No

String

Whether to automatically renew resources. This parameter is mandatory when the billing mode is yearly/monthly.

Value range:

  • false: Do not automatically renew the subscription.

  • true: Automatically renew the subscription.

    The default value is false.

    Note:

    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.

charging_mode

Yes

String

Billing mode. The default value is postPaid, indicating pay-per-use.

is_auto_pay

No

String

Indicates whether fees are deducted automatically from the account balance. Non-automatic payment is used by default.

Value range:

  • true: Fees are automatically deducted from the account balance.

  • false: The order must be paid manually. This is the default value.

Note:

If this parameter is set to true, fees will be automatically deleted from the account balance. 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, the instance enters the Payment in progress state after being created. You must go to Billing Center > Orders to pay for the order. Otherwise, the order is always pending payment and the instance creation is not considered successful.

period_type

No

String

Subscription cycle type. This field is mandatory if the billing mode is yearly/monthly.

Options:

  • month: monthly

  • year: yearly

period_num

No

Integer

Subscription cycles.

This parameter is optional for pay-per-use billing.

Value range: (subject to change due to operation policy change)

  • 1–9, if period_type is set to month.

  • 1–3, if period_type is set to year.

Note: This parameter is mandatory if the billing mode is yearly/monthly.

Table 4 BackupPolicy

Parameter

Mandatory

Type

Description

backup_type

Yes

String

Backup type.

  • auto: automatic backup

  • manual: manual backup

save_days

No

Integer

This parameter is mandatory when backup_type is set to auto.

Retention period, in days. The value ranges from 1 to 7.

periodical_backup_plan

No

BackupPlan object

Backup schedule. This parameter is mandatory when backup_type is set to auto.

Table 5 BackupPlan

Parameter

Mandatory

Type

Description

timezone_offset

No

String

Time zone in which backup is performed. Range: GMT –12:00 to GMT +12:00. If this parameter is left blank, the current time zone of the DCS-Server VM is used by default.

backup_at

Yes

Array of integers

Day in a week on which backup starts. The value ranges from 1 to 7, where 1 indicates Monday, and 7 indicates Sunday.

period_type

Yes

String

Interval at which backup is performed, which supports only weekly currently.

begin_at

Yes

String

Time at which backup starts. 00:00-01:00 indicates that the backup starts at 00:00. The value must be on the hour. The backup interval is 1 hour.

Table 6 ResourceTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key.

  • Must be specified.

  • Must be unique for each resource.

  • Can contain a maximum of 36 characters.

  • Must be unique and cannot be empty.

value

No

String

Tag value.

  • This parameter is mandatory when action is set to create and is optional when action is set to delete.

  • It can contain a maximum of 43 characters.

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

instances

Array of Instances objects

DCS instance ID and name. If multiple DCS instances are created at a time, multiple DCS instance IDs and names will be returned.

Table 8 Instances

Parameter

Type

Description

instance_id

String

DCS instance ID.

instance_name

String

DCS instance name.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 403

Table 11 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 404

Table 12 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 500

Table 13 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Example Requests

  • Creating a DCS Redis instance

    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",
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01" ],
      "capacity" : 1,
      "access_user" : "",
      "password" : "********",
      "enable_publicip" : false,
      "spec_code" : "redis.single.xu1.large.1",
      "subnet_id" : "a4112635-3ec0-471c-95c3-5cf49b9533af",
      "no_password_access" : false,
      "template_id" : "b3ecc9c7-1133-4c47-a06a-21366e227d61"
    }
  • Creating a pay-per-use, master/standby DCS Redis instance with a customized port, renamed commands, and cross-AZ deployment

    {
      "enterprise_project_name" : "default",
      "vpc_id" : "c5cd009b-9ba9-41f2-9a26-2b8c3f3ffd39",
      "description" : "Test",
      "port" : 4040,
      "enable_ssl" : false,
      "private_ip" : "",
      "az_codes" : [ "region01", "region02" ],
      "capacity" : 2,
      "access_user" : "",
      "instance_num" : 1,
      "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"
      }
    }

Example Responses

Status code: 200

The DCS instance creation task is submitted successfully.

If the instance status is RUNNING, the DCS instance has been successfully created.

  • Example 1

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

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

Status code: 400

Invalid request.

{
  "error_code" : "DCS.1004",
  "error_msg" : "Project ID does not match the token."
}

Status code: 401

Invalid authentication information.

{
  "error_code" : "DCS.1001",
  "error_msg" : "Invalid token."
}

Status code: 403

The request is rejected.

{
  "error_code" : "DCS.2003",
  "error_msg" : "This role does not have the permission to perform this operation."
}

Status code: 404

The requested resource is not found.

{
  "error_code" : "DCS.4001",
  "error_msg" : "The requested URL does not exist."
}

Status code: 500

Internal service error.

{
  "error_code" : "DCS.5000",
  "error_msg" : "Internal service error."
}

SDK Sample Code

The SDK sample code is as follows.

  • Creating a DCS Redis instance

     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
    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.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            body.withSubnetId("a4112635-3ec0-471c-95c3-5cf49b9533af");
            body.withVpcId("5e37b3be-950a-48e1-b498-65b63d336481");
            body.withAzCodes(listbodyAzCodes);
            body.withSpecCode("redis.single.xu1.large.1");
            body.withCapacity(1f);
            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 pay-per-use, master/standby DCS Redis instance with a customized port, renamed commands, 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
    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");
            listbodyAzCodes.add("region02");
            body.withRenameCommands("{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}");
            body.withPort(4040);
            body.withEnablePublicip(false);
            body.withAccessUser("");
            body.withNoPasswordAccess(false);
            body.withPassword("********");
            body.withInstanceNum(1);
            body.withPrivateIp("");
            body.withEnableSsl(false);
            body.withDescription("Test");
            body.withEnterpriseProjectName("default");
            body.withEnterpriseProjectId("0");
            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 DCS Redis instance

     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
    # 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="********",
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                subnet_id="a4112635-3ec0-471c-95c3-5cf49b9533af",
                vpc_id="5e37b3be-950a-48e1-b498-65b63d336481",
                az_codes=listAzCodesbody,
                spec_code="redis.single.xu1.large.1",
                capacity=1,
                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 pay-per-use, master/standby DCS Redis instance with a customized port, renamed commands, 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
    # 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",
                "region02"
            ]
            request.body = CreateInstanceBody(
                rename_commands="{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}",
                port=4040,
                enable_publicip=False,
                access_user="",
                no_password_access=False,
                password="********",
                instance_num=1,
                private_ip="",
                enable_ssl=False,
                description="Test",
                enterprise_project_name="default",
                enterprise_project_id="0",
                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 DCS Redis instance

     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
    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:= "********"
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	engineVersionCreateInstanceBody:= "5.0"
    	request.Body = &model.CreateInstanceBody{
    		TemplateId: &templateIdCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		SubnetId: "a4112635-3ec0-471c-95c3-5cf49b9533af",
    		VpcId: "5e37b3be-950a-48e1-b498-65b63d336481",
    		AzCodes: listAzCodesbody,
    		SpecCode: "redis.single.xu1.large.1",
    		Capacity: float32(1),
    		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 pay-per-use, master/standby DCS Redis instance with a customized port, renamed commands, 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
    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",
    	    "region02",
        }
    	var renameCommandsCreateInstanceBody interface{} = "{\"keys\":\"keys001\",\"flushall\":\"flushall001\",\"flushdb\":\"flushdb001\"}"
    	portCreateInstanceBody:= int32(4040)
    	enablePublicipCreateInstanceBody:= false
    	accessUserCreateInstanceBody:= ""
    	noPasswordAccessCreateInstanceBody:= false
    	passwordCreateInstanceBody:= "********"
    	instanceNumCreateInstanceBody:= int32(1)
    	privateIpCreateInstanceBody:= ""
    	enableSslCreateInstanceBody:= false
    	descriptionCreateInstanceBody:= "Test"
    	enterpriseProjectNameCreateInstanceBody:= "default"
    	enterpriseProjectIdCreateInstanceBody:= "0"
    	engineVersionCreateInstanceBody:= "4.0"
    	request.Body = &model.CreateInstanceBody{
    		RenameCommands: &renameCommandsCreateInstanceBody,
    		Port: &portCreateInstanceBody,
    		EnablePublicip: &enablePublicipCreateInstanceBody,
    		AccessUser: &accessUserCreateInstanceBody,
    		NoPasswordAccess: &noPasswordAccessCreateInstanceBody,
    		Password: &passwordCreateInstanceBody,
    		InstanceNum: &instanceNumCreateInstanceBody,
    		PrivateIp: &privateIpCreateInstanceBody,
    		EnableSsl: &enableSslCreateInstanceBody,
    		Description: &descriptionCreateInstanceBody,
    		EnterpriseProjectName: &enterpriseProjectNameCreateInstanceBody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceBody,
    		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)
        }
    }
    

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 submitted successfully.

NOTE:

If the instance status is RUNNING, the DCS instance has been successfully created.

400

Invalid request.

401

Invalid authentication information.

403

The request is rejected.

404

The requested resource is not found.

500

Internal service error.

Error Codes

See Error Codes.