查询转发策略列表
功能介绍
查询七层转发策略列表。
接口约束
分页查询使用的参数为marker、limit、page_reverse。
marker和page_reverse只有和limit一起使用时才会生效,单独使用无效。
调用方法
请参见如何调用API。
URI
GET /v3/{project_id}/elb/l7policies
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
marker |
否 |
String |
上一页最后一条记录的ID。 使用说明:
|
limit |
否 |
Integer |
参数解释:每页返回的个数。 取值范围:0-2000 默认取值:2000 最小值:0 最大值:2000 缺省值:2000 |
page_reverse |
否 |
Boolean |
是否反向查询。 取值:
使用说明:
|
enterprise_project_id |
否 |
Array |
企业项目ID。不传时查询default企业项目"0"下的资源,鉴权按照default企业项目鉴权; 如果传值,则传已存在的企业项目ID或all_granted_eps(表示查询所有企业项目)进行查询。 支持多值查询,查询条件格式: enterprise_project_id=xxx&enterprise_project_id=xxx。 |
id |
否 |
Array |
转发策略ID。 支持多值查询,查询条件格式:id=xxx&id=xxx。 |
name |
否 |
Array |
转发策略名称。 支持多值查询,查询条件格式:name=xxx&name=xxx。 |
description |
否 |
Array |
转发策略额描述信息。 支持多值查询,查询条件格式:description=xxx&description=xxx。 |
admin_state_up |
否 |
Boolean |
转发策略的管理状态,默认为true。 不支持该字段,请勿使用。 |
listener_id |
否 |
Array |
转发策略所属的监听器ID。 支持多值查询,查询条件格式:listener_id=xxx&listener_id=xxx。 |
position |
否 |
Array |
转发策略的优先级。 支持多值查询,查询条件格式:position=xxx&position=xxx。 不支持该字段,请勿使用。 |
action |
否 |
Array |
转发策略的转发动作。 取值:
支持多值查询,查询条件格式:action=xxx&action=xxx。 |
redirect_url |
否 |
Array |
转发到的url。必须满足格式: protocol://host:port/path?query。 支持多值查询,查询条件格式:redirect_url=xxx&redirect_url=xxx。 不支持该字段,请勿使用。 |
redirect_pool_id |
否 |
Array |
转发到pool的ID。 支持多值查询,查询条件格式:redirect_pool_id=xxx&redirect_pool_id=xxx。 |
redirect_listener_id |
否 |
Array |
转发到的listener的ID。 支持多值查询,查询条件格式:redirect_listener_id=xxx&redirect_listener_id=xxx。 |
provisioning_status |
否 |
Array |
转发策略的配置状态。 取值范围:
支持多值查询,查询条件格式:provisioning_status=xxx&provisioning_status=xxx。 |
display_all_rules |
否 |
Boolean |
是否显示转发策略下的rule详细信息。 取值:
|
priority |
否 |
Array |
转发策略的优先级。数值越小,优先级越高。 支持多值查询,查询条件格式:priority=xxx&priority=xxx。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
IAM鉴权Token |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
请求ID。 注:自动生成 。 |
page_info |
PageInfo object |
分页信息。 |
l7policies |
Array of L7Policy objects |
转发策略对象列表。 |
参数 |
参数类型 |
描述 |
---|---|---|
previous_marker |
String |
参数解释:分页查询结果中第一条记录的ID。通常用于配合page_reverse=true查询上一页。 |
next_marker |
String |
参数解释:分页查询结果中最后一条记录的ID。通常用于查询下一页。 |
current_count |
Integer |
参数解释:当前的记录数。 |
参数 |
参数类型 |
描述 |
---|---|---|
action |
String |
转发策略的转发动作。 取值:
使用说明:
|
admin_state_up |
Boolean |
转发策略的管理状态,默认为true。 不支持该字段,请勿使用。 |
description |
String |
转发策略描述信息。 |
id |
String |
转发策略ID。 |
listener_id |
String |
转发策略所属的监听器ID。 |
name |
String |
转发策略名称 最小长度:1 最大长度:255 |
position |
Integer |
转发策略的优先级,不支持更新。 不支持该字段,请勿使用。 最小值:1 最大值:100 |
priority |
Integer |
转发策略的优先级。数字越小表示优先级越高,同一监听器下不允许重复。 当监听器的高级转发策略功能(enhance_l7policy_enable)开启后才会生效,未开启传入该字段会报错。 当action为REDIRECT_TO_LISTENER时,仅支持指定为0,优先级最高。 当关联的listener没有开启enhance_l7policy_enable,按原有policy的排序逻辑,自动排序。 各域名之间优先级独立,相同域名下,按path的compare_type排序,精确>前缀>正则, 匹配类型相同时,path的长度越长优先级越高。若policy下只有域名rule,没有路径rule,默认path为前缀匹配/。 当关联的listener开启了enhance_l7policy_enable,且不传该字段,则新创建的转发策略的优先级的值为: 同一监听器下已有转发策略的优先级的最大值+1。 因此,若当前已有转发策略的优先级的最大值是10000,新创建会因超出取值范围10000而失败。 此时可通过传入指定priority,或调整原有policy的优先级来避免错误。若监听器下没有转发策略,则新建的转发策略的优先级为1。 共享型负载均衡器下的转发策略不支持该字段。 |
project_id |
String |
转发策略所在的项目ID。 |
provisioning_status |
String |
转发策略的配置状态。 取值范围:
|
redirect_pool_id |
String |
转发到pool的ID。当action为REDIRECT_TO_POOL时生效。 |
redirect_listener_id |
String |
转发到的listener的ID,当action为REDIRECT_TO_LISTENER时必选。 使用说明:
|
redirect_url |
String |
转发到的url。必须满足格式: protocol://host:port/path?query。 不支持该字段,请勿使用。 |
rules |
Array of RuleRef objects |
转发策略关联的转发规则列表 |
redirect_url_config |
RedirectUrlConfig object |
转发到的url配置。 当监听器的高级转发策略功能(enhance_l7policy_enable)开启后才会生效,未开启传入该字段会报错。 当action为REDIRECT_TO_URL时生效,且为必选字段,其他action不可指定,否则报错。 格式:protocol://host:port/path?query protocol、host、port、path不允许同时不传或同时传${xxx} (${xxx}表示原值,如${host}表示被转发的请求URL的host部分)。 protocol和port传入的值不能与l7policy关联的监听器一致且host、path同时不传或同时传${xxx}。 共享型负载均衡器下的转发策略不支持该字段,传入会报错。 |
redirect_pools_config |
Array of RedirectPoolsConfig objects |
转发到多个主机组列表。一个policy最多配置5个pool。 |
redirect_pools_sticky_session_config |
配置转发策略关联的服务器组之间会话保持。负载均衡器会根据客户端第一个请求生成一个cookie,后续所有包含这个cookie值的请求都会由同一个pool处理。 共享型负载均衡器下的转发策略不支持该字段,传入会报错。 |
|
redirect_pools_extend_config |
RedirectPoolsExtendConfig object |
转发到的后端主机组的配置。当action为REDIRECT_TO_POOL时生效。 |
fixed_response_config |
FixtedResponseConfig object |
固定返回页面的配置。 当监听器的高级转发策略功能(enhance_l7policy_enable)开启后才会生效,未开启传入该字段会报错。 当action为FIXED_RESPONSE时生效,且为必选字段,其他action不可指定,否则报错。 共享型负载均衡器下的转发策略不支持该字段,传入会报错。 |
created_at |
String |
创建时间。格式:yyyy-MM-dd'T'HH:mm:ss'Z',UTC时区。 注意:独享型实例的历史数据以及共享型实例下的资源,不返回该字段。 |
updated_at |
String |
更新时间。格式:yyyy-MM-dd'T'HH:mm:ss'Z',UTC时区。 注意:独享型实例的历史数据以及共享型实例下的资源,不返回该字段。 |
参数 |
参数类型 |
描述 |
---|---|---|
protocol |
String |
重定向的协议。默认值${protocol}表示继承原值(即与被转发请求保持一致)。 取值:
最小长度:1 最大长度:36 |
host |
String |
重定向的主机名。字符串只能包含英文字母、数字、“-”、“.”。 且必须以字母、数字开头。默认值${host}表示继承原值(即与被转发请求保持一致)。 缺省值:${host} 最小长度:1 最大长度:128 |
port |
String |
重定向到的端口。默认值${port}表示继承原值(即与被转发请求保持一致)。 缺省值:${port} 最小长度:1 最大长度:16 |
path |
String |
重定向的路径。默认值${path}表示继承原值(即与被转发请求保持一致)。 支持英文字母、数字、_~';@^-%#&$.*+?,=!:|\/()[]{},且必须以"/"开头。 缺省值:${path} 最小长度:1 最大长度:128 |
query |
String |
重定向的查询字符串。默认${query}表示继承原值(即与被转发请求保持一致)。举例如下: 若该字段被设置为:${query}&name=my_name,则在转发符合条件的URL (如https://www.example.com:8080/elb?type=loadbalancer, 此时${query}表示type=loadbalancer)时,将会重定向到 https://www.example.com:8080/elb?type=loadbalancer&name=my_name。 只能包含英文字母、数字和特殊字符:!$&'()*+,-./:;=?@^_`。字母区分大小写。 缺省值:${query} 最小长度:0 最大长度:128 |
status_code |
String |
重定向后的返回码。 取值范围:
最小长度:1 最大长度:16 |
insert_headers_config |
InsertHeadersConfig object |
要添加的请求头参数列表。 |
remove_headers_config |
RemoveHeadersConfig object |
要移除的请求头参数列表。 |
参数 |
参数类型 |
描述 |
---|---|---|
pool_id |
String |
所在后端服务器组ID。 |
weight |
Integer |
转发策略主机组的权重,范围为[0,100], 请求将根据该权重进行负载分发到不同的主机组。 权重值越大,分发的请求越多。权重为0的后端不再接受新的请求。 最小值:0 最大值:100 |
参数 |
参数类型 |
描述 |
---|---|---|
enable |
Boolean |
转发策略主机组会话保持开启的开关。 默认值为false,表示关闭主机组会话保持。 缺省值:false |
timeout |
Integer |
会话保持的时间。 适用范围:范围为[1,1440](分钟),默认值1440。 |
参数 |
参数类型 |
描述 |
---|---|---|
rewrite_url_enable |
Boolean |
是否开启url重定向。 |
rewrite_url_config |
RewriteUrlConfig object |
URL重定向配置。当action为REDIRECT_TO_POOL的时候生效。 |
insert_headers_config |
InsertHeadersConfig object |
要添加的请求头参数列表。 |
remove_headers_config |
RemoveHeadersConfig object |
要移除的请求头参数列表。 |
traffic_limit_config |
TrafficLimitConfig object |
转发策略限速的配置。 |
参数 |
参数类型 |
描述 |
---|---|---|
host |
String |
重定向的域名。取值只能包含英文字母、数字、“-”、“.”,必须以字母、数字开头。 默认值${host},表示继承原值(即与被重写请求host保持一致)。 |
path |
String |
重定向的请求路径。 取值只能包含英文字母、数字、_~';@^-%#&$.+?,=!:|/(),且必须以"/"开头。其中$1-$9会匹配请求url通配符星号(),当正则匹配分组小于指定数字,则$指定数字结果为空。$后面跟字母,匹配结果均为空,直到下一个特殊字符出现,例如$abc#123,则匹配结果为#123;$后面跟特殊字符则直接输出特殊字符,例如$#匹配结果为$#。 默认值${path}表示继承原值(即与被重写请求保持一致)。 |
query |
String |
重定向的查询字符串。取值只能包含英文字母、数字和特殊字符:!$&'()+,-./:;=?@^_`。字母区分大小写。其中$1-$9会匹配请求url通配符星号(),当正则匹配分组小于指定数字,则$指定数字结果为空。$后面跟字母,匹配结果均为空,直到下一个特殊字符出现,例如$abc#123,则匹配结果为#123;$后面跟特殊字符则直接输出特殊字符,例如$#匹配结果为$#。 默认${query},表示继承原值(即与被重写请求保持一致)。 |
参数 |
参数类型 |
描述 |
---|---|---|
status_code |
String |
返回码。支持200~299,400~499,500~599。 最小长度:1 最大长度:16 |
content_type |
String |
返回body的格式。 取值范围:
最小长度:0 最大长度:32 |
message_body |
String |
返回消息内容。 最小长度:0 最大长度:1024 |
insert_headers_config |
InsertHeadersConfig object |
要添加的请求头参数列表。 |
remove_headers_config |
RemoveHeadersConfig object |
要移除的请求头参数列表。 |
traffic_limit_config |
TrafficLimitConfig object |
转发策略限速的配置。 |
参数 |
参数类型 |
描述 |
---|---|---|
key |
String |
支持1-40个字符(不区分大小写)。 支持字母a-z,数字,短划线-和下划线_。 key不能是以下字符: connection、upgrade、content-length、transfer-encoding、keep-alive、te、host、cookie、remoteip、authority、x-forwarded-host、x-forwarded-for、x-forwarded-for-port、x-forwarded-tls-certificate-id、x-forwarded-tls-protocol、x-forwarded-tls-cipher、x-forwarded-elb-ip、x-forwarded-port、x-forwarded-elb-id、x-forwarded-elb-vip、x-real-ip、x-forwarded-proto、x-nuwa-trace-ne-in、x-nuwa-trace-ne-out。 |
value_type |
String |
可选值:USER_DEFINED,REFERENCE_HEADER,SYSTEM_DEFINED。 |
value |
String |
header值。当value_type为SYSTEM_DEFINED时,value只可从CLIENT-PORT,CLIENT-IP, ELB-PROTOCOL, ELB-ID, ELB-PORT, ELB-EIP, ELB-VIP中取值。 取值范围:1-128个字符, 支持ascii码值32<=ch<=127范围内可打印字符,*和英文问号?。不能以空格开头或结尾。 |
参数 |
参数类型 |
描述 |
---|---|---|
key |
String |
被移除的请求头的参数名。取值范围: 1-40个字符(不区分大小写)。 支持字母a-z,数字,短划线-和下划线_。 不能移除以下请求头参数: connection、upgrade、content-length、transfer-encoding、keep-alive、te、host、cookie、remoteip、authority、x-forwarded-host、x-forwarded-for、x-forwarded-for-port、x-forwarded-tls-certificate-id、x-forwarded-tls-protocol、x-forwarded-tls-cipher、x-forwarded-elb-ip、x-forwarded-port、x-forwarded-elb-id、x-forwarded-elb-vip、x-real-ip、x-forwarded-proto、x-nuwa-trace-ne-in、x-nuwa-trace-ne-out |
参数 |
参数类型 |
描述 |
---|---|---|
qps |
Integer |
转发策略整体限速。取值: 0-100000s。0表示不限速 最小值:0 最大值:100000 |
per_source_ip_qps |
Integer |
对转发策略单源进行限速。 quic监听器下转发策略不支持配置单源限速,指定该字段时,赋值可以为0或者为null 取值: 0-100000s。0表示不限速,如果qps不为0,per_ip_qps需要小于qps。 最小值:0 最大值:100000 |
burst |
Integer |
对转发策略单源进行限速。取值: 0-100000s。当qps超限的时候,不返回503,支持允许局部突增burst大小的请求。 最小值:0 最大值:100000 |
请求示例
查询转发策略列表
GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/l7policies?display_all_rules=true
响应示例
状态码: 200
操作正常返回。
{ "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代码示例
SDK代码示例如下。
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 |
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.*; import java.util.List; import java.util.ArrayList; 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); ListL7PoliciesRequest request = new ListL7PoliciesRequest(); request.withMarker("<marker>"); request.withLimit(<limit>); request.withPageReverse(<page_reverse>); request.withEnterpriseProjectId(); request.withId(); request.withName(); request.withDescription(); request.withAdminStateUp(<admin_state_up>); request.withListenerId(); request.withPosition(); request.withAction(); request.withRedirectUrl(); request.withRedirectPoolId(); request.withRedirectListenerId(); request.withProvisioningStatus(); request.withDisplayAllRules(<display_all_rules>); request.withPriority(); 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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"] credentials = BasicCredentials(ak, sk) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListL7PoliciesRequest() request.marker = "<marker>" request.limit = <limit> request.page_reverse = <PageReverse> request.enterprise_project_id = request.id = request.name = request.description = request.admin_state_up = <AdminStateUp> request.listener_id = request.position = request.action = request.redirect_url = request.redirect_pool_id = request.redirect_listener_id = request.provisioning_status = request.display_all_rules = <DisplayAllRules> request.priority = 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 38 39 40 41 42 43 44 45 |
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListL7PoliciesRequest{} markerRequest:= "<marker>" request.Marker = &markerRequest limitRequest:= int32(<limit>) request.Limit = &limitRequest pageReverseRequest:= <page_reverse> request.PageReverse = &pageReverseRequest adminStateUpRequest:= <admin_state_up> request.AdminStateUp = &adminStateUpRequest displayAllRulesRequest:= <display_all_rules> request.DisplayAllRules = &displayAllRulesRequest response, err := client.ListL7Policies(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
操作正常返回。 |
错误码
请参见错误码。