• Elastic Load Balancing

elb
  1. Help Center
  2. Elastic Load Balancing
  3. API Reference
  4. Enhanced Load Balancer APIs
  5. Tag
  6. Querying Load Balancers by Tag

Querying Load Balancers by Tag

Function

This API is used to query load balancers using tags.

URI

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

Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the ID of the project where the tag is used.

Constraints

None

Request

  • Request parameters
    Table 2 Parameter description

    Parameter

    Mandatory

    Type

    Description

    tags

    No

    List

    Lists of the load balancers to be queried. A maximum of 10 keys are supported, and each key can have a maximum of 10 values.

    The key cannot be left blank or an empty string.

    Each tag key must be unique, and each tag value in a tag must be unique.

    limit

    No

    String

    Sets the page size. This parameter is available when action is set to filter. Both the default value and maximum value are 1000, and 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. If action is set to filter, the value must be a number, and the default value is 0. The value cannot be a negative number.

    action

    Yes

    String

    Identifies the operation. 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

    List

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

    Determine whether fuzzy match is required based on different fields. For example, if key is resource_name, fuzzy search is used by default. If value is an empty string, exact match is used. If the key is resource_id, exact match is used. Currently, only resource_name can be used for search. For details, see Table 4.

    Table 3 tags field description

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key. It contains a maximum of 127 Unicode characters and cannot be left blank. (This parameter is not verified in the search process.)

    values

    Yes

    List

    Lists the tag values. Each value can contain a maximum of 255 Unicode characters. The values are in the OR relationship.

    If no tag values in the list, the tag key is used for full search. If each value in the list starts with an asterisk (*), fuzzy match is performed based on the part after the asterisk.

    Table 4 matches field description

    Parameter

    Mandatory

    Type

    Description

    key

    Yes

    String

    Specifies the tag key for match.

    The value can be one of the following:

    • resource_name: indicates the resource name.
    • resource_id: indicates the resource ID.

    value

    Yes

    String

    Specifies the tag value for match. Each tag value can contain a maximum of 255 Unicode characters.

  • Example request 1 (when action is set to filter)
    POST https://{Endpoint}/v2.0/6a0de1c3-7d74-4f4a-b75e-e57135bd2b97/loadbalancers/resource_instances/action
    
    {
        "offset": "100", 
        "limit": "100", 
        "action": "filter", 
        "matches": [
            {
                "key": "resource_name", 
                "value": "resource1"
            }
        ], 
        "tags": [
            {
                "key": "key1", 
                "values": [
                    "*value1", 
                    "value2"
                ]
            }
        ]
    }
  • Example request 2 (when action is set to count)
    POST https://{Endpoint}/v2.0/6a0de1c3-7d74-4f4a-b75e-e57135bd2b97/loadbalancers/resource_instances/action
    
    {
        "action": "count", 
        "tags": [
            {
                "key": "key1", elb-realtek
                "values": [
                    "value1", 
                    "value2"
                ]
            }, 
            {
                "key": "key2", 
                "values": [
                    "value1", 
                    "value2"
                ]
            }
        ], 
        "matches": [
            {
                "key": "resource_name", 
                "value": "resource1"
            }
        ]
    }

Response

  • Response parameters
    Table 5 Parameter description

    Parameter

    Type

    Description

    resources

    List

    Lists the load balancers. For details, see Table 6.

    total_count

    Integer

    Specifies the total number of queried records.

    Table 6 resource field description

    Parameter

    Type

    Description

    resource_id

    String

    Specifies the resource ID.

    resource_detail

    Object

    Provides details about the resource. Resource details are used for extension. This value is left blank by default.

    tags

    List

    Lists the tags. If there is no tag, an empty array is used by default. For details, see Table 7.

    resource_name

    String

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

    Table 7 tags field description

    Parameter

    Type

    Description

    key

    String

    Specifies the tag key. It contains a maximum of 127 Unicode characters and cannot be left blank. (This parameter is not verified in the search process.)

    values

    String

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

  • Example response 1 (when action is set to filter)
    {
        "resources": [
            {
                "resource_detail": "", 
                "resource_id": "154d135b-3a89-4e89-8023-06efb9acdc05", 
                "resource_name": "resouece1", 
                "tags": [
                    {
                        "key": "key1", 
                        "value": "value1"
                    }, 
                    {
                        "key": "key2", 
                        "value": "value1"
                    }
                ]
            }
        ], 
        "total_count": 1000
    }
  • Example response 2 (when action is set to count)
    {
        "total_count": 1000
    }

Response Codes

For details, see Response Codes.