查询资源实例接口
功能介绍
使用标签过滤查询租户下资源的实例。
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/{resource_type}/resource_instances/action
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。 最小长度:1 最大长度:64 |
resource_type |
是 |
String |
资源类型,值为:endpoint_service或endpoint。
|
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
Content-Type |
否 |
String |
发送的实体的MIME类型。推荐用户默认使用application/json, 如果API是对象、镜像上传等接口,媒体类型可按照流类型的不同进行确定。 缺省值:application/json |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
tags |
否 |
Array of TagValuesList objects |
包含标签,最多包含10个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复, 同一个key中values不能重复。结果返回包含所有标签的资源列表, key之间是与的关系,key-value结构中value是或的关系。 无tag过滤条件时返回全量数据。 数组长度:1 - 10 |
tags_any |
否 |
Array of TagValuesList objects |
包含任意标签,最多包含10个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。 Key不能重复,同一个key中values不能重复。 结果返回包含标签的资源列表,key之间是或的关系,key、value结构中value是或的关系。 无过滤条件时返回全量数据。 数组长度:1 - 10 |
not_tags |
否 |
Array of TagValuesList objects |
不包含标签,最多包含10个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复, 同一个key中values不能重复。结果返回不包含标签的资源列表,key之间是与的关系, key、value结构中value是或的关系。 无过滤条件时返回全量数据。 数组长度:1 - 10 |
not_tags_any |
否 |
Array of TagValuesList objects |
不包含任意标签,最多包含10个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复, 同一个key中values不能重复。结果返回不包含标签的资源列表, key之间是与的关系,key、value结构中value是或的关系。 无过滤条件时返回全量数据。 数组长度:1 - 10 |
sys_tags |
否 |
Array of TagValuesList objects |
系统标签, |
limit |
否 |
String |
查询记录数(action为count时无此参数)如果action为filter默认为1000, limit最多为1000,不能为负数,最小值为1。 |
offset |
否 |
String |
索引位置,偏移量(action为count时无此参数)从第一条数据偏移offset条数据后开始查询, 如果action为filter默认为0(偏移0条数据,表示从第一条数据开始查询), 必须为数字,不能为负数。 |
action |
是 |
String |
操作标识(仅限于filter,count):filter(过滤), count(查询总条数)如果是filter就按照过滤条件查询, 如果是count,只需要返回总条数,禁止返回其他字段。 |
matches |
否 |
Array of Match objects |
搜索字段,key为要匹配的字段,如resource_name等。value为匹配的值。 key为固定字典值,不能包含重复的key或不支持的key。 根据key的值确认是否需要模糊匹配,如resource_name默认为模糊搜索(不区分大小写), 如果value为空字符串精确匹配(多数服务不存在资源名称为空的情况, 因此此类情况返回空列表)。resource_id为精确匹配。 第一期只做resource_name,后续再扩展。 |
without_any_tag |
否 |
Boolean |
默认为false,取值【true/false】,当withoutAnyTag=true, 忽略tags、tagsAny、notTags、notTagsAny参数校验。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
键。 最大长度128个unicode字符。key不能为空。(搜索时不对此参数做字符集校), key不能为空或者空字符串,不能为空格,校验和使用之前先trim前后半角空格。 最小长度:1 最大长度:128 |
values |
是 |
Array of strings |
值列表。 每个值最大长度255个unicode字符,校验和使用之前先trim前后半角空格。 value可为空数组但不可缺省。如果values为空列表,则表示any_value(查询任意value)。 value之间为或的关系。(搜索时不对此参数做字符集校验,只做长度校验)。 最大长度:255 数组长度:1 - 1000 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
resources |
Array of ResourceInstance objects |
资源实例详情 |
total_count |
Integer |
总记录数。 最小值:1 |
参数 |
参数类型 |
描述 |
---|---|---|
resource_id |
String |
资源ID,Endpoint Service ID或Endpoint ID。 最小长度:1 最大长度:64 |
tags |
Array of TagList objects |
标签列表。 |
resource_name |
String |
资源名称,资源没有名称时,返回ID。 最小长度:0 最大长度:128 |
参数 |
参数类型 |
描述 |
---|---|---|
key |
String |
键。 key不能为空,长度1~128个字符(中文也可以输入128个字符)。 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格,以及以下字符: _ . : = + - @。 _sys_开头属于系统标签,租户不能输入。 key两头不能有空格字符。 最小长度:1 最大长度:128 |
value |
String |
值。 长度0~255个字符(中文也可以输入255个字符)。 可用 UTF-8 格式表示的字母(包含中文、西班牙语、葡语等)、数字和空格,以及以下字符: _ . : / = + - @。 资源标签值可以为空字符串。 最大长度:255 |
请求示例
-
使用标签查询终端节点
POST https://{endpoint}/v1/{project_id}/endpoint/resource_instances/action action为filter时请求体 { "offset": "100", "limit": "100", "action": "filter", "matches": [ { "key": "resource_name", "value": "resource1" } ], "not_tags": [ { "key": "key1", "values": [ "*value1", "value2" ] } ], "tags": [ { "key": "key1", "values": [ "*value1", "value2" ] } ], "tags_any": [ { "key": "key1", "values": [ "value1", "value2" ] } ], "not_tags_any": [ { "key": "key1", "values": [ "value1", "value2" ] } ] }
-
查询终端节点服务资源总数
https://{endpoint}/v1/{project_id}/endpoint_service/ resource_instances/action action为count时请求体 { "action": "count", "not_tags": [ { "key": "key1", "values": [ "value1", "*value2" ] } ], "tags": [ { "key": "key1", "values": [ "value1", "value2" ] }, { "key": "key2", "values": [ "value1", "value2" ] } ], "tags_any": [ { "key": "key1", "values": [ "value1", "value2" ] } ], "not_tags_any": [ { "key": "key1", "values": [ "value1", "value2" ] } ], "matches": [ { "key": "resource_name", "value": "resource1" } ] }
响应示例
状态码: 200
服务器已成功处理了请求
– action为filter时响应体 { "resources": [ { "resource_id": "cdfs_cefs_wesas_12_dsad", "resource_name": "resource1", "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value1" } ] } ], "total_count": 1000 }
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
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.vpcep.v1.region.VpcepRegion; import com.huaweicloud.sdk.vpcep.v1.*; import com.huaweicloud.sdk.vpcep.v1.model.*; public class ListResourceInstancesSolution { 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); VpcepClient client = VpcepClient.newBuilder() .withCredential(auth) .withRegion(VpcepRegion.valueOf("<YOUR REGION>")) .build(); ListResourceInstancesRequest request = new ListResourceInstancesRequest(); try { ListResourceInstancesResponse response = client.listResourceInstances(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 38 39 40 41 42 43 44 45
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.vpcep.v1.region.VpcepRegion; import com.huaweicloud.sdk.vpcep.v1.*; import com.huaweicloud.sdk.vpcep.v1.model.*; public class ListResourceInstancesSolution { 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); VpcepClient client = VpcepClient.newBuilder() .withCredential(auth) .withRegion(VpcepRegion.valueOf("<YOUR REGION>")) .build(); ListResourceInstancesRequest request = new ListResourceInstancesRequest(); try { ListResourceInstancesResponse response = client.listResourceInstances(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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkvpcep.v1.region.vpcep_region import VpcepRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkvpcep.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 = VpcepClient.new_builder() \ .with_credentials(credentials) \ .with_region(VpcepRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListResourceInstancesRequest() response = client.list_resource_instances(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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkvpcep.v1.region.vpcep_region import VpcepRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkvpcep.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 = VpcepClient.new_builder() \ .with_credentials(credentials) \ .with_region(VpcepRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListResourceInstancesRequest() response = client.list_resource_instances(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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" vpcep "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/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 := vpcep.NewVpcepClient( vpcep.VpcepClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListResourceInstancesRequest{} response, err := client.ListResourceInstances(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
查询终端节点服务资源总数
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" vpcep "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpcep/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 := vpcep.NewVpcepClient( vpcep.VpcepClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListResourceInstancesRequest{} response, err := client.ListResourceInstances(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
服务器已成功处理了请求 |
错误码
请参见错误码。