This topic details the specifications for DataScript pool functions available on Avi Load Balancer.
Function |
Description |
---|---|
Returns the up/down status of the server |
|
Returns up and total server count |
|
Pick a specific pool |
|
Returns the IP address of the selected server |
|
Returns the IP address and port of the server |
|
Pick a specific pool group |
|
Sets the string value that the consistent hash load-balancing algorithm hashes on to choose a server within the selected pool
Note:
Starting with Avi Load Balancer version 22.1.3, Consistent Hash is supported as a load balancing algorithm for pool groups. |
avi.pool.get_server_status
Function |
avi.pool.get_server_status(pool, server, port) |
Description |
Determine the status of the server listening at a specified port. |
Events |
|
Parameter |
All three parameter fields are required.
|
Returns |
Return value of 0 indicates the server is |
Example |
If a server is down, redirect traffic elsewhere as follows: if avi.pool.get_server_status("web-pool", "10.1.1.1", "80") == 0 then avi.http.redirect("backupsite.com" .. avi.http.get_uri()) end |
avi.pool.get_servers
Function |
|
Description |
Check the number of servers with 'up' status and total number of servers configured within a specified pool. |
Events |
|
Parameter |
|
Returns |
Returns the number of up servers and the number of total servers within the pool. |
Example |
Forward the request to an explicit destination. servers_up, servers_total = avi.pool.get_servers("web-pool") if servers_up == 0 then avi.http.response(503) end |
avi.pool.select
Function |
|
Description |
Selects a pool or a specific server within a pool for the current request. The selection does not take effect if an HTTP request policy was also configured with a switching action to select a pool or a specific server in a pool. The switching action of the HTTP request policy takes precedence over the DataScript's pool selection. |
Events |
|
Parameter |
The server parameter (a string) is the IPv4 address of the server, in quotes. The optional port parameter (an integer) forwards the connection to a specific service port of the server. The port must be a number between 0 and 65536 or an expression that evaluates to a valid port number. |
Caveats |
The pool name, server name or IP, and the server port may be called explicitly, or dynamically determined based on a Lua expression. If the pool name, server, or server port do not exist or are not able to be referenced by the virtual service, an error is generated.
|
Returns |
No value returned |
Related |
avi.poolgroup.select()- Selects a pool group for the current request. |
Example 1 |
Forward the request to an explicit destination. if avi.http.get_path() == "/sales/" then avi.pool.select("sales-pool") elseif avi.http.get_path () == "/engineering/" then avi.pool.select("engineering-pool", "apache1") elseif avi.http.get_path () == "/marketing/" then avi.pool.select("marketing", "10.10.31.201") end |
Example 2 |
Forward the request to a dynamically generated destination.
avi.pool.select(avi.http.get_path_tokens(1, 1)) |
Example 3 |
Forward the request to a named server. var = "abcd" avi.pool.select("poolx", var) |
The pool select feature is not supported for IPv6.
avi.pool.server_ip
Function |
|
Description |
Returns the IPv6 address of the server for this request or response. Keep in mind that with content switching or multiplexing, a single client connection may have multiple requests, each distributed to a different server. |
Events |
|
Parameter |
None |
Returns |
Returns a string of the server's IP address |
Example |
|
This API is not supported in the events SSL_PRECONNECT
, SSL_CLIENTHELLO
, and SSL_HANDSHAKE_DONE
.
avi.pool.get_server_info
Function |
|
Description |
Returns the IPv6 address and port of the server for this request or response.
Note:
With content switching or multiplexing, a single client connection may have multiple requests, each distributed to a different server. |
Events |
|
Parameter |
None |
Returns |
The server's IP address(string) and its port number |
Caveats |
The pool name, server name or IP, and the server port may be called explicitly or dynamically determined based on a
|
Related |
|
Example |
ip, port = avi.pool.get_server_info() |
avi.poolgroup.select
Function |
|
Description |
Selects a pool group for the current request. The selection does not take effect if an HTTP request policy was also configured with a switching action to select a pool. The switching action of the HTTP request policy takes precedence over the DataScript's pool group selection. |
Events |
|
Parameter |
|
Returns |
The pool group name may be called explicitly or dynamically determined based on a
|
Caveats |
No value returned |
Related |
avi.pool.select() - Selects a pool for the current request. |
Example |
Forward the request to an explicit destination. if avi.http.get_path() == "/test/" then avi.poolgroup.select("test-poolgroupl") else avi.poolgroup.select("defaut-poolgroup") end |
avi.pool.chash
Function |
|
Description |
Sets the string value that the consistent hash load-balancing algorithm hashes on to choose a server within the selected pool |
Events |
|
Parameter |
The string value must be specified, and can be created in any manner. |
Returns |
No return value |
Example |
If there is a header by the name hash = avi.http.get_header("custom-hash") if hash then avi.pool.select("pool-of-servers") avi.pool.chash(hash) end |