Querying a Host List - ListHosts
Function
This API is used to query the host list details of a specified MRS cluster, including the host name, IP address, node type, and running status, for cluster operations and troubleshooting.
Constraints
None
Debugging
You can debug this API in API Explorer, which supports automatic authentication and authorization. API Explorer can automatically generate sample SDK code and supports sample SDK code debugging.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, no identity policy-based permissions are required for calling this API.
URI
- Format
- Parameter description
Table 1 URI parameters Parameter
Mandatory
Type
Description
project_id
Yes
String
Definition
Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.
Constraints
N/A
Range
The value must consist of 1 to 64 characters. Only letters and digits are allowed.
Default Value
N/A
cluster_id
Yes
String
Definition
Cluster ID For details about how to obtain the cluster ID, see Obtaining a Cluster ID.
Constraints
N/A
Range
The value can contain 1 to 64 characters, including only letters, digits, underscores (_), and hyphens (-).
Default Value
N/A
Table 2 Query parameters Parameter
Mandatory
Type
Description
pageSize
No
Integer
Definition
Maximum number of clusters displayed on a page.
Constraints
N/A
Range
1-2147483646
Default Value
10
currentPage
No
Integer
Definition
Current page number.
Constraints
N/A
Range
N/A
Default Value
N/A
Request Parameters
None
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| total | Integer | Definition Host parameters. Range N/A |
| hosts | Array of HostModel objects | Definition Host list information, containing detailed information about each host in the cluster. For detailed parameter descriptions, see the parameter details list in Table 4. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| id | String | Definition VM ID. Range N/A |
| name | String | Definition VM name. Range N/A |
| ip | String | Definition VM IP address. Range N/A |
| availability_zone_id | String | Definition Availability zone. Range N/A |
| tags | Array of TagPlain objects | Definition The tag list. For details, see Table 5. Range N/A |
| status | String | Definition Current VM status, which is ACTIVE under normal conditions. Range |
| resource_id | String | Definition Node resource ID. Range N/A |
| flavor | String | Definition VM specification ID. Range N/A |
| type | String | Definition VM type. The value can be MasterNode, CoreNode, or TaskNode. Range
|
| mem | String | Definition Memory, in GB. Range N/A |
| cpu | String | Definition Number of CPU cores. Range N/A |
| root_volume_size | String | Definition OS disk capacity, in GB. Range N/A |
| data_volume_type | String | Definition Data disk type. Range SATA: common I/O SAS: high I/O SSD: ultra-high I/O |
| data_volume_size | Integer | Definition Data disk capacity, in GB. Range N/A |
| data_volume_count | Integer | Definition Number of data disks. Range N/A |
| node_group_name | String | Definition Node group name. Range N/A |
| Parameter | Type | Description |
|---|---|---|
| key | String | Definition Tag key. Range A tag key can contain letters, digits, spaces, and special characters _.:=+-@, but cannot start or end with a space or start with _sys_. |
| value | String | Definition Tag value. Range The value can contain letters, digits, spaces, and special characters _.:=+-@, but cannot start or end with a space or start with _sys_. |
Example Request
GET /v1.1/{project_id}/clusters/{cluster_id}/hosts Example Response
Status code: 200
Querying the host list is successful.
{
"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 Sample Code
The SDK sample code is as follows.
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()); } } } |
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) |
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) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | The host list has been queried. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot