变更实例规格
功能介绍
用户可以为状态为“运行中”的DCS缓存实例进行规格变更。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/instances/{instance_id}/resize
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
instance_id |
是 |
String |
实例ID。 |
project_id |
是 |
String |
项目ID。获取方法请参见获取项目ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
spec_code |
是 |
String |
变更后的产品规格编码。具体查询方法如下:
|
new_capacity |
是 |
Integer |
新的缓存实例规格,单位:GB。 Redis4.0及以上版本:单机和主备类型实例取值:0.125、0.25、0.5、1、2、4、8、16、32、64。集群实例规格支持4、8、16、24、32、48、64、96、128、192、256、384、512、768、1024。读写分离实例规格支持8、16、32、64。 Memcached:单机和主备类型实例取值:2、4、8、16、32、64。 说明:目前不支持3.0 proxy集群的缩容。该参数支持数字类型的0.125,0.25,0.5。 |
bss_param |
否 |
BssParamEntity object |
按需计费无需填写,表示包周期计费模式的相关参数,包周期实例变更规格时需要填写。 |
reserved_ip |
否 |
Array of strings |
需要保留的节点IP。cluster集群缩容时需要填写,不填写时系统将随机删除多余的分片。 |
change_type |
否 |
String |
变更类型,Redis 4.0或者5.0实例进行副本数变更时必选。
|
available_zones |
否 |
Array of strings |
Redis 4.0或者5.0实例进行添加副本时必选,指定每个副本所在的可用区Code,使用前需要先确认该可用区是否有足够资源。集群实例删除副本时必选。 具体查询方法,请参考查询可用区信息。 |
node_list |
否 |
Array of strings |
Redis 4.0或者5.0主备或读写分离实例进行删除副本时必选,指定需要删除的节点ID,目前仅支持一次删除一个副本。 节点ID查询方法,请参考查询分片信息。 |
execute_immediately |
否 |
Boolean |
是否立即变更。默认值为true。
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
is_auto_pay |
否 |
String |
功能说明:下单订购后,是否自动从客户的账户中支付;默认是“不自动支付” 。 取值范围:
约束: 自动支付时,只能使用账户的现金支付;如果要使用代金券,请选择不自动支付,然后在用户费用中心,选择代金券支付。 如果包周期购买,没有设置成自动支付,即设置为false时,在变更规格或创建实例之后,用户必须在“费用中心 > 我的订单”,完成订单支付,否则订单一直在支付中,实例没有变更或者创建成功。 |
响应参数
无
请求示例
变更实例规格,新的缓存实例规格是1GB。
POST https://{dcs_endpoint}/v2/{project_id}/instances/{instance_id}/resize { "spec_code" : "redis.ha.xu1.tiny.r2.1", "new_capacity" : 1, "reserved_ip" : [ "192.168.0.125" ], "change_type" : "createReplication", "available_zones" : [ "e7afd64502d64fe3bfb60c2c82ec0ec6", "d90ff6d692954373bf53be49cf3900cb" ], "node_list" : [ "ff80808282eee5f90183120188ae093e" ], "execute_immediately" : true }
响应示例
无
SDK代码示例
SDK代码示例如下。
变更实例规格,新的缓存实例规格是1GB。
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 |
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 ResizeInstanceSolution { 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(); ResizeInstanceRequest request = new ResizeInstanceRequest(); request.withInstanceId("{instance_id}"); ResizeInstanceBody body = new ResizeInstanceBody(); List<String> listbodyNodeList = new ArrayList<>(); listbodyNodeList.add("ff80808282eee5f90183120188ae093e"); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("e7afd64502d64fe3bfb60c2c82ec0ec6"); listbodyAvailableZones.add("d90ff6d692954373bf53be49cf3900cb"); List<String> listbodyReservedIp = new ArrayList<>(); listbodyReservedIp.add("192.168.0.125"); body.withExecuteImmediately(true); body.withNodeList(listbodyNodeList); body.withAvailableZones(listbodyAvailableZones); body.withChangeType(ResizeInstanceBody.ChangeTypeEnum.fromValue("createReplication")); body.withReservedIp(listbodyReservedIp); body.withNewCapacity(1); body.withSpecCode("redis.ha.xu1.tiny.r2.1"); request.withBody(body); try { ResizeInstanceResponse response = client.resizeInstance(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()); } } } |
变更实例规格,新的缓存实例规格是1GB。
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 |
# 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 = ResizeInstanceRequest() request.instance_id = "{instance_id}" listNodeListbody = [ "ff80808282eee5f90183120188ae093e" ] listAvailableZonesbody = [ "e7afd64502d64fe3bfb60c2c82ec0ec6", "d90ff6d692954373bf53be49cf3900cb" ] listReservedIpbody = [ "192.168.0.125" ] request.body = ResizeInstanceBody( execute_immediately=True, node_list=listNodeListbody, available_zones=listAvailableZonesbody, change_type="createReplication", reserved_ip=listReservedIpbody, new_capacity=1, spec_code="redis.ha.xu1.tiny.r2.1" ) response = client.resize_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) |
变更实例规格,新的缓存实例规格是1GB。
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 |
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.ResizeInstanceRequest{} request.InstanceId = "{instance_id}" var listNodeListbody = []string{ "ff80808282eee5f90183120188ae093e", } var listAvailableZonesbody = []string{ "e7afd64502d64fe3bfb60c2c82ec0ec6", "d90ff6d692954373bf53be49cf3900cb", } var listReservedIpbody = []string{ "192.168.0.125", } executeImmediatelyResizeInstanceBody:= true changeTypeResizeInstanceBody:= model.GetResizeInstanceBodyChangeTypeEnum().CREATE_REPLICATION request.Body = &model.ResizeInstanceBody{ ExecuteImmediately: &executeImmediatelyResizeInstanceBody, NodeList: &listNodeListbody, AvailableZones: &listAvailableZonesbody, ChangeType: &changeTypeResizeInstanceBody, ReservedIp: &listReservedIpbody, NewCapacity: int32(1), SpecCode: "redis.ha.xu1.tiny.r2.1", } response, err := client.ResizeInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
204 |
缓存实例规格变更成功。 |
错误码
请参见错误码。