Querying Transit IP Addresses by Tag
Function
-
This API is used to query transit IP addresses by tag.
-
TMS uses this API to filter and list transit IP addresses by tag.
Calling Method
For details, see Calling APIs.
URI
POST /v3/{project_id}/transit-ips/resource_instances/action
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Specifies the project ID. |
Request 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 value. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
offset |
No |
String |
Specifies the index position. The query starts from the next data record indexed by this parameter. When querying resources on the first page, you do not need to specify this parameter. When querying resources on subsequent pages, set this parameter to the value returned in the response body for querying resources on the previous page. This parameter is not available when action is set to count. If action is set to filter, the value must be a positive number, and the default value is 0. |
limit |
No |
String |
Specifies the number of records to be queried. This parameter is not available when action is set to count. If 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. |
action |
Yes |
String |
Specifies the operation to be performed. The value can be filter or count. The value filter indicates pagination query. The value 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 field. The tag key is the field to be matched, for example, resource_name. The tag value indicates the value to be matched. This field is a fixed dictionary value. You can determine whether fuzzy match is required based on different fields. For example, if key is set to resource_name, fuzzy search (case insensitive) is used by default. If value is an empty string, exact match is used. If key is set to resource_id, exact match is used. Currently, only resource_name is supported. |
not_tags |
No |
Array of Tags objects |
The resources to be queried do not contain tags listed in not_tags. Each resource to be queried contains a maximum of 20 keys. Each tag key can have a maximum of 20 tag 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 in a tag must be unique.Resources that do not contain the tags listed in not_tags will be returned.Keys are in AND relationship, and values in a tag are in OR relationship.If this parameter is not specified, all resources will be returned. |
tags |
No |
Array of Tags objects |
The resources to be queried contain tags listed in tags. Each resource to be queried contains a maximum of 20 keys. Each tag key can have a maximum of 20 tag 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 in a tag must be unique.Resources that contain the tags listed in *tags will be returned.Keys are in AND relationship, and values in a tag are in OR relationship.If this parameter is not specified, all resources will be returned. |
tags_any |
No |
Array of Tags objects |
The resources to be queried contain any tag listed in tags_any. Each resource to be queried contains a maximum of 20 keys. Each tag key can have a maximum of 20 tag 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 in a tag must be unique.Resources that contain any tag listed in *tags_any will be returned.Keys are in AND relationship, and values in a tag are in OR relationship.If this parameter is not specified, all resources will be returned. |
not_tags_any |
No |
Array of Tags objects |
The resources to be queried do not contain any tag listed in not_tags_any. Each resource to be queried contains a maximum of 20 keys. Each tag key can have a maximum of 20 tag 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 in a tag must be unique.Resources that do not contain any tag listed in not_tags_any will be returned.Keys are in AND relationship, and values in a tag are in OR relationship.If this parameter is not specified, all resources will be returned. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
Yes |
String |
Specifies the tag key used to search for resources. |
value |
Yes |
String |
Specifies the tag value used to search for resources. |
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 or be an empty string. key cannot contain spaces. Before using the value of key, delete spaces before and after the value. |
values |
Yes |
Array of strings |
Specifies the list of tag values. Each value can contain a maximum of 255 Unicode characters and cannot contain spaces. Before verification and use, delete spaces before and after the value. The value can be an empty array but cannot be left blank. If values is not specified, any parameter value can be queried. All values of a tag key are in the OR relationship. The system verifies the length, but not the character set of values when searching for resources. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
resources |
Array of Resource objects |
Specifies the resource list. |
request_id |
String |
Specifies the request ID. |
total_count |
Integer |
Specifies the total number of records. |
Parameter |
Type |
Description |
---|---|---|
resource_detail |
Object |
Specifies the resource details. This parameter is used for extension and is left blank by default. |
resource_id |
String |
Specifies the resource ID. |
resource_name |
String |
Specifies the resource name. This parameter is an empty string by default if there is no resource name. |
resource_tag |
Array of ResourceTag objects |
Specifies the list of queried tags. If no tag is matched, an empty array is returned. |
Example Requests
-
Querying transit IP addresses by tag (Setting action to filter and limit to 1000)
POST https://{Endpoint}/v3/cfa563efb77d4b6d9960781d82530fd8/transit-ips/resource_instances/action { "offset" : "0", "limit" : "1000", "action" : "filter", "not_tags_any" : [ { "key" : "owner", "values" : "tag_1_value" } ] }
-
Querying transit IP addresses by tag (Setting action to count and adding tags)
POST https://{Endpoint}/v3/cfa563efb77d4b6d9960781d82530fd8/transit-ips/resource_instances/action { "action" : "count", "tags" : [ { "key" : "key1", "values" : [ "value1", "value2" ] } ], "matches" : [ { "key" : "resource_name", "value" : "resource1" } ] }
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" : "ae33be9b-d2c0-441b-a8d0-f6dafedf1778", "resource_name" : "transit_ips", "resource_tag" : [ { "key" : "key1", "value" : "value1" }, { "key" : "key2", "value" : "value1" } ] } ], "request_id" : "9e47d9476cfd346f864cb77acb274185", "total_count" : 1 }
-
Example 2
{ "request_id" : "d70aabc854d3d301f9bb106e6b70ac99", "total_count" : 100 }
SDK Sample Code
The SDK sample code is as follows.
-
Querying transit IP addresses by tag (Setting action to filter and limit to 1000)
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
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.nat.v2.region.NatRegion; import com.huaweicloud.sdk.nat.v2.*; import com.huaweicloud.sdk.nat.v2.model.*; import java.util.List; import java.util.ArrayList; public class ListTransitIpsByTagsSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); NatClient client = NatClient.newBuilder() .withCredential(auth) .withRegion(NatRegion.valueOf("<YOUR REGION>")) .build(); ListTransitIpsByTagsRequest request = new ListTransitIpsByTagsRequest(); ListTagResourceInstancesRequestBody body = new ListTagResourceInstancesRequestBody(); List<Tags> listbodyNotTagsAny = new ArrayList<>(); listbodyNotTagsAny.add( new Tags() .withKey("owner") .withValues() ); body.withNotTagsAny(listbodyNotTagsAny); body.withAction(ListTagResourceInstancesRequestBody.ActionEnum.fromValue("filter")); body.withLimit("1000"); body.withOffset("0"); request.withBody(body); try { ListTransitIpsByTagsResponse response = client.listTransitIpsByTags(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 transit IP addresses by tag (Setting action to count and adding tags)
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
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.nat.v2.region.NatRegion; import com.huaweicloud.sdk.nat.v2.*; import com.huaweicloud.sdk.nat.v2.model.*; import java.util.List; import java.util.ArrayList; public class ListTransitIpsByTagsSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); NatClient client = NatClient.newBuilder() .withCredential(auth) .withRegion(NatRegion.valueOf("<YOUR REGION>")) .build(); ListTransitIpsByTagsRequest request = new ListTransitIpsByTagsRequest(); ListTagResourceInstancesRequestBody body = new ListTagResourceInstancesRequestBody(); List<String> listTagsValues = new ArrayList<>(); listTagsValues.add("value1"); listTagsValues.add("value2"); List<Tags> listbodyTags = new ArrayList<>(); listbodyTags.add( new Tags() .withKey("key1") .withValues(listTagsValues) ); List<Match> listbodyMatches = new ArrayList<>(); listbodyMatches.add( new Match() .withKey("resource_name") .withValue("resource1") ); body.withTags(listbodyTags); body.withMatches(listbodyMatches); body.withAction(ListTagResourceInstancesRequestBody.ActionEnum.fromValue("count")); request.withBody(body); try { ListTransitIpsByTagsResponse response = client.listTransitIpsByTags(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 transit IP addresses by tag (Setting action to filter and limit to 1000)
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdknat.v2.region.nat_region import NatRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdknat.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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = NatClient.new_builder() \ .with_credentials(credentials) \ .with_region(NatRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListTransitIpsByTagsRequest() listNotTagsAnybody = [ Tags( key="owner", ) ] request.body = ListTagResourceInstancesRequestBody( not_tags_any=listNotTagsAnybody, action="filter", limit="1000", offset="0" ) response = client.list_transit_ips_by_tags(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 transit IP addresses by tag (Setting action to count and adding tags)
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdknat.v2.region.nat_region import NatRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdknat.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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = NatClient.new_builder() \ .with_credentials(credentials) \ .with_region(NatRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListTransitIpsByTagsRequest() listValuesTags = [ "value1", "value2" ] listTagsbody = [ Tags( key="key1", values=listValuesTags ) ] listMatchesbody = [ Match( key="resource_name", value="resource1" ) ] request.body = ListTagResourceInstancesRequestBody( tags=listTagsbody, matches=listMatchesbody, action="count" ) response = client.list_transit_ips_by_tags(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 transit IP addresses by tag (Setting action to filter and limit to 1000)
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" nat "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := nat.NewNatClient( nat.NatClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListTransitIpsByTagsRequest{} var listNotTagsAnybody = []model.Tags{ { Key: "owner", }, } limitListTagResourceInstancesRequestBody:= "1000" offsetListTagResourceInstancesRequestBody:= "0" request.Body = &model.ListTagResourceInstancesRequestBody{ NotTagsAny: &listNotTagsAnybody, Action: model.GetListTagResourceInstancesRequestBodyActionEnum().FILTER, Limit: &limitListTagResourceInstancesRequestBody, Offset: &offsetListTagResourceInstancesRequestBody, } response, err := client.ListTransitIpsByTags(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Querying transit IP addresses by tag (Setting action to count and adding tags)
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" nat "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := nat.NewNatClient( nat.NatClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListTransitIpsByTagsRequest{} var listValuesTags = []string{ "value1", "value2", } var listTagsbody = []model.Tags{ { Key: "key1", Values: listValuesTags, }, } var listMatchesbody = []model.Match{ { Key: "resource_name", Value: "resource1", }, } request.Body = &model.ListTagResourceInstancesRequestBody{ Tags: &listTagsbody, Matches: &listMatchesbody, Action: model.GetListTagResourceInstancesRequestBodyActionEnum().COUNT, } response, err := client.ListTransitIpsByTags(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 |
Query operation succeeded.
|
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot