查询转发策略详情
功能介绍
查询七层转发策略详情。
调用方法
请参见如何调用API。
URI
GET /v3/{project_id}/elb/l7policies/{l7policy_id}
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。 |
l7policy_id |
是 |
String |
转发策略ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
IAM鉴权Token。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
请求ID。 注:自动生成 。 |
l7policy |
L7Policy object |
l7policy对象。 |
参数 |
参数类型 |
描述 |
---|---|---|
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_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 |
参数 |
参数类型 |
描述 |
---|---|---|
rewrite_url_enable |
Boolean |
是否开启url重定向 |
rewrite_url_config |
RewriteUrlConfig object |
转发到的后端主机组的URL配置。rewrite_url_enable为true时,改字段有效。 |
请求示例
查询指定转发策略详情
GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/l7policies/cf4360fd-8631-41ff-a6f5-b72c35da74be
响应示例
状态码: 200
操作正常返回。
{ "l7policy" : { "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, "fixed_response_config" : null, "redirect_listener_id" : null, "action" : "REDIRECT_TO_POOL", "position" : 100, "priority" : 1, "provisioning_status" : "ACTIVE", "id" : "01832d99-bbd8-4340-9d0c-6ff8f7a37307", "name" : "l7policy-67" }, "request_id" : "6be83ec4-623e-4840-a417-2fcdf8ad5dfa" }
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 |
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 ShowL7PolicySolution {
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();
ShowL7PolicyRequest request = new ShowL7PolicyRequest();
try {
ShowL7PolicyResponse response = client.showL7Policy(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 |
# coding: utf-8
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.getenv("CLOUD_SDK_AK")
sk = os.getenv("CLOUD_SDK_SK")
credentials = BasicCredentials(ak, sk) \
client = ElbClient.new_builder() \
.with_credentials(credentials) \
.with_region(ElbRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ShowL7PolicyRequest()
response = client.show_l7_policy(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 |
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.ShowL7PolicyRequest{}
response, err := client.ShowL7Policy(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
操作正常返回。 |
错误码
请参见错误码。