Querying the Cluster List of a Tenant

Sample Code

You can use the API to the list of clusters of a tenant. The following parameters are involved in this API: name, status, cursor, next, limit, and order. In this example, the query results are displayed in descending order and information about the clusters whose IDs are less than the value of cursor is displayed. 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
// Import classes:
import com.huaweicloud.cs.java.v1.client.ApiException;
import com.huaweicloud.cs.java.v1.ClusterApi;


ClusterApi apiInstance = new ClusterApi(apiClient);//apiClient is created when initializing a CS API client.
String xProjectId = "xProjectId_example"; // String | Project ID used for obtaining the token for the project.
String name = "name_example"; // String | Cluster name.
String status = "status_example"; // String | Cluster status code. For details, see CS documentation.
Long cursor = 789L; // Long | Cluster ID.
Boolean next = true; // Boolean | Whether to turn to the previous or next page.
Integer limit = 10; // Integer | Number of returned data records.
String order = "desc"; // String | Query result display. The query results can be displayed in ascending or descending order.
try {
    QueryClustersResponse result = apiInstance.getReservedClusters(xProjectId, name, status, cursor, next, limit, order);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ClusterApi#getReservedClusters");
    System.err.println(e.getResponseBody());
    e.printStackTrace();
}

Parameter Description

Table 1 Parameters

Parameter

Mandatory

Type

Description

xProjectId

Yes

String

Project ID. This parameter is used to obtain the token for the project.

name

No

String

Cluster name.

status

No

String

Indicates the status code of a cluster. Possible values are:

  • cluster_creating
  • cluster_create_fail
  • cluster_create_success
  • cluster_starting
  • cluster_running
  • cluster_deleting
  • cluster_delete_fail

cursor

No

Integer

Cluster ID.

next

No

Boolean

Whether to switch to the previous or next page. The default value is true.

limit

No

Integer

Number of returned data records. The default value is 10.

order

No

String

Query result display. Value asc indicates that the query results are displayed in ascending order, and value desc indicates that the query results are displayed in descending order. The default value is desc.

Table 2 Parameters involved in QueryClustersResponse

Parameter

Mandatory

Type

Description

messageId

No

String

Message type ID.

message

No

String

Message content.

currentTime

No

Long

Current time, expressed by milliseconds.

payload

No

Integer

Number of records in the query result.

clusters

No

Array

For details about parameter types, see Table 3.

Table 3 Parameters involved in ClusterInfo

Parameter

Mandatory

Type

Description

clusterId

No

Integer

Cluster ID.

name

No

String

Cluster name.

desc

No

String

Cluster description.

statusCode

No

Integer

Current status code of a cluster.

statusName

No

String

Current status name of a cluster.

statusDesc

No

String

Current status description of a cluster.

regionId

No

String

Region where a cluster is currently located.

spuUsed

No

Integer

SPU quota used by a cluster.

maximumSpuQuota

No

Integer

Maximum SPU quota of a cluster.

errorReason

No

String

Cause of the error that results in cluster status exceptions.

createdAt

No

Long

Time when a cluster is created.