更新时间:2026-09-03 GMT+08:00

查询主机列表-ListHosts

功能介绍

该接口用于查询指定MRS集群的主机列表详情,包括主机名称、IP地址、节点类型、运行状态等信息,用于集群运维和故障排查。

接口约束

调试

您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和受限项
  • 如果使用身份策略授权,当前API调用无需身份策略权限。

URI

  • URI格式

    GET /v1.1/{project_id}/clusters/{cluster_id}/hosts

  • 参数说明
    表1 路径参数

    参数

    是否必选

    参数类型

    描述

    project_id

    String

    参数解释:

    项目编号。获取方法,请参见获取项目ID

    约束限制:

    不涉及

    取值范围:

    只能由英文字母和数字组成,且长度为[1-64]个字符。

    默认取值:

    不涉及

    cluster_id

    String

    参数解释:

    集群ID。获取方法,请参见获取集群ID

    约束限制:

    不涉及

    取值范围:

    只能由英文字母、数字以及“_”和“-”组成,且长度为[1-64]个字符。

    默认取值:

    不涉及

    表2 Query参数

    名称

    是否必选

    参数类型

    说明

    pageSize

    Integer

    参数解释:

    分页查询每页返回的最大集群数量。

    约束限制:

    不涉及

    取值范围:

    1-2147483646

    默认取值:

    10

    currentPage

    Integer

    参数解释:

    当前查询页码。

    约束限制:

    不涉及

    取值范围:

    不涉及

    默认取值:

    不涉及

请求参数

响应参数

状态码:200

表3 响应Body说明

参数名

参数类型

说明

total

Integer

参数解释:

主机参数。

取值范围:

不涉及

hosts

Array of HostModel objects

参数解释:

主机列表信息,包含集群中各主机的详细信息,详细参数说明请参考参数详情列表,请参见表4

取值范围:

不涉及

表4 HostModel

参数名

参数类型

说明

id

String

参数解释:

虚拟机ID。

取值范围:

不涉及

name

String

参数解释:

虚拟机名称。

取值范围:

不涉及

ip

String

参数解释:

虚拟机IP地址。

取值范围:

不涉及

availability_zone_id

String

参数解释:

可用区域。

取值范围:

不涉及

tags

Array of TagPlain objects

参数解释:

标签列表信息,请参见表5

取值范围:

不涉及

status

String

参数解释:

虚拟机当前状态,正常状态为ACTIVE。

取值范围:

  • ACTIVE:运行中

  • STARTED:运行中(属ACTIVE状态中的一种)

  • SHUTOFF:关机

  • ERROR:故障

  • BUILD:创建中

  • DELETED:已删除

  • DELETEING: 删除中

  • STOPPING:停止中

  • ATTACHED:已解除隔离

  • DETACHED:已隔离

  • DETACH_FAIL:隔离失败

  • UNKNOWN:未知

  • SCALING_UP:规格升级中

  • DECOMMISSIONING:节点退服中

  • DECOMMISSIONED:节点已退服

  • VOLUMES_EXPANDING:磁盘扩容中

resource_id

String

参数解释:

节点资源ID。

取值范围:

不涉及

flavor

String

参数解释:

虚拟机规格ID。

取值范围:

不涉及

type

String

参数解释:

虚拟机类型,当前支持MasterNode,CoreNode,TaskNode。

取值范围:

  • MasterNode:Master节点类型
  • CoreNode:Core节点类型
  • TaskNode:Task节点类型

mem

String

参数解释:

内存(单位为GB)。

取值范围:

不涉及

cpu

String

参数解释:

CPU核数。

取值范围:

不涉及

root_volume_size

String

参数解释:

操作系统盘容量(单位为GB)。

取值范围:

不涉及

data_volume_type

String

参数解释:

数据盘类型。

取值范围:

SATA:普通IO

SAS:高IO

SSD:超高IO

data_volume_size

Integer

参数解释:

数据盘容量(单位为GB)。

取值范围:

不涉及

data_volume_count

Integer

参数解释:

数据盘个数。

取值范围:

不涉及

node_group_name

String

参数解释:

节点组名称。

取值范围:

不涉及

表5 TagPlain

参数

参数类型

描述

key

String

参数解释:

标签的键。

取值范围:

标签的key值可以包含任意语种字母、数字、空格和_.:=+-@,但首尾不能含有空格,不能以_sys_开头。

value

String

参数解释:

标签的值。

取值范围:

标签的value值可以包含任意语种字母、数字、空格和_.:=+-@,但首尾不能含有空格,不能以_sys_开头。

请求示例

GET /v1.1/{project_id}/clusters/{cluster_id}/hosts

响应示例

状态码:200

查询主机列表信息成功。

{
  "total" : "5",
  "hosts" : [ {
    "id" : "063d1d47-ae91-4a48-840c-b3cfe4efbcf0",
    "name" : "a78e161c-d14f-4b68-8c2d-0219920ce844_node_core_IQhiC",
    "ip" : "192.168.0.169",
    "availability_zone_id" : null,
    "tags" : null,
    "status" : "ACTIVE",
    "resource_id" : "95c1eabc-ed1d-4037-97d1-62f0587790c7",
    "flavor" : "c2.2xlarge.linux.mrs",
    "type" : "Core",
    "mem" : "16384",
    "cpu" : "8",
    "root_volume_size" : "480",
    "data_volume_type" : "SATA",
    "data_volume_size" : "600",
    "data_volume_count" : "1",
    "node_group_name" : "node_group_1"
  }, {
    "id" : "dc5c6208-faa2-4727-a65a-2b1ce235d350",
    "name" : "a78e161c-d14f-4b68-8c2d-0219920ce844_node_master1_ASzkl",
    "ip" : "192.168.0.156",
    "availability_zone_id" : null,
    "tags" : null,
    "status" : "ACTIVE",
    "resource_id" : "95c1eabc-ed1d-4037-97d1-62f0587790c7",
    "flavor" : "c2.4xlarge.linux.mrs",
    "type" : "Master",
    "mem" : "32768",
    "cpu" : "16",
    "root_volume_size" : "480",
    "data_volume_type" : "SATA",
    "data_volume_size" : "600",
    "data_volume_count" : "1",
    "node_group_name" : "master_node_default_group"
  }, {
    "id" : "c0ce793d-848b-448a-835b-ea0cac534b09",
    "name" : "a78e161c-d14f-4b68-8c2d-0219920ce844_node_core_ANnRN",
    "ip" : "192.168.0.243",
    "availability_zone_id" : null,
    "tags" : null,
    "status" : "ACTIVE",
    "resource_id" : "95c1eabc-ed1d-4037-97d1-62f0587790c7",
    "flavor" : "c2.2xlarge.linux.mrs",
    "type" : "Core",
    "mem" : "16384",
    "cpu" : "8",
    "root_volume_size" : "480",
    "data_volume_type" : "SATA",
    "data_volume_size" : "600",
    "data_volume_count" : "1",
    "node_group_name" : "node_group_1"
  }, {
    "id" : "95c23e43-ef6e-4732-b6ed-a5f1c7779fae",
    "name" : "a78e161c-d14f-4b68-8c2d-0219920ce844_node_core_uRRiA",
    "ip" : "192.168.0.126",
    "availability_zone_id" : null,
    "tags" : null,
    "status" : "ACTIVE",
    "resource_id" : "95c1eabc-ed1d-4037-97d1-62f0587790c7",
    "flavor" : "c2.2xlarge.linux.mrs",
    "type" : "Core",
    "mem" : "16384",
    "cpu" : "8",
    "root_volume_size" : "480",
    "data_volume_type" : "SATA",
    "data_volume_size" : "600",
    "data_volume_count" : "1",
    "node_group_name" : "node_group_1"
  }, {
    "id" : "63bdbf75-1133-4a94-8c27-1fa12c8b9e70",
    "name" : "a78e161c-d14f-4b68-8c2d-0219920ce844_node_master2_StqFu",
    "ip" : "192.168.0.22",
    "availability_zone_id" : null,
    "tags" : null,
    "status" : "ACTIVE",
    "resource_id" : "95c1eabc-ed1d-4037-97d1-62f0587790c7",
    "flavor" : "c2.4xlarge.linux.mrs",
    "type" : "Master",
    "mem" : "32768",
    "cpu" : "16",
    "root_volume_size" : "480",
    "data_volume_type" : "SATA",
    "data_volume_size" : "600",
    "data_volume_count" : "1",
    "node_group_name" : "master_node_default_group"
  } ]
}

SDK代码示例

SDK代码示例如下。

Java

 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
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 ListHostsSolution {

    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);

        MrsClient client = MrsClient.newBuilder()
                .withCredential(auth)
                .withRegion(MrsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListHostsRequest request = new ListHostsRequest();
        request.withClusterId("{cluster_id}");
        try {
            ListHostsResponse response = client.listHosts(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

 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
# 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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = MrsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(MrsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListHostsRequest()
        request.cluster_id = "{cluster_id}"
        response = client.list_hosts(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

 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
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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := mrs.NewMrsClient(
        mrs.MrsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListHostsRequest{}
	request.ClusterId = "{cluster_id}"
	response, err := client.ListHosts(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

表6 状态码

状态码

描述

200

查询主机列表信息成功。

错误码

请参见错误码