更新时间:2024-07-17 GMT+08:00
分享

查询可用区信息

功能介绍

在创建集群时,需要配置实例所在的可用区ID,可通过该接口查询可用区的ID。

调用方法

请参见如何调用API

URI

GET /v1.1/{region_id}/available-zones

表1 路径参数

参数

是否必选

参数类型

描述

region_id

String

参数解释:

区域id,例如cn-north-4。

约束限制:

不涉及

取值范围:

长度为[1-255]个字符。

默认取值:

不涉及

表2 Query参数

参数

是否必选

参数类型

描述

scope

String

参数解释:

可用区范围。

约束限制:

不涉及

取值范围:

  • Center:表示作用域为中心。

  • Edge:表示作用域为边缘。

默认取值:

不涉及

请求参数

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

available_zones

Array of AvailableZoneV2 objects

参数解释:

可用区列表。

default_az_code

String

参数解释:

默认可用区编码。

取值范围:

不涉及。

support_physical_az_group

Boolean

参数解释:

支持的物理可用区分组。

取值范围:

  • True:支持物理可用区分组。

  • False:不支持物理可用区分组。

表4 AvailableZoneV2

参数

参数类型

描述

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

参数解释:

可用区类型。

取值范围:

  • Core 核心

  • Satellite 卫星

  • Dedicated 专属

  • Virtual 虚拟

  • Edge 边缘

  • EdgeCental 中心边缘

az_tags

AvailableTag object

参数解释:

可用区标签。

表5 AvailableTag

参数

参数类型

描述

mode

String

参数解释:

模式,分为专属dedicated和共享shared。

取值范围:

  • dedicated:专属可用区。

  • shared:共享可用区。

alias

String

参数解释:

az的别名。

取值范围:

不涉及

public_border_group

String

参数解释:

所属group。默认为“center”。

取值范围:

不涉及

请求示例

响应示例

状态码: 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代码示例

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.withScope(ListAvailableZonesRequest.ScopeEnum.fromValue("<scope>"));
        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.scope = "<scope>"
        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
37
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{}
	scopeRequest:= model.GetListAvailableZonesRequestScopeEnum().<SCOPE>
	request.Scope = &scopeRequest
	response, err := client.ListAvailableZones(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

可用区信息

错误码

请参见错误码

分享:

    相关文档

    相关产品