请登录后查看
ListAvailableZones
查询可用区信息
本文档信息来源于官网帮助中心
在创建集群时,需要配置实例所在的可用区ID,可通过该接口查询可用区的ID。
请参见如何调用API。
GET /v1.1/{region_id}/available-zones
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
region_id |
是 |
String |
参数解释: 区域id,例如cn-north-4。 约束限制: 不涉及 取值范围: 长度为[1-255]个字符。 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
scope |
否 |
String |
参数解释: 可用区范围。 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
无
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
available_zones |
Array of AvailableZoneV2 objects |
参数解释: 可用区列表。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
default_az_code |
String |
参数解释: 默认可用区编码。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
support_physical_az_group |
Boolean |
参数解释: 支持的物理可用区分组。 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
参数解释: 可用区编码。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
az_code |
String |
参数解释: 可用区编码。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
az_name |
String |
参数解释: 可用区名称。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
az_id |
String |
参数解释: 可用区id。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
status |
String |
参数解释: 可用区状态。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
region_id |
String |
参数解释: 区域id。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
az_group_id |
String |
参数解释: 可用区分组id。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
az_type |
String |
参数解释: 可用区类型。 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
az_tags |
AvailableTag object |
参数解释: 可用区标签。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
无
状态码: 200
可用区信息
{ "available_zones" : [ { "id" : "cn-north-7a", "az_code" : "cn-north-7a", "az_name" : "可用区1", "az_id" : "8c90c2a4e2594c0782faa6b205afeca7", "status" : "Running", "region_id" : "cn-north-7", "az_type" : "Dedicated", "az_group_id" : "", "az_tags" : { "mode" : null, "alias" : null, "public_border_group" : "center" } }, { "id" : "cn-north-7b", "az_code" : "cn-north-7b", "az_name" : "可用区2", "az_id" : "d539378ec1314c85b76fefa3f7071458", "status" : "Running", "region_id" : "cn-north-7", "az_type" : "Dedicated", "az_tags" : { "mode" : null, "alias" : null, "public_border_group" : "center" } }, { "id" : "cn-north-7c", "az_code" : "cn-north-7c", "az_name" : "可用区3", "az_id" : "9f1c5806706d4c1fb0eb72f0a9b18c77", "status" : "Running", "region_id" : "cn-north-7", "az_type" : "Dedicated", "az_tags" : { "mode" : null, "alias" : null, "public_border_group" : "center" } } ], "default_az_code" : "cn-north-7a", "support_physical_az_group" : true }
SDK代码示例如下。
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 |
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()); } } } |
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 |
# 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) |
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 |
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的代码示例页签,可生成自动对应的SDK代码示例。
状态码 |
描述 |
---|---|
200 |
可用区信息 |
请参见错误码。