Updated on 2024-09-26 GMT+08:00

Querying Forwarding Policies

Function

This API is used to query all forwarding policies.

Constraints

This API has the following constraints:

  • Parameters marker, limit, and page_reverse are used for pagination query.

  • Parameters marker and page_reverse take effect only when they are used together with parameter limit.

Calling Method

For details, see Calling APIs.

URI

GET /v3/{project_id}/elb/l7policies

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

marker

No

String

Specifies the ID of the last record on the previous page.

Notes and constraints:

  • This parameter must be used together with limit.

  • If this parameter is not specified, the first page will be queried.

  • This parameter cannot be left blank or set to an invalid ID.

limit

No

Integer

Specifies the number of records on each page.

The value ranges from 0 to 2,000, and the default value is 2,000.

page_reverse

No

Boolean

Specifies whether to use reverse query. The value can be:

  • true: Query the previous page.

  • false (default): Query the next page.

Notes and constraints:

  • This parameter must be used together with limit.

  • If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker.

enterprise_project_id

No

Array of strings

Specifies the enterprise project ID.

  • If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project.

  • If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried).

Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx.

id

No

Array of strings

Specifies the forwarding policy ID.

Multiple IDs can be queried in the format of id=xxx&id=xxx.

name

No

Array of strings

Specifies the forwarding policy name.

Multiple names can be queried in the format of name=xxx&name=xxx.

description

No

Array of strings

Provides supplementary information about the forwarding policy.

Multiple descriptions can be queried in the format of description=xxx&description=xxx.

admin_state_up

No

Boolean

Specifies the administrative status of the forwarding policy.

listener_id

No

Array of strings

Specifies the ID of the listener to which the forwarding policy is added.

Multiple IDs can be queried in the format of listener_id=xxx&listener_id=xxx.

position

No

Array of integers

Specifies the forwarding policy priority.

Multiple priorities can be queried in the format of position=xxx&position=xxx.

This parameter is unsupported. Please do not use it.

action

No

Array of strings

Specifies where requests are forwarded. The value can be one of the following:

  • REDIRECT_TO_POOL: Requests are forwarded to another backend server group.

  • REDIRECT_TO_LISTENER: Requests are redirected to an HTTPS listener.

  • REDIRECT_TO_URL: Requests are redirected to another URL.

  • FIXED_RESPONSE: A fixed response body is returned.

Multiple values can be queried in the format of action=xxx&action=xxx.

redirect_url

No

Array of strings

Specifies the URL to which requests will be forwarded.

Multiple URLs can be queried in the format of redirect_url=xxx&redirect_url=xxx.

This parameter is unsupported. Please do not use it.

redirect_pool_id

No

Array of strings

Specifies the ID of the backend server group to which requests will be forwarded.

Multiple IDs can be queried in the format of redirect_pool_id=xxx&redirect_pool_id=xxx.

redirect_listener_id

No

Array of strings

Specifies the ID of the listener to which requests are redirected.

Multiple IDs can be queried in the format of redirect_listener_id=xxx&redirect_listener_id=xxx.

provisioning_status

No

Array of strings

Specifies the provisioning status of the forwarding policy.

The value can be:

  • ACTIVE: The forwarding policy is provisioned successfully.

  • ERROR: The forwarding policy has the same rule as another forwarding policy added to the same listener.

Multiple provisioning statuses can be queried in the format of provisioning_status=xxx&provisioning_status=xxx.

display_all_rules

No

Boolean

Specifies whether to display details about the forwarding rule in the forwarding policy.

  • true: Details about the forwarding rule are displayed.

  • false: Only the rule ID is displayed.

priority

No

Array of integers

Specifies the forwarding policy priority. A smaller value indicates a higher priority.

Multiple priorities can be queried in the format of priority=xxx&priority=xxx.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the token used for IAM authentication.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID.

Note: The value is automatically generated.

page_info

PageInfo object

Shows pagination information.

l7policies

Array of L7Policy objects

Lists the forwarding policies.

Table 5 PageInfo

Parameter

Type

Description

previous_marker

String

Specifies the ID of the first record in the pagination query result.

next_marker

String

Specifies the ID of the last record in the pagination query result.

current_count

Integer

Specifies the number of records.

Table 6 L7Policy

Parameter

Type

Description

action

String

Specifies where requests will be forwarded.

The value can be one of the following:

  • REDIRECT_TO_POOL: Requests will be forwarded to another backend server group.

  • REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener.

  • REDIRECT_TO_URL: Requests will be redirected to another URL.

  • FIXED_RESPONSE: A fixed response body will be returned.

Notes and constraints:

  • REDIRECT_TO_LISTENER has the highest priority. If requests are to be redirected to an HTTPS listener, other forwarding policies of the listener will become invalid.

  • If action is set to REDIRECT_TO_POOL, the listener's protocol must be HTTP, TERMINATED_HTTPS, or HTTPS.

  • If action is set to REDIRECT_TO_LISTENER, the listener's protocol must be HTTP.

admin_state_up

Boolean

Specifies the administrative status of the forwarding policy. The value can only be true.

description

String

Provides supplementary information about the forwarding policy.

id

String

Specifies the forwarding policy ID.

listener_id

String

Specifies the ID of the listener to which the forwarding policy is added.

name

String

Specifies the forwarding policy name.

position

Integer

Specifies the forwarding policy priority. This parameter cannot be updated.

This parameter is unsupported. Please do not use it.

priority

Integer

Specifies the forwarding policy priority. A smaller value indicates a higher priority.

Value ranges:

  • If action is set to REDIRECT_TO_LISTENER, the priority ranges from 0 to 10,000.

  • If action is set to other values, the priority ranges from 1 to 10,000.

Default values:

  • If this parameter is not passed and enhance_l7policy_enable is set to false, the priority of the new forwarding policy is 1.

  • If action is set to REDIRECT_TO_LISTENER, the priority of the new forwarding policy is 0.

  • If action is set to other values, the priority of the new forwarding policy will be a sum of 1 and the highest priority of existing forwarding policy in the same listener by default.

    • If no forwarding policies exist, the priority of the new forwarding policy will be 1 by default.

    • If the highest priority of existing forwarding policies is the maximum value (10,000), the forwarding policy will fail to be created because the final priority for creating the forwarding policy is the sum of 1 and 10,000, which exceeds the maximum value. In this case, specify a value or adjust the priorities of existing forwarding policies.

Notes and constraints:

  • The value must be unique for forwarding policies of the same listener.

  • This parameter takes effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned.

  • If enhance_l7policy_enable is not enabled, forwarding policies are automatically prioritized based on the original policy sorting logic. The priorities of domain names are independent from each other. For the same domain name, the priorities are sorted in the order of exact match (EQUAL_TO), prefix match (STARTS_WITH), and regular expression match (REGEX). If the matching types are the same, the longer the path is, the higher the priority is. If a forwarding policy contains only a domain name without a path specified, the path is /, and prefix match is used by default.

This parameter is supported by forwarding policies of shared load balancers.

project_id

String

Specifies the project ID of the forwarding policy.

provisioning_status

String

Specifies the provisioning status of the forwarding policy.

The value can be:

  • ACTIVE (default): The forwarding policy is provisioned successfully.

  • ERROR: Another forwarding policy of the same listener has the same forwarding rule.

redirect_pool_id

String

Specifies the ID of the backend server group to which the requests are forwarded.

Notes and constraints: This parameter is valid only when action is set to REDIRECT_TO_POOL.

redirect_listener_id

String

Specifies the ID of the listener to which requests are redirected.

Notes and constraints:

  • This parameter is mandatory when action is set to REDIRECT_TO_LISTENER.

  • The listener's protocol must be HTTPS or TERMINATED_HTTPS.

  • A listener added to another load balancer is not allowed.

  • This parameter cannot be passed in the API for adding or updating a forwarding policy if action is set to REDIRECT_TO_POOL.

redirect_url

String

Specifies the URL to which requests are forwarded.

Format: protocol://host:port/path?query

This parameter is unsupported. Please do not use it.

rules

Array of RuleRef objects

Lists the forwarding rules in the forwarding policy.

redirect_url_config

RedirectUrlConfig object

Specifies the URL to which requests are forwarded.

Notes and constraints:

  • This parameter will take effect only when advanced forwarding is enabled (enhance_l7policy_enable is set to true). If it is passed when enhance_l7policy_enable is set to false, an error will be returned.

  • This parameter is mandatory when action is set to REDIRECT_TO_URL. It cannot be specified if the value of action is not REDIRECT_TO_URL.

  • For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned.

  • At least one of the four parameters (protocol, host, port, and path) must be passed, or their values cannot be set to ${xxx} at the same time. ${xxx} indicates that the value in the request will be used. For example, ${host} indicates the host in the URL to be redirected.

  • The values of protocol and port cannot be the same as those of the associated listener, and either host or path must be passed or their values cannot be ${xxx} at the same time.

Value format: protocol://host:port/path?query

redirect_pools_extend_config

RedirectPoolsExtendConfig object

Specifies the backend server group that the requests are forwarded to.

Notes and constraints:

This parameter is valid only when action is set to REDIRECT_TO_POOL.

fixed_response_config

FixtedResponseConfig object

Specifies the configuration of the page that will be returned.

Notes and constraints:

  • This parameter will take effect when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned.

  • This parameter is mandatory when action is set to FIXED_RESPONSE. It cannot be specified if the value of action is not FIXED_RESPONSE.

  • For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned.

created_at

String

Specifies the time when the forwarding policy was added.

The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

updated_at

String

Specifies the time when the forwarding policy was updated.

The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

Table 7 RuleRef

Parameter

Type

Description

id

String

Specifies the forwarding rule ID.

Table 8 RedirectUrlConfig

Parameter

Type

Description

protocol

String

Specifies the protocol for redirection.

The value can be HTTP, HTTPS, or ${protocol}.

The default value is ${protocol}, indicating that the protocol of the request will be used.

host

String

Specifies the host name that requests are redirected to.

The value can contain only letters, digits, hyphens (-), and periods (.) and must start with a letter or digit.

The default value is ${host}, indicating that the host of the request will be used.

port

String

Specifies the port that requests are redirected to.

The default value is ${port}, indicating that the port of the request will be used.

path

String

Specifies the path that requests are redirected to.

The value can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|\/()[]{} and must start with a slash (/).

The default value is ${path}, indicating that the path of the request will be used.

query

String

Specifies the query string set in the URL for redirection.

The value is case-sensitive and can contain only letters, digits, and special characters: !$&'()*+,-./:;=?@^_`. $1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL.

The default value is ${query}, indicating that the query string of the request will be used.

For example, in the URL https://www.example.com:8080/elb?type=loadbalancer, ${query} indicates type=loadbalancer. If this parameter is set to ${query}&name=my_name, the URL will be redirected to https://www.example.com:8080/elb?type=loadbalancer&name=my_name.

status_code

String

Specifies the status code returned after the requests are redirected.

The value can be 301, 302, 303, 307, or 308.

Table 9 RedirectPoolsExtendConfig

Parameter

Type

Description

rewrite_url_enable

Boolean

Specifies whether to enable URL redirection.

rewrite_url_config

RewriteUrlConfig object

Specifies the URL for the backend server group that requests are forwarded to. This parameter is valid when rewrite_url_enable is set to true.

Table 10 RewriteUrlConfig

Parameter

Type

Description

host

String

Specifies the rewritten host that requests are redirected to.

The string can contain only letters, digits, hyphens (-), and periods (.), and must start with a letter or digit.

The default value is ${host}, indicating that the host of the request will be used.

path

String

Specifies the path that requests are redirected to.

The default value is ${path}, indicating that the path of the request will be used. The value can contain only letters, digits, and special characters _~';@^-%#&$.+?,=!:|/() and must start with a slash (/).

$1, $2, $3, and all the way to $9 match the wildcard asterisk (*) in the request URL. If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

query

String

Specifies the query string set in the URL for redirection.

The value is case-sensitive and can contain only letters, digits, and special characters: !$&'()+,-./:;=?@^_`. $1, $2, $3, and all the way to $9 match the wildcard asterisk () in the request URL.

The default value is ${query}, indicating that the query string of the request will be used.

If the number of regular expression match groups is less than the specified number, ${path} is empty. If the dollar sign ($) is followed by a letter, the matching result is empty until the next special character appears, for example, $abc#123, and the matching result is #123. If the dollar sign ($) is followed by a special character, for example, $#, the matching result is $#.

Table 11 FixtedResponseConfig

Parameter

Type

Description

status_code

String

Specifies the HTTP status code configured in the forwarding policy. The value can be any integer in the range of 200–299, 400–499, or 500–599.

content_type

String

Specifies the format of the response body.

The value can be text/plain, text/css, text/html, application/javascript, or application/json.

message_body

String

Specifies the content of the response message body.

Example Requests

Querying forwarding policies

GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/l7policies?display_all_rules=true

Example Responses

Status code: 200

Successful request.

{
  "request_id" : "d3c67339-be91-4813-bb24-85728a5d326a",
  "l7policies" : [ {
    "redirect_pool_id" : "768e9e8c-e7cb-4fef-b24b-af9399dbb240",
    "description" : "",
    "admin_state_up" : true,
    "rules" : [ {
      "id" : "c5c2d625-676b-431e-a4c7-c59cc2664881"
    } ],
    "project_id" : "7a9941d34fc1497d8d0797429ecfd354",
    "listener_id" : "cdb03a19-16b7-4e6b-bfec-047aeec74f56",
    "redirect_url" : null,
    "redirect_url_config" : null,
    "redirect_pools_config" : {
      "pool_id" : "722e9e8c-e7cb-4fef-b24b-af9399dbb240",
      "weight" : 12
    },
    "redirect_pools_sticky_session_config" : {
      "timeout" : 23,
      "enable" : false
    },
    "fixed_response_config" : null,
    "redirect_listener_id" : null,
    "action" : "REDIRECT_TO_POOL",
    "position" : 100,
    "priority" : null,
    "provisioning_status" : "ACTIVE",
    "id" : "01832d99-bbd8-4340-9d0c-6ff8f7a37307",
    "name" : "l7policy-67"
  }, {
    "redirect_pool_id" : null,
    "description" : "",
    "admin_state_up" : true,
    "rules" : [ {
      "id" : "390f3a9f-670d-4ca6-b72c-6be8a48a8a00"
    } ],
    "project_id" : "7a9941d34fc1497d8d0797429ecfd354",
    "listener_id" : "bd782cbf-fb5e-411a-9295-530bdec05058",
    "redirect_url" : null,
    "redirect_url_config" : null,
    "redirect_pools_config" : {
      "pool_id" : "722e9e8c-e7cb-4fef-b24b-af9399dbb240",
      "weight" : 12
    },
    "redirect_pools_sticky_session_config" : {
      "timeout" : 23,
      "enable" : false
    },
    "fixed_response_config" : {
      "content_type" : "text/plain",
      "message_body" : "",
      "status_code" : "207"
    },
    "redirect_listener_id" : null,
    "action" : "FIXED_RESPONSE",
    "position" : 6,
    "priority" : 2,
    "provisioning_status" : "ACTIVE",
    "id" : "049a8635-9754-444e-94aa-678993b39cd6",
    "name" : "l7policy-67"
  } ],
  "page_info" : {
    "next_marker" : "2587d8b1-9e8d-459c-9081-7bccaa075d2b",
    "previous_marker" : "01832d99-bbd8-4340-9d0c-6ff8f7a37307",
    "current_count" : 2
  }
}

SDK Sample Code

The SDK sample code is as follows.

 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
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.elb.v3.region.ElbRegion;
import com.huaweicloud.sdk.elb.v3.*;
import com.huaweicloud.sdk.elb.v3.model.*;


public class ListL7PoliciesSolution {

    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);

        ElbClient client = ElbClient.newBuilder()
                .withCredential(auth)
                .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                .build();
        ListL7PoliciesRequest request = new ListL7PoliciesRequest();
        try {
            ListL7PoliciesResponse response = client.listL7Policies(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());
        }
    }
}
 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkelb.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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = ElbClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ElbRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListL7PoliciesRequest()
        response = client.list_l7_policies(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := elb.NewElbClient(
        elb.ElbClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListL7PoliciesRequest{}
	response, err := client.ListL7Policies(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

Successful request.

Error Codes

See Error Codes.