缩容集群
功能介绍
对MRS集群进行缩容。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/clusters/{cluster_id}/shrink
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
node_group_name |
是 |
String |
参数解释: 节点组名称。 约束限制: 不涉及 取值范围: 只能由英文字母、数字以及“_”和“-”组成,且长度为[1-64]个字符。 默认取值: 不涉及 |
count |
否 |
Integer |
参数解释: 缩容节点数量,如果是指定节点缩容,则该参数可以不填。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
resource_ids |
否 |
Array of strings |
参数解释: 缩容节点时指定待删除节点的资源ID列表。resource_ids为空时,按照系统规则自动选择删除节点。仅支持删除状态异常的ecs节点。会针对指定节点进行强制删除。可通过查询主机接口获取resource_id。 约束限制: 不涉及 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
result |
String |
参数解释: 更新映射请求操作结果。 取值范围:
|
请求示例
在node_group_1节点组上缩容1个节点。
/v2/ff8080828997cb24018a1b2db3440b80/clusters/f7f45c04-4303-411c-9b71-d2cb730dd162/shrink { "node_group_name" : "node_group_1", "count" : 1 }
在node_group_1节点组上强制缩容资源id为678050cd-ba1d-4550-942d-f2e396b1c6fb的节点。
/v2/ff8080828997cb24018a1b2db3440b80/clusters/f7f45c04-4303-411c-9b71-d2cb730dd162/shrink { "node_group_name" : "node_group_1", "resource_ids" : [ "678050cd-ba1d-4550-942d-f2e396b1c6fb" ] }
响应示例
状态码: 200
缩容成功
{ "result" : "succeeded" }
SDK代码示例
SDK代码示例如下。
在node_group_1节点组上缩容1个节点。
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
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.mrs.v2.region.MrsRegion; import com.huaweicloud.sdk.mrs.v2.*; import com.huaweicloud.sdk.mrs.v2.model.*; public class ShrinkClusterSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); MrsClient client = MrsClient.newBuilder() .withCredential(auth) .withRegion(MrsRegion.valueOf("<YOUR REGION>")) .build(); ShrinkClusterRequest request = new ShrinkClusterRequest(); ShrinkParam body = new ShrinkParam(); body.withCount(1); body.withNodeGroupName("node_group_1"); request.withBody(body); try { ShrinkClusterResponse response = client.shrinkCluster(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()); } } }
在node_group_1节点组上强制缩容资源id为678050cd-ba1d-4550-942d-f2e396b1c6fb的节点。
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
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.mrs.v2.region.MrsRegion; import com.huaweicloud.sdk.mrs.v2.*; import com.huaweicloud.sdk.mrs.v2.model.*; import java.util.List; import java.util.ArrayList; public class ShrinkClusterSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); MrsClient client = MrsClient.newBuilder() .withCredential(auth) .withRegion(MrsRegion.valueOf("<YOUR REGION>")) .build(); ShrinkClusterRequest request = new ShrinkClusterRequest(); ShrinkParam body = new ShrinkParam(); List<String> listbodyResourceIds = new ArrayList<>(); listbodyResourceIds.add("678050cd-ba1d-4550-942d-f2e396b1c6fb"); body.withResourceIds(listbodyResourceIds); body.withNodeGroupName("node_group_1"); request.withBody(body); try { ShrinkClusterResponse response = client.shrinkCluster(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()); } } }
在node_group_1节点组上缩容1个节点。
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmrs.v2.region.mrs_region import MrsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmrs.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"] credentials = BasicCredentials(ak, sk) client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ShrinkClusterRequest() request.body = ShrinkParam( count=1, node_group_name="node_group_1" ) response = client.shrink_cluster(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
在node_group_1节点组上强制缩容资源id为678050cd-ba1d-4550-942d-f2e396b1c6fb的节点。
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmrs.v2.region.mrs_region import MrsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmrs.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"] credentials = BasicCredentials(ak, sk) client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ShrinkClusterRequest() listResourceIdsbody = [ "678050cd-ba1d-4550-942d-f2e396b1c6fb" ] request.body = ShrinkParam( resource_ids=listResourceIdsbody, node_group_name="node_group_1" ) response = client.shrink_cluster(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
在node_group_1节点组上缩容1个节点。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := mrs.NewMrsClient( mrs.MrsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ShrinkClusterRequest{} countShrinkParam:= int32(1) request.Body = &model.ShrinkParam{ Count: &countShrinkParam, NodeGroupName: "node_group_1", } response, err := client.ShrinkCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
在node_group_1节点组上强制缩容资源id为678050cd-ba1d-4550-942d-f2e396b1c6fb的节点。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := mrs.NewMrsClient( mrs.MrsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ShrinkClusterRequest{} var listResourceIdsbody = []string{ "678050cd-ba1d-4550-942d-f2e396b1c6fb", } request.Body = &model.ShrinkParam{ ResourceIds: &listResourceIdsbody, NodeGroupName: "node_group_1", } response, err := client.ShrinkCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
缩容成功 |
错误码
请参见错误码。