查询主机列表
功能介绍
该接口用于查询输入集群的主机列表详情。
接口约束
无
调用方法
请参见如何调用API。
URI
GET /v1.1/{project_id}/clusters/{cluster_id}/hosts
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cluster_id |
是 |
String |
参数解释: 集群ID。如果指定集群ID,则获取该集群做过补丁更新的最新版本元数据。获取方法,请参见获取集群ID。 约束限制: 不涉及 取值范围: 只能由英文字母、数字以及“_”和“-”组成,且长度为[1-64]个字符。 默认取值: 不涉及 |
project_id |
是 |
String |
参数解释: 项目编号。获取方法,请参见获取项目ID。 约束限制: 不涉及 取值范围: 只能由英文字母和数字组成,且长度为[1-64]个字符。 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
pageSize |
否 |
String |
参数解释: 分页查询每页返回的最大集群数量。 约束限制: 不涉及 取值范围: 1-2147483646 默认取值: 10 |
currentPage |
否 |
String |
参数解释: 当前查询页码。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 1 |
请求参数
无
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
hosts |
Array of HostModel objects |
参数解释: 主机参数。 |
total |
Integer |
参数解释: 主机列表总数。 取值范围: 不涉及 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
参数解释: 虚拟机ID。 取值范围: 不涉及 |
name |
String |
参数解释: 虚拟机名称。 取值范围: 不涉及 |
ip |
String |
参数解释: 虚拟机IP地址。 取值范围: 不涉及 |
availability_zone_id |
String |
参数解释: 可用区域。 取值范围: 不涉及 |
tags |
Array of TagPlain objects |
参数解释: 标签列表信息。 |
status |
String |
参数解释: 虚拟机当前状态。 取值范围: 不涉及 |
resource_id |
String |
参数解释: 节点资源ID。 取值范围: 不涉及 |
flavor |
String |
参数解释: 虚拟机规格ID。 取值范围: 不涉及 |
type |
String |
参数解释: 虚拟机类型,当前支持MasterNode,CoreNode,TaskNode。 取值范围: 不涉及 |
mem |
String |
参数解释: 内存。 取值范围: 不涉及 |
cpu |
String |
参数解释: CPU核数。 取值范围: 不涉及 |
root_volume_size |
String |
参数解释: 操作系统盘容量。 取值范围: 不涉及 |
data_volume_type |
String |
参数解释: 数据盘类型。 取值范围: 不涉及 |
data_volume_size |
Integer |
参数解释: 数据盘容量。 取值范围: 不涉及 |
data_volume_count |
Integer |
参数解释: 数据盘个数。 取值范围: 不涉及 |
node_group_name |
String |
参数解释: 节点组名称。 取值范围: 不涉及 |
请求示例
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代码示例如下。
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 |
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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); MrsClient client = MrsClient.newBuilder() .withCredential(auth) .withRegion(MrsRegion.valueOf("<YOUR REGION>")) .build(); ListHostsRequest request = new ListHostsRequest(); request.withPageSize("<pageSize>"); request.withCurrentPage("<currentPage>"); 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()); } } } |
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"] credentials = BasicCredentials(ak, sk) client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListHostsRequest() request.page_size = "<pageSize>" request.current_page = "<currentPage>" 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) |
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 |
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.ListHostsRequest{} pageSizeRequest:= "<pageSize>" request.PageSize = &pageSizeRequest currentPageRequest:= "<currentPage>" request.CurrentPage = ¤tPageRequest response, err := client.ListHosts(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
查询主机列表信息成功。 |
错误码
请参见错误码。