Updated on 2024-04-19 GMT+08:00

Querying Public NAT Gateways by Tag

Function

  • This API is used to query public NAT gateways by tag.

  • Tag Management Service (TMS) uses this API to filter and list public NAT gateways.

  • By default, public NAT gateways and their tags are sorted by creation time in descending order.

Constraints

  • You need to add the VPC domain name when calling the API for managing public NAT gateway tags.

Calling Method

For details, see Calling APIs.

URI

POST /v2.0/{project_id}/nat_gateways/resource_instances/action

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the user token. It is a response to the API for obtaining a user token. This API is the only one that does not require authentication. The value of X-Subject-Token in the response header is the token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

tags

No

Array of Tag objects

Specifies the included tags. Each tag has a maximum of 10 keys, and each key has a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value for a tag key must be unique. Resources that contain all keys and one or multiple values listed in tags will be found and returned. If no tag filtering criteria is specified, full data is returned.

Array Length: 1 - 10

tags_any

No

Array of Tag objects

Specifies any included tags. Each tag has a maximum of 10 keys, and each key has a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value for a tag key must be unique. Resources identified by different keys are in OR relationship, and values in one tag are in OR relationship. If no tag filtering criteria is specified, full data is returned.

not_tags

No

Array of Tag objects

Specifies the excluded tags. Each tag has a maximum of 10 keys, and each key has a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value for a tag key must be unique. Resources not identified by different keys are in AND relationship, and values in one tag are in OR relationship. If no tag filtering criteria is specified, full data is returned.

not_tags_any

No

Array of Tag objects

Specifies any excluded tags. Each tag has a maximum of 10 keys, and each key has a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value for a tag key must be unique. Resources not identified by different keys are in OR relationship, and values in one tag are in OR relationship. If no tag filtering criteria is specified, full data is returned.

limit

No

String

Specifies the number of records to be queried. This parameter is not available when action is set to count. When action is set to filter, the default value is 1000, which is also the maximum value. The minimum value is 1. The value cannot be a negative number.

offset

No

String

Specifies the index position. The query starts from the next piece of data indexed by this parameter. This parameter is not required when you query data on the first page. The value in the response returned for querying data on the previous page will be included in this parameter for querying data on subsequent pages. This parameter is not available when action is set to count. When action is set to filter, the value must be a positive number, and the default value is 0.

action

Yes

String

  • Specifies the operation to be performed. The value can only be filter or count.

  • filter indicates pagination query. count indicates that the total number of query results meeting the search criteria will be returned.

matches

No

Array of Match objects

  • Specifies the search criteria. The tag key is the field to match, for example, resource_name. The tag value indicates the matched value. This field is a fixed dictionary value.

  • You can determine whether fuzzy match is required based on different fields. For example, if key is resource_name, fuzzy search (case insensitive) is used by default. If value is an empty string, exact match is used. If key is resource_id, exact match is used.

Table 4 Tag

Parameter

Mandatory

Type

Description

key

Yes

String

Specifies the tag key. A key can contain up to 128 Unicode characters. (The system does not verify key when searching for resources.) key cannot be left blank, be an empty string, or be only spaces. Before using key, delete spaces before and after the value.

values

Yes

Array of strings

  • Specifies the tag value list. Each value can contain a maximum of 255 Unicode characters and cannot contain spaces. Before verification, delete spaces before and after the value. Note the following when adding a tag:

  • The asterisk (*) is a reserved character. The value can be empty but cannot be left blank.

  • If a tag value starts with *, the string following * is fuzzily matched.

  • If values is left blank, it indicates any_value (querying any value). The resources containing one or more values listed in values will be found and displayed.

Table 5 Match

Parameter

Mandatory

Type

Description

key

Yes

String

Specifies the tag key. The value can only be resource_name.

value

Yes

String

Specifies the tag value. It can contain a maximum of 255 Unicode characters.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

resources

Array of Resource objects

Specifies the resource object list. For details, see the Resource field description.

total_count

Integer

Specifies the total number of records.

Table 7 Resource

Parameter

Type

Description

resource_id

String

Specifies the resource ID.

resource_detail

Object

Specifies resource details. The value is a resource object used for extension. This parameter is left blank by default.

tags

Array of ResourceTag objects

Specifies the list of queried tags. If no tag is matched, an empty array is returned. For details, see the ResourceTag field description.

resource_name

String

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

Table 8 ResourceTag

Parameter

Type

Description

key

String

Specifies the tag key. A key can contain up to 128 Unicode characters. key cannot be left blank. A key cannot contain ASCII characters (0–31 decimal) nor the following characters: *<>=

value

String

Specifies the tag value. Each value can contain up to 255 Unicode characters and can be an empty string. A value cannot contain ASCII characters (0–31 decimal) nor the following characters: *<>=

Example Requests

  • Querying public NAT gateways (Setting limit to 100 and action to filter)

    POST  https://{VPC_endpoint}/v2.0/9ad601814ac94c80bf7bb9073ded66fc/nat_gateways/resource_instances/action
    
    {
      "offset" : "100",
      "limit" : "100",
      "action" : "filter",
      "matches" : [ {
        "key" : "resource_name",
        "value" : "nat_gateways"
      } ],
      "not_tags" : [ {
        "key" : "key1",
        "values" : [ "*value1", "value2" ]
      } ],
      "tags" : [ {
        "key" : "key2",
        "values" : [ "*value3", "value4" ]
      } ],
      "tags_any" : [ {
        "key" : "key3",
        "values" : [ "*value5", "value6" ]
      } ],
      "not_tags_any" : [ {
        "key" : "key4",
        "values" : [ "*value7", "value8" ]
      } ]
    }
  • Querying public NAT gateways (Setting action to count)

    POST  https://{VPC_endpoint}/v2.0/9ad601814ac94c80bf7bb9073ded66fc/nat_gateways/resource_instances/action
    
    {
      "action" : "count",
      "matches" : [ {
        "key" : "resource_name",
        "value" : "nat_gateways"
      } ],
      "not_tags" : [ {
        "key" : "key1",
        "values" : [ "*value1", "value2" ]
      } ],
      "tags" : [ {
        "key" : "key2",
        "values" : [ "*value3", "value4" ]
      } ],
      "tags_any" : [ {
        "key" : "key3",
        "values" : [ "*value5", "value6" ]
      } ],
      "not_tags_any" : [ {
        "key" : "key4",
        "values" : [ "*value7", "value8" ]
      } ]
    }

Example Responses

Status code: 200

  • Query operation succeeded.

  • Example 1: the response body when action is set to filter

  • Example 2: the response body when action is set to count

  • Example 1

    {
      "resources" : [ {
        "resource_detail" : null,
        "resource_id" : "e5ad289f-9c56-4daf-b08b-2e53a983473a",
        "resource_name" : "nat_gateways",
        "tags" : [ {
          "key" : "key2",
          "value" : "value4"
        }, {
          "key" : "key2",
          "value" : "value3"
        } ]
      } ],
      "total_count" : 1000
    }
  • Example 2

    {
      "total_count" : 1000
    }

Status Codes

Status Code

Description

200

  • Query operation succeeded.

  • Example 1: the response body when action is set to filter

  • Example 2: the response body when action is set to count

Error Codes

See Error Codes.