文档首页/ 云连接 CC/ API参考/ API/ 全域互联带宽标签管理/ 查询账户全域互联带宽资源实例列表
更新时间:2024-11-25 GMT+08:00

查询账户全域互联带宽资源实例列表

功能介绍

查询账户全域互联带宽资源实例列表

调试

您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。

URI

POST /v3/gcb/resource-instances/filter

表1 Query参数

参数

是否必选

参数类型

描述

limit

Integer

查询记录数。

offset

Integer

索引位置,偏移量。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

表3 请求Body参数

参数

是否必选

参数类型

描述

request_id

String

请求ID。

without_any_tag

Boolean

不包含任意一个标签,该字段为true时查询所有不带标签的资源,此时忽略 “tags”、“tags_any”、“not_tags”、“not_tags_any”字段。

tags

Array of QueryTag objects

包含标签,最多包含20个key,每个key下面的value最多10个,每个key对应的value可以为空数组但结构体不能缺失。Key不能重复,同一个key中values不能重复。结果返回包含所有标签的资源列表,key之间是与的关系,key-value结构中value是或的关系。无tag过滤条件时返回全量数据。

tags_any

Array of QueryTag objects

包含任意标签,最多包含20个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复,同一个key中values不能重复。结果返回包含标签的资源列表,key之间是或的关系,key-value结构中value是或的关系。无过滤条件时返回全量数据。

not_tags

Array of QueryTag objects

不包含标签,最多包含20个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复,同一个key中values不能重复。结果返回不包含标签的资源列表,key之间是与的关系,key-value结构中value是或的关系。无过滤条件时返回全量数据。

not_tags_any

Array of QueryTag objects

不包含任意标签,最多包含20个key,每个key下面的value最多10个, 每个key对应的value可以为空数组但结构体不能缺失。Key不能重复,同一个key中values不能重复。结果返回不包含标签的资源列表,key之间是或的关系,key-value结构中value是或的关系。无过滤条件时返回全量数据。

matches

Array of TmsMatch objects

是否匹配以下tag,key必须为"resource_name",value如果有值则模糊匹配,如果为空字符串则精确匹配。

表4 QueryTag

参数

是否必选

参数类型

描述

key

String

键。

values

Array of strings

值列表。

表5 TmsMatch

参数

是否必选

参数类型

描述

key

String

键。第一期限定为resource_name,后续扩展。

value

String

值。

响应参数

状态码: 200

表6 响应Body参数

参数

参数类型

描述

resources

Array of TmsResource objects

资源列表。

total_count

Integer

总记录数。

request_id

String

请求ID。

表7 TmsResource

参数

参数类型

描述

resource_id

String

资源ID。

tags

Array of Tag objects

标签列表,没有标签默认为空数组。

resource_name

String

资源名称,资源没有名称时默认为空字符串。

表8 Tag

参数

参数类型

描述

key

String

标签键,最大长度128个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,中文。

value

String

标签值,最大长度255个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,点“.”,中文。

请求示例

查询账户全域互联带宽资源实例列表

POST https://{cc_endpoint}/v3/gcb/resource-instances/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" ]
  } ]
}

响应示例

状态码: 200

查询账户全域互联带宽资源实例列表。

{
  "resources" : [ {
    "resource_id" : "cb9d7ead-834a-4275-93e1-217f79df9dc1",
    "resource_name" : "test",
    "tags" : [ {
      "key" : "key1",
      "value" : "value1"
    } ]
  } ],
  "request_id" : "e3371202-7e85-4c16-bb4b-4e3c092734f7",
  "total_count" : 1
}

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.cc.v3.region.CcRegion;
import com.huaweicloud.sdk.cc.v3.*;
import com.huaweicloud.sdk.cc.v3.model.*;

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

public class ListGcbResourceByTagSolution {

    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 GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CcClient client = CcClient.newBuilder()
                .withCredential(auth)
                .withRegion(CcRegion.valueOf("<YOUR REGION>"))
                .build();
        ListGcbResourceByTagRequest request = new ListGcbResourceByTagRequest();
        QueryResourceByTagRequestBody body = new QueryResourceByTagRequestBody();
        List<TmsMatch> listbodyMatches = new ArrayList<>();
        listbodyMatches.add(
            new TmsMatch()
                .withKey("resource_name")
                .withValue("resource1")
        );
        List<String> listNotTagsAnyValues = new ArrayList<>();
        listNotTagsAnyValues.add("value1");
        listNotTagsAnyValues.add("value2");
        List<QueryTag> listbodyNotTagsAny = new ArrayList<>();
        listbodyNotTagsAny.add(
            new QueryTag()
                .withKey("key1")
                .withValues(listNotTagsAnyValues)
        );
        List<String> listNotTagsValues = new ArrayList<>();
        listNotTagsValues.add("value1");
        listNotTagsValues.add("value2");
        List<QueryTag> listbodyNotTags = new ArrayList<>();
        listbodyNotTags.add(
            new QueryTag()
                .withKey("key1")
                .withValues(listNotTagsValues)
        );
        List<String> listTagsAnyValues = new ArrayList<>();
        listTagsAnyValues.add("value1");
        listTagsAnyValues.add("value2");
        List<QueryTag> listbodyTagsAny = new ArrayList<>();
        listbodyTagsAny.add(
            new QueryTag()
                .withKey("key1")
                .withValues(listTagsAnyValues)
        );
        List<String> listTagsValues = new ArrayList<>();
        listTagsValues.add("value1");
        listTagsValues.add("value2");
        List<QueryTag> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new QueryTag()
                .withKey("key1")
                .withValues(listTagsValues)
        );
        body.withMatches(listbodyMatches);
        body.withNotTagsAny(listbodyNotTagsAny);
        body.withNotTags(listbodyNotTags);
        body.withTagsAny(listbodyTagsAny);
        body.withTags(listbodyTags);
        request.withBody(body);
        try {
            ListGcbResourceByTagResponse response = client.listGcbResourceByTag(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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcc.v3.region.cc_region import CcRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcc.v3 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 = GlobalCredentials(ak, sk)

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

    try:
        request = ListGcbResourceByTagRequest()
        listMatchesbody = [
            TmsMatch(
                key="resource_name",
                value="resource1"
            )
        ]
        listValuesNotTagsAny = [
            "value1",
            "value2"
        ]
        listNotTagsAnybody = [
            QueryTag(
                key="key1",
                values=listValuesNotTagsAny
            )
        ]
        listValuesNotTags = [
            "value1",
            "value2"
        ]
        listNotTagsbody = [
            QueryTag(
                key="key1",
                values=listValuesNotTags
            )
        ]
        listValuesTagsAny = [
            "value1",
            "value2"
        ]
        listTagsAnybody = [
            QueryTag(
                key="key1",
                values=listValuesTagsAny
            )
        ]
        listValuesTags = [
            "value1",
            "value2"
        ]
        listTagsbody = [
            QueryTag(
                key="key1",
                values=listValuesTags
            )
        ]
        request.body = QueryResourceByTagRequestBody(
            matches=listMatchesbody,
            not_tags_any=listNotTagsAnybody,
            not_tags=listNotTagsbody,
            tags_any=listTagsAnybody,
            tags=listTagsbody
        )
        response = client.list_gcb_resource_by_tag(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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cc/v3/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 := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cc.NewCcClient(
        cc.CcClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListGcbResourceByTagRequest{}
	var listMatchesbody = []model.TmsMatch{
        {
            Key: "resource_name",
            Value: "resource1",
        },
    }
	var listValuesNotTagsAny = []string{
        "value1",
	    "value2",
    }
	var listNotTagsAnybody = []model.QueryTag{
        {
            Key: "key1",
            Values: listValuesNotTagsAny,
        },
    }
	var listValuesNotTags = []string{
        "value1",
	    "value2",
    }
	var listNotTagsbody = []model.QueryTag{
        {
            Key: "key1",
            Values: listValuesNotTags,
        },
    }
	var listValuesTagsAny = []string{
        "value1",
	    "value2",
    }
	var listTagsAnybody = []model.QueryTag{
        {
            Key: "key1",
            Values: listValuesTagsAny,
        },
    }
	var listValuesTags = []string{
        "value1",
	    "value2",
    }
	var listTagsbody = []model.QueryTag{
        {
            Key: "key1",
            Values: listValuesTags,
        },
    }
	request.Body = &model.QueryResourceByTagRequestBody{
		Matches: &listMatchesbody,
		NotTagsAny: &listNotTagsAnybody,
		NotTags: &listNotTagsbody,
		TagsAny: &listTagsAnybody,
		Tags: &listTagsbody,
	}
	response, err := client.ListGcbResourceByTag(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查询账户全域互联带宽资源实例列表。

错误码

请参见错误码