Help Center/ Cloud Connect/ API Reference/ API/ Global Connection Bandwidth Tag Management/ Querying the Number of Global Connection Bandwidth Tags in an Account
Updated on 2024-11-25 GMT+08:00

Querying the Number of Global Connection Bandwidth Tags in an Account

Function

This API is used to query the number of global connection bandwidth tags in an account.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

POST /v3/gcb/resource-instances/count

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

request_id

No

String

Request ID.

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 and each value of the same tag key must be unique. The response returns resources 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 searching condition is specified, full data is returned.

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 and each value of the same tag key must be unique. The response returns resources 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 searching condition is specified, full data is returned.

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. Keys must be unique and values of a 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 searching condition is specified, full data is returned.

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. Keys must be unique and values of a 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 filtering criteria is specified, full data is returned.

matches

No

Array of TmsMatch objects

Whether to match the tags: The tag key must be 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.

Table 3 QueryTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key.

values

Yes

Array of strings

List of tag values.

Table 4 TmsMatch

Parameter

Mandatory

Type

Description

key

Yes

String

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

value

Yes

String

Tag value.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

total_count

Integer

Total records.

request_id

String

Request ID.

Example Requests

Querying the number of global connection bandwidth tags in an account

POST https://{cc_endpoint}/v3/gcb/resource-instances/count

{
  "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" ]
  } ],
  "matches" : [ {
    "key" : "resource_name",
    "value" : "resource1"
  } ]
}

Example Responses

Status code: 200

The number of global connection bandwidth tags in an account has been queried.

{
  "request_id" : "e3371202-7e85-4c16-bb4b-4e3c092734f7",
  "total_count" : 1
}

SDK Sample Code

The SDK sample code is as follows.

Querying the number of global connection bandwidth tags 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
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 CountGcbResourceByTagSolution {

    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();
        CountGcbResourceByTagRequest request = new CountGcbResourceByTagRequest();
        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 {
            CountGcbResourceByTagResponse response = client.countGcbResourceByTag(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 number of global connection bandwidth tags 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
# 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 = CountGcbResourceByTagRequest()
        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.count_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 number of global connection bandwidth tags 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
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.CountGcbResourceByTagRequest{}
	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.CountGcbResourceByTag(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 number of global connection bandwidth tags in an account has been queried.

Error Codes

See Error Codes.