Help Center/ Cloud Connect/ API Reference/ Historical APIs/ Global Private Bandwidth Tag Management/ Querying the Global Private Bandwidth List in an Account
Updated on 2024-03-29 GMT+08:00

Querying the Global Private Bandwidth List in an Account

Function

This API is used to query the global private bandwidth list in an account.

Calling Method

For details, see Calling APIs.

URI

POST /v3/gcb/resource-instances/filter

Table 1 Query Parameters

Parameter

Mandatory

Type

Description

limit

No

Integer

Records to be queried.

Minimum: 1

Maximum: 1000.0

offset

No

Integer

Index position.

Minimum: 0

Maximum: 999

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Minimum: 0

Maximum: 102400

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

request_id

No

String

Request ID.

Minimum: 0

Maximum: 36

without_any_tag

No

Boolean

If this parameter is set to true, all resources without tags are queried. In this case, the tags, tags_any, not_tags, and not_tags_any fields are not required.

tags

No

Array of QueryTag objects

The instances to be queried contain tags listed in tags. Each instance to be queried contains a maximum of 20 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key must be unique, and each tag value for a tag key must be unique. The response returns instances containing all tags in this list. Keys in this list are in the AND relationship and values in each key-value structure are in the OR relationship. If no tag filtering condition is specified, full data is returned.

Array Length: 0 - 50

tags_any

No

Array of QueryTag objects

The instances to be queried contain any tag listed in tags_any. Each instance to be queried contains a maximum of 20 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key must be unique, and each tag value for a tag key must be unique. The response returns instances containing any tag in this list. Keys in this list are in the OR relationship and values in each key-value structure are also in the OR relationship. If no tag filtering criteria is specified, full data is returned.

Array Length: 0 - 50

not_tags

No

Array of QueryTag objects

The instances to be queried do not contain any tag listed in not_tags. Each instance to be queried contains a maximum of 20 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key must be unique, and each tag value for a tag key must be unique. The response returns resources containing no tags in this list. Keys in this list are in the AND relationship and values in each key-value structure are in the OR relationship. If no tag filtering criteria is specified, full data is returned.

Array Length: 0 - 50

not_tags_any

No

Array of QueryTag objects

The instances to be queried do not contain all tags listed in not_tags_any. Each instance to be queried contains a maximum of 20 keys. Each tag key has a maximum of 10 tag values. The tag value corresponding to each tag key can be an empty array but the structure cannot be missing. Each tag key must be unique, and each tag value for a tag key must be unique. The response returns resources containing no tag in this list. Keys in this list are in the OR relationship and values in each key-value structure are also in the OR relationship. If no tag filtering criteria is specified, full data is returned.

Array Length: 0 - 50

matches

No

Array of TmsMatch objects

Whether to match the tags: The tag key is set to resource_name. If there is a tag value, fuzzy matching is used. If the tag value is an empty string, exact matching is used.

Array Length: 0 - 50

Table 4 QueryTag

Parameter

Mandatory

Type

Description

key

Yes

String

Key.

Minimum: 0

Maximum: 128

values

Yes

Array of strings

Tag value list.

Minimum: 0

Maximum: 255

Array Length: 1 - 10

Table 5 TmsMatch

Parameter

Mandatory

Type

Description

key

Yes

String

Key. Currently, only resource_name is supported. Other key values will be available later.

Minimum: 1

Maximum: 128

value

Yes

String

Tag value.

Minimum: 0

Maximum: 255

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

resources

Array of TmsResource objects

Array Length: 0 - 2000

total_count

Integer

Total number of records.

Minimum: 0

Maximum: 2000.0

request_id

String

Request ID

Minimum: 0

Maximum: 36

Table 7 TmsResource

Parameter

Type

Description

resource_id

String

Resource ID.

Minimum: 1

Maximum: 36

tags

Array of Tag objects

Tag list. If no tag is matched, an empty array is returned.

Array Length: 0 - 20

resource_name

String

Resource name. This parameter is an empty string by default if there is no resource name.

Minimum: 1

Maximum: 64

Table 8 Tag

Parameter

Type

Description

key

String

Tag key.

Minimum: 1

Maximum: 128

value

String

Tag value.

Minimum: 0

Maximum: 255

Example Requests

Querying the global private bandwidth list in an account

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" ]
  } ]
}

Example Responses

Status code: 200

The global private bandwidth list in an account has been queried.

{
  "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 Sample Code

The SDK sample code is as follows.

Querying the global private bandwidth list in an account

 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
97
98
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.v2.region.CcRegion;
import com.huaweicloud.sdk.cc.v2.*;
import com.huaweicloud.sdk.cc.v2.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();
        request.withLimit(<limit>);
        request.withOffset(<offset>);
        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());
        }
    }
}

Querying the global private bandwidth list in an account

 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcc.v2.region.cc_region import CcRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcc.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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("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()
        request.limit = <limit>
        request.offset = <offset>
        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)

Querying the global private bandwidth list in an account

 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
package main

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

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

    request := &model.ListGcbResourceByTagRequest{}
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	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)
    }
}

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 global private bandwidth list in an account has been queried.

Error Codes

See Error Codes.