
# 扩容实例的数量和存储容量 - UpdateExtendInstanceStorage
#### 功能介绍
当集群的数据量持续增长或内存占用过高时，集群可能无法有效应对业务负载和性能需求。此时，可以扩容节点的数量和存储容量。
#### 接口约束
- 集群的节点存储容量只支持扩容不支持缩容，请基于业务量合理选择节点存储容量。
  
- 按需集群支持同时扩容"节点数量"和"节点存储容量"，包周期集群不支持。
  
- 集群的Master节点和Client节点的存储容量不支持扩容。
  
- 本地盘类型的数据节点不支持扩容节点存储容量。
  
- Logstash集群只支持扩容节点数量，不支持扩容存储容量。
  
 
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-css/css_03_0077.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-css/css_03_0096.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                | 访问级别  | 资源类型（\*为必须） | 条件键                                                                                                                                                                                                                                                                                                                                                                                                                                 | 别名 | 依赖的授权项                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
  |:---|:---|:---|:---|:---|:---|
  | css:cluster:expand | Write | cluster \*  | - g:EnterpriseProjectId   - g:ResourceTag/\<tag-key\>    | -  | - ecs:cloudServerFlavors:get  - evs:types:get  - vpc:vpcs:list  - vpc:subnets:list  - vpc:subnets:get  - vpc:ports:create  - vpc:ports:update  - vpc:ports:delete  - vpc:ports:get  - kms:cmk:get   |
     
  
 
#### URI
POST /v1.0/{project_id}/clusters/{cluster_id}/role_extend
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**： 项目ID。获取方法请参见[获取项目ID和名称](https://support.huaweicloud.com/api-css/css_03_0071.html)。 **约束限制**： 不涉及 **取值范围**： 账户的项目ID，长度为32个字符，由小写字母和数字组成。 **默认取值**： 不涉及 |
| cluster_id | 是    | String | **参数解释**： 指定扩容的集群ID。获取方法请参见[获取集群ID](https://support.huaweicloud.com/api-css/css_03_0101.html)。 **约束限制**： 不涉及 **取值范围**： UUID格式，36个字符。 **默认取值**： 不涉及              |
   
#### 请求参数
表2请求Body参数 
| 参数          | 是否必选 | 参数类型                                                                                          | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|:---|
| grow        | 是    | Array of [RoleExtendGrowReq] objects | **参数解释**： 集群扩容请求的详细描述，包含type、nodesize、disksize等字段，用于指定扩容的节点类型、实例个数和存储容量。 **约束限制**： 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| is_auto_pay | 否    | Integer                                                                                       | **参数解释**： 是否自动支付。下单订购后，是否自动从客户的华为云账户中支付，而不需要客户手动支付。 **约束限制**： 该参数适用于包周期集群。 **取值范围**： - 1：自动支付。会自动选择折扣和优惠券，从客户的华为云账户中自动扣款。自动支付失败后会生成"待支付"的订单（该订单应付金额是优惠后的金额)，等待客户手动完成支付，支付时可以修改系统自动选择的折扣和优惠券。   - 0：手动支付。需要客户手动支付订单，支付时，可以选择折扣和优惠券。    **默认取值**： 0 |
   
 表3RoleExtendGrowReq 
| 参数       | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| type     | 是    | String  | **参数解释**： 待扩容的节点类型。 **约束限制**： ess-master、ess-client、lgs节点只支持增加实例个数。 必须为合理的节点类型，仅支持小写英文字母和连字符 **取值范围**： - ess：数据节点。   - ess-master：Master节点。   - ess-client：Client节点。   - ess-cold：冷数据节点。   - lgs：Logstash集群创建的Logstash节点。    可以选择其中一个或多个之间的组合，但不可以重复选择。 说明： lgs不支持和其他一起组合。 **默认取值**： 不涉及 |
| nodesize | 是    | Integer | **参数解释**： 增加的实例个数。 **约束限制**： 集群扩容后，各类型节点的数量需要满足以下要求： - 数据节点：集群没有Master节点时：1\~32个，集群有Master节点时：1\~200个。   - Master节点：3、5、7、9(必须是3\~9之间的奇数)。   - Client节点：1\~64。   - 冷数据节点：1\~32。   - Logstash节点：1\~100。    **取值范围**： 不涉及 **默认取值**： 不涉及                                                                                                   |
| disksize | 是    | Integer | **参数解释**： 扩容实例存储容量，单位：GB。 **约束限制**： - 集群原实例存储容量和扩容实例存储容量之和不能超过创建集群时对应默认实例存储容量上限。若无需扩容该参数将该参数设置为0即可。当集群为包周期集群时不支持同时修改节点个数和磁盘容量。   - ess节点、ess-cold节点扩容步长为20。   - ess-master节点、ess-client节点不允许扩容存储。   - Logstash不支持扩容存储容量。    **取值范围**： 不涉及 **默认取值**： 不涉及                                                                                                                                                                                                                                                                                               |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数 | 参数类型   | 描述                                                                                                                                                                         |
|:---|:---|:---|
| id | String | **参数解释**： 集群ID。 **取值范围**： 不涉及 |
   
#### 请求示例
修改当前集群的实例个数与存储容量。
```
POST https://{Endpoint}/v1.0/{project_id}/clusters/4f3deec3-efa8-4598-bf91-560aad1377a3/role_extend
{
  "grow" : [ {
    "type" : "ess",
    "nodesize" : 0,
    "disksize" : 40
  } ],
  "is_auto_pay" : 1
}
```
#### 响应示例
**状态码：200**
请求成功。
```
{
  "id" : "4f3deec3-efa8-4598-bf91-560aad1377a3"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  修改当前集群的实例个数与存储容量。
  ```
  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.css.v1.region.CssRegion;
  import com.huaweicloud.sdk.css.v1.*;
  import com.huaweicloud.sdk.css.v1.model.*;
  import java.util.List;
  import java.util.ArrayList;
  public class UpdateExtendInstanceStorageSolution {
      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);
          CssClient client = CssClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(CssRegion.valueOf("<YOUR REGION>"))
                  .build();
          UpdateExtendInstanceStorageRequest request = new UpdateExtendInstanceStorageRequest();
          request.withClusterId("{cluster_id}");
          RoleExtendReq body = new RoleExtendReq();
          List<RoleExtendGrowReq> listbodyGrow = new ArrayList<>();
          listbodyGrow.add(
              new RoleExtendGrowReq()
                  .withType("ess")
                  .withNodesize(0)
                  .withDisksize(40)
          );
          body.withIsAutoPay(1);
          body.withGrow(listbodyGrow);
          request.withBody(body);
          try {
              UpdateExtendInstanceStorageResponse response = client.updateExtendInstanceStorage(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());
          }
      }
  }
  ```
- [Python]
  修改当前集群的实例个数与存储容量。
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkcss.v1.region.css_region import CssRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkcss.v1 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 = CssClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(CssRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = UpdateExtendInstanceStorageRequest()
          request.cluster_id = "{cluster_id}"
          listGrowbody = [
              RoleExtendGrowReq(
                  type="ess",
                  nodesize=0,
                  disksize=40
              )
          ]
          request.body = RoleExtendReq(
              is_auto_pay=1,
              grow=listGrowbody
          )
          response = client.update_extend_instance_storage(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  修改当前集群的实例个数与存储容量。
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/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, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := css.CssClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := css.NewCssClient(hcClient)
      request := &model.UpdateExtendInstanceStorageRequest{}
  request.ClusterId = "{cluster_id}"
  var listGrowbody = []model.RoleExtendGrowReq{
          {
              Type: "ess",
              Nodesize: int32(0),
              Disksize: int32(40),
          },
      }
  isAutoPayRoleExtendReq:= int32(1)
  request.Body = &model.RoleExtendReq{
  IsAutoPay: &isAutoPayRoleExtendReq,
  Grow: listGrowbody,
  }
  response, err := client.UpdateExtendInstanceStorage(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CSS/sdk?api=UpdateExtendInstanceStorage&version=v1)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                                                           |
|:---|:---|
| 200 | 请求成功。                                                                        |
| 400 | 非法请求。 建议直接修改该请求，不要重试该请求。      |
| 404 | 所请求的资源不存在。 建议直接修改该请求，不要重试该请求。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-css/css_03_0076.html)。
