Updated on 2024-04-18 GMT+08:00

Querying the Node List

Function

This API is used to query the node list.

Call Method

For details, see Calling APIs.

URI

GET /v2/{project_id}/clusters/{cluster_id}/nodes
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the ID, see Obtaining Project ID.

cluster_id

Yes

String

Cluster ID. For details about how to obtain the ID, see Obtaining the Cluster ID.

Table 2 Query parameters

Parameter

Mandatory

Type

Description

deleted

No

String

Reserved and not recommended. can be replaced by node_ids:

  • deleted = true: node_ids is not empty.
  • "deleted = false": node_ids is empty.

node_ids

No

Array

List of node IDs

offset

No

Integer

Offset of pagination query. The value ranges from 0 to 10000.

limit

No

Integer

Specifies the number of records displayed on each page. The value ranges from 1 to 1000.

filter_by

No

String

Filter field

  • status: node status.
  • instCreateType: resource status.

filter

No

String

Content of the filter field

  • status = ALL: queries all nodes, including deleted historical nodes.
  • status = CREATING: The instance is being created.
  • status = FREE: indicates that the node is idle.
  • status = INIT: initialized.
  • status = ACTIVE: available.
  • status = FAILED: unavailable.
  • status = UNKNOWN: unknown.
  • status = CREATE_FAILED: The creation fails.
  • status = DELETING: The volume is being deleted.
  • status = DELETE_FAILED: The deletion fails.
  • status = REBOOTING: The VM is being restarted.
  • status = STOPPED: The task has been stopped.
  • instCreateType = ALL: Query all nodes, including deleted historical nodes.
  • instCreateType = INST: used.
  • instCreateType = NODE: idle.

order_by

No

String

Sort By:

  • Node ID: id.
  • Node name: name.
  • Node status: status.

order

No

String

Sorting method. Available values include:

  • asc: the ascending order
  • desc: the descending order

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameter

Parameter

Type

Description

node_list

Array of ClusterNodeInfo objects

List of nodes in a logical cluster

count

Integer

Total number of nodes in a logical cluster

failed_count

Integer

Total number of failed nodes in a logical cluster

Table 4 ClusterNodeInfo

Parameter

Type

Description

id

String

Node ID

name

String

Node name

status

String

Node status.

  • CREATING
  • FREE: idle.
  • ACTIVE: The cluster is available.
  • FAILED: The cluster is unavailable.
  • UNKNOWN: The device node type is unknown.
  • SERVER_FAILED: An internal error occurs.
  • CREATE_FAILED: The workspace failed to be created.
  • DELETING
  • DELETE_FAILED: The workspace failed to be deleted.
  • DELETED: deleted
  • REBOOTING: Restarting
  • RESTORING: Restoring
  • MODIFYING: The policy is being modified.
  • MODIFYING_PORT: The port is being bonded.
  • INIT: initializing.
  • STOPPED

sub_status

String

Node sub-status

  • READY: The ECS on the node is ready.
  • PREPARED: The node software has been installed.
  • INITED: The cluster has been created.
  • CREATED: The node has been created.

spec

String

Node specifications

inst_create_type

String

Instance creation type

alias_name

String

Node alias

az_code

String

AZ code

Example Request

GET https://{Endpoint}/v2/9b06d044ea4f49f1a58b2bed2b0084bd/clusters/9b7ff56b-47b3-4d00-a1fd-4c023d34404b/nodes?deleted=false&node_ids&offset=0&limit=10&filter_by=instCreateType&filter=INST

Example Response

Status code: 200

The cluster node information is queried.

{
  "node_list" : [ {
    "id" : "16413746-258e-4a3c-bea9-8496fdbefde3",
    "name" : "ty-default--BGy6PUIN-K-dws-cn-cn-2-1",
    "status" : "ACTIVE",
    "sub_status" : "CREATED",
    "spec" : "dws2.kc1.2xlarge",
    "inst_create_type" : null,
    "alias_name" : null,
    "az_code" : "cn-north-4c"
  }, {
    "id" : "46d8754b-3ed3-4b92-85b5-7479ef5b10ac",
    "name" : "ty-default--BGy6PUIN-K-dws-cn-cn-1-1",
    "status" : "ACTIVE",
    "sub_status" : "CREATED",
    "spec" : "dws2.kc1.2xlarge",
    "inst_create_type" : null,
    "alias_name" : null,
    "az_code" : "cn-north-4c"
  } ],
  "count" : 2,
  "failed_count" : 0
}

SDK Sample Code

The 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
49
50
51
52
53
54
55
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.dws.v2.region.DwsRegion;
import com.huaweicloud.sdk.dws.v2.*;
import com.huaweicloud.sdk.dws.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class ListClusterNodesSolution {

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

        DwsClient client = DwsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DwsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListClusterNodesRequest request = new ListClusterNodesRequest();
        request.withDeleted("<deleted>");
        request.withNodeIds();
        request.withOffset(<offset>);
        request.withLimit(<limit>);
        request.withFilterBy("<filter_by>");
        request.withFilter("<filter>");
        request.withOrderBy("<order_by>");
        request.withOrder("<order>");
        try {
            ListClusterNodesResponse response = client.listClusterNodes(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
33
34
35
36
37
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdws.v2.region.dws_region import DwsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdws.v2 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.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

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

    try:
        request = ListClusterNodesRequest()
        request.deleted = "<deleted>"
        request.node_ids = 
        request.offset = <offset>
        request.limit = <limit>
        request.filter_by = "<filter_by>"
        request.filter = "<filter>"
        request.order_by = "<order_by>"
        request.order = "<order>"
        response = client.list_cluster_nodes(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
40
41
42
43
44
45
46
47
48
49
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dws "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/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 := dws.NewDwsClient(
        dws.DwsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListClusterNodesRequest{}
	deletedRequest:= "<deleted>"
	request.Deleted = &deletedRequest
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	filterByRequest:= "<filter_by>"
	request.FilterBy = &filterByRequest
	filterRequest:= "<filter>"
	request.Filter = &filterRequest
	orderByRequest:= "<order_by>"
	request.OrderBy = &orderByRequest
	orderRequest:= "<order>"
	request.Order = &orderRequest
	response, err := client.ListClusterNodes(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For more SDK sample codes of programming languages, visit API Explorer and click the Sample Code tab. Example codes can be automatically generated.

Status Code

Status Code

Description

200

The cluster node information is queried.

400

Request error.

401

Authentication failed.

403

You do not have required permissions.

404

No resources found.

500

Internal server error.

503

Service unavailable.