# 查询可用区信息-ListAvailableZones
#### 功能介绍
查询MRS服务当前区域下可用的可用区信息，包括可用区ID和名称。在创建集群时，需要通过该接口获取可用区ID来配置集群节点所在的位置。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-mrs/zh-cn_topic_0013582897.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-mrs/mrs_02_0221.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
GET /v1.1/{region_id}/available-zones
表1路径参数 
| 参数        | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| region_id | 是    | String | **参数解释：** 区域ID信息，例如cn-north-4。获取方法请参见[地区和终端节点](https://console.huaweicloud.com/apiexplorer/#/endpoint/MRS)。 **约束限制：** 不涉及 **取值范围：** 只能由小写字母、数字和连字符组成，长度为1\~255个字符。 **默认取值：** 不涉及 |
   
表2Query参数 
| 参数    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
|:---|:---|:---|:---|
| scope | 否    | String | **参数解释：** 可用区范围。 **约束限制：** 不涉及 **取值范围：** - Center：表示作用域为中心。   - Edge：表示作用域为边缘。    **默认取值：** 不涉及 |
   
#### 请求参数
无
#### 响应参数
**状态码：200**
表3响应Body参数 
| 参数                        | 参数类型                                                                              | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
|:---|:---|:---|
| available_zones           | Array of [AvailableZoneV2] objects | **参数解释：** 可用区列表。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                              |
| default_az_code           | String                                                                            | **参数解释：** 默认可用区编码。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                              |
| support_physical_az_group | Boolean                                                                           | **参数解释：** 支持的物理可用区分组。 **取值范围：** - True：支持物理可用区分组。   - False：不支持物理可用区分组。    |
   
 表4AvailableZoneV2 
| 参数            | 参数类型                                                              | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
|:---|:---|:---|
| id            | String                                                            | **参数解释：** 可用区唯一ID标识。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| az_code       | String                                                            | **参数解释：** 可用区编码信息。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| az_name       | String                                                            | **参数解释：** 可用区名称。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| az_id         | String                                                            | **参数解释：** 可用区id。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| status        | String                                                            | **参数解释：** 可用区状态。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| region_id     | String                                                            | **参数解释：** 区域id。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| az_group_id   | String                                                            | **参数解释：** 可用区分组id。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| az_type       | String                                                            | **参数解释：** 可用区类型。 **取值范围：** - Core：核心   - Satellite：卫星   - Dedicated：专属   - Virtual：虚拟   - Edge：边缘   - EdgeCentral：中心边缘    |
| az_tags       | [AvailableTag] object | **参数解释：** 可用区标签。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| az_category   | Integer                                                           | **参数解释：** 当前可用区的类型。 **取值范围：** - 0：大云主可用区   - 21：本地可用区   - 41：边缘可用区                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| charge_policy | String                                                            | **参数解释：** 当前可用区的销售策略。 **取值范围：** - charge：计费   - notCharge：非计费                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
   
 表5AvailableTag 
| 参数                  | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|
| mode                | String | **参数解释：** 模式，分为专属dedicated和共享shared。 **取值范围：** - dedicated：专属可用区。   - shared：共享可用区。    |
| alias               | String | **参数解释：** az的别名。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                              |
| public_border_group | String | **参数解释：** 所属group。默认为"center"。 **取值范围：** 不涉及                                                                                                                                                                                                                                                                                                                                                                                           |
   
#### 请求示例
无
#### 响应示例
**状态码：200**
可用区信息
```
{
  "available_zones" : [ {
    "id" : "cn-north-4a",
    "az_code" : "cn-north-4a",
    "az_name" : "可用区1",
    "az_id" : "cn-north-4a",
    "status" : "Running",
    "region_id" : "cn-north-4",
    "az_group_id" : null,
    "az_type" : "Core",
    "az_tags" : {
      "mode" : null,
      "alias" : null,
      "public_border_group" : "center"
    },
    "az_category" : 0,
    "charge_policy" : "charge"
  }, {
    "id" : "cn-north-4b",
    "az_code" : "cn-north-4b",
    "az_name" : "可用区2",
    "az_id" : "cn-north-4b",
    "status" : "Running",
    "region_id" : "cn-north-4",
    "az_group_id" : null,
    "az_type" : "Core",
    "az_tags" : {
      "mode" : null,
      "alias" : null,
      "public_border_group" : "center"
    },
    "az_category" : 0,
    "charge_policy" : "charge"
  }, {
    "id" : "cn-north-4c",
    "az_code" : "cn-north-4c",
    "az_name" : "可用区3",
    "az_id" : "cn-north-4c",
    "status" : "Running",
    "region_id" : "cn-north-4",
    "az_group_id" : null,
    "az_type" : "Core",
    "az_tags" : {
      "mode" : null,
      "alias" : null,
      "public_border_group" : "center"
    },
    "az_category" : 0,
    "charge_policy" : "charge"
  }, {
    "id" : "cn-north-4g",
    "az_code" : "cn-north-4g",
    "az_name" : "可用区7",
    "az_id" : "cn-north-4g",
    "status" : "Running",
    "region_id" : "cn-north-4",
    "az_group_id" : null,
    "az_type" : "Core",
    "az_tags" : {
      "mode" : null,
      "alias" : null,
      "public_border_group" : "center"
    },
    "az_category" : 0,
    "charge_policy" : "charge"
  } ],
  "default_az_code" : "cn-north-4g",
  "support_physical_az_group" : true
}
```
#### 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.mrs.v1.region.MrsRegion;
  import com.huaweicloud.sdk.mrs.v1.*;
  import com.huaweicloud.sdk.mrs.v1.model.*;
  public class ListAvailableZonesSolution {
      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();
          ListAvailableZonesRequest request = new ListAvailableZonesRequest();
          request.withRegionId("{region_id}");
          try {
              ListAvailableZonesResponse response = client.listAvailableZones(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 huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkmrs.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"]
      credentials = BasicCredentials(ak, sk)
      client = MrsClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(MrsRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListAvailableZonesRequest()
          request.region_id = "{region_id}"
          response = client.list_available_zones(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"
      mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/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")
      auth := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          Build()
      client := mrs.NewMrsClient(
          mrs.MrsClientBuilder().
              WithRegion(region.ValueOf("<YOUR REGION>")).
              WithCredential(auth).
              Build())
      request := &model.ListAvailableZonesRequest{}
  request.RegionId = "{region_id}"
  response, err := client.ListAvailableZones(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/MRS/sdk?api=ListAvailableZones&version=v1)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述    |
|:---|:---|
| 200 | 可用区信息 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-mrs/ErrorCode.html)。
