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

Modifying Details of a DCS Instance

Function

This API is used to modify the information about a DCS instance, including the instance name, description, port, backup policy, start and end time of the maintenance window, and security group.

Calling Method

For details, see Calling APIs.

URI

PUT /v2/{project_id}/instances/{instance_id}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

instance_id

Yes

String

Instance ID.

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

No

String

Instance name.

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

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.

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

port

No

Integer

Port for connecting to the Redis instance. The port range is from 1 to 65535.

After the port is changed, all connections to the Redis instance are interrupted, and services must connect to the new port.

Only DCS Redis 4.0 and later basic edition instances support port change.

rename_commands

No

RenameCommandResp object

Command renaming list.

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 18:00:00, 19:00:00, and so on.

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

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 must also be left blank.

security_group_id

No

String

Security group ID.

The value can be obtained from the VPC console or the API used to query the security group list.

This parameter is supported only by DCS Redis 3.0 and Memcached instances.

instance_backup_policy

No

BackupPolicy object

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

Table 3 RenameCommandResp

Parameter

Mandatory

Type

Description

command

No

String

Command COMMAND.

flushall

No

String

Command FLUSHALL.

flushdb

No

String

Command FLUSHDB.

hgetall

No

String

Command HGETALL.

keys

No

String

Command KEYS.

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

periodical_backup_plan

No

BackupPlan object

Backup schedule. 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.

Table 5 BackupPlan

Parameter

Mandatory

Type

Description

timezone_offset

No

String

Time zone in which backup is performed. This parameter is no longer used.

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. The automatic backup policy is retained when automatic backup is switched to manual backup.

period_type

Yes

String

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.

begin_at

Yes

String

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.

Response Parameters

None

Example Requests

Changing the name of a specified instance to dcs002 and port to 6379, and configuring an auto backup policy

PUT https://{dcs_endpoint}/v2/{project_id}/instance/{instance_id}

{
  "name" : "dcs002",
  "description" : "instance description",
  "port" : 6379,
  "maintain_begin" : "18:00:00",
  "maintain_end" : "19:00:00",
  "security_group_id" : "18e9309f-f81a-4749-bb21-f74576292162",
  "instance_backup_policy" : {
    "backup_type" : "auto",
    "save_days" : "1,",
    "periodical_backup_plan" : {
      "backup_at" : [ "1", "2", "3", "4", "6", "7" ],
      "period_type" : "weekly",
      "begin_at" : "00:00-01:00"
    }
  }
}

Example Responses

None

SDK Sample Code

The SDK sample code is as follows.

Changing the name of a specified instance to dcs002 and port to 6379, and configuring an auto 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
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 UpdateInstanceSolution {

    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();
        UpdateInstanceRequest request = new UpdateInstanceRequest();
        request.withInstanceId("{instance_id}");
        ModifyInstanceBody body = new ModifyInstanceBody();
        List<Integer> listPeriodicalBackupPlanBackupAt = new ArrayList<>();
        listPeriodicalBackupPlanBackupAt.add(1);
        listPeriodicalBackupPlanBackupAt.add(2);
        listPeriodicalBackupPlanBackupAt.add(3);
        listPeriodicalBackupPlanBackupAt.add(4);
        listPeriodicalBackupPlanBackupAt.add(6);
        listPeriodicalBackupPlanBackupAt.add(7);
        BackupPlan periodicalBackupPlanInstanceBackupPolicy = new BackupPlan();
        periodicalBackupPlanInstanceBackupPolicy.withBackupAt(listPeriodicalBackupPlanBackupAt)
            .withPeriodType("weekly")
            .withBeginAt("00:00-01:00");
        BackupPolicy instanceBackupPolicybody = new BackupPolicy();
        instanceBackupPolicybody.withBackupType("auto")
            .withSaveDays(1,)
            .withPeriodicalBackupPlan(periodicalBackupPlanInstanceBackupPolicy);
        body.withInstanceBackupPolicy(instanceBackupPolicybody);
        body.withSecurityGroupId("18e9309f-f81a-4749-bb21-f74576292162");
        body.withMaintainEnd("19:00:00");
        body.withMaintainBegin("18:00:00");
        body.withPort(6379);
        body.withDescription("instance description");
        body.withName("dcs002");
        request.withBody(body);
        try {
            UpdateInstanceResponse response = client.updateInstance(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());
        }
    }
}

Changing the name of a specified instance to dcs002 and port to 6379, and configuring an auto 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
# 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 = UpdateInstanceRequest()
        request.instance_id = "{instance_id}"
        listBackupAtPeriodicalBackupPlan = [
            1,
            2,
            3,
            4,
            6,
            7
        ]
        periodicalBackupPlanInstanceBackupPolicy = BackupPlan(
            backup_at=listBackupAtPeriodicalBackupPlan,
            period_type="weekly",
            begin_at="00:00-01:00"
        )
        instanceBackupPolicybody = BackupPolicy(
            backup_type="auto",
            save_days=1,,
            periodical_backup_plan=periodicalBackupPlanInstanceBackupPolicy
        )
        request.body = ModifyInstanceBody(
            instance_backup_policy=instanceBackupPolicybody,
            security_group_id="18e9309f-f81a-4749-bb21-f74576292162",
            maintain_end="19:00:00",
            maintain_begin="18:00:00",
            port=6379,
            description="instance description",
            name="dcs002"
        )
        response = client.update_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)

Changing the name of a specified instance to dcs002 and port to 6379, and configuring an auto 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
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.UpdateInstanceRequest{}
	request.InstanceId = "{instance_id}"
	var listBackupAtPeriodicalBackupPlan = []int32{
        int32(1),
	    int32(2),
	    int32(3),
	    int32(4),
	    int32(6),
	    int32(7),
    }
	periodicalBackupPlanInstanceBackupPolicy := &model.BackupPlan{
		BackupAt: listBackupAtPeriodicalBackupPlan,
		PeriodType: "weekly",
		BeginAt: "00:00-01:00",
	}
	saveDaysInstanceBackupPolicy:= int32(1,)
	instanceBackupPolicybody := &model.BackupPolicy{
		BackupType: "auto",
		SaveDays: &saveDaysInstanceBackupPolicy,
		PeriodicalBackupPlan: periodicalBackupPlanInstanceBackupPolicy,
	}
	securityGroupIdModifyInstanceBody:= "18e9309f-f81a-4749-bb21-f74576292162"
	maintainEndModifyInstanceBody:= "19:00:00"
	maintainBeginModifyInstanceBody:= "18:00:00"
	portModifyInstanceBody:= int32(6379)
	descriptionModifyInstanceBody:= "instance description"
	nameModifyInstanceBody:= "dcs002"
	request.Body = &model.ModifyInstanceBody{
		InstanceBackupPolicy: instanceBackupPolicybody,
		SecurityGroupId: &securityGroupIdModifyInstanceBody,
		MaintainEnd: &maintainEndModifyInstanceBody,
		MaintainBegin: &maintainBeginModifyInstanceBody,
		Port: &portModifyInstanceBody,
		Description: &descriptionModifyInstanceBody,
		Name: &nameModifyInstanceBody,
	}
	response, err := client.UpdateInstance(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

204

DCS instance modified successfully.

400

Invalid request.

500

Internal service error.

Error Codes

See Error Codes.