This topic details the specifications for DataScript pool functions available on NSX Advanced Load Balancer.

Function

Description

avi.pool.get_server_status( pool, server, port )

Returns the up/down status of the server

avi.pool.get_servers( pool )

Returns up and total server count

avi.pool.select( pool [, server [, port]] )

Pick a specific pool

avi.pool.server_ip()

Returns the IP address of the selected server

avi.pool.get_server_info()

Returns the IP address and port of the server

avi.poolgroup.select( pool )

Pick a specific pool group

avi.pool.chash( string )

Sets the string value that the consistent hash load-balancing algorithm hashes on to choose a server within the selected pool

Note:

Starting with NSX Advanced 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

  • HTTP_REQ

  • HTTP_RESP

Parameter

All three parameter fields are required.

  • pool can be a specific pool name or an expression that evaluates to a valid pool name.

  • The server flag is the IPv6 address of the server, in quotes.

  • The port flag 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.

Returns

Return value of 0 indicates the server is down. Return value of 1 indicates the server is up.

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

avi.pool.get_servers( pool )

Description

Check the number of servers with 'up' status and total number of servers configured within a specified pool.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

pool can be a pool name or an expression that evaluates to a valid pool name.

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

avi.pool.select( pool [, server [, port]] )

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

HTTP_REQ

Parameter

pool can be a specific pool name or an expression that evaluates to a valid pool name.

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.

  • Explicit reference: A configuration error will be generated while saving the DataScript.

  • Dynamically generated reference: A runtime error is generated, which results in a 500 error return to the client.

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.

www.avi.com/support/index.htm would go to the support pool www.avi.com/sales/apac/index.htmwould go to the sales pool

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)
Note:

The pool select feature is not supported for IPv6.

avi.pool.server_ip

Function

avi.pool.server_ip()

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

HTTP_RESP

Parameter

None

Returns

Returns a string of the server's IP address

Example

avi.http.add_header("Server", avi.pool.server_ip())
Note:

This API is not supported in the events SSL_PRECONNECT, SSL_CLIENTHELLO, and SSL_HANDSHAKE_DONE.

avi.pool.get_server_info

Function

avi.pool.server_info()

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

  • HTTP_RESP

  • LB_DONE

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 Lua expression. If the pool name, server, or server port does not exist or cannot be referenced by the virtual service, an error is generated.

  • Explicit Reference: A configuration error will be generated while saving the DataScript.

  • Dynamically Generated Reference: A runtime error is generated, which results in a 500 error return to the client.

Related

avi.pool.get_server_status(), determines the status of the server listening at a specified port.

Example

ip, port = avi.pool.get_server_info()

avi.poolgroup.select

Function

avi.poolgroup.select( poolgroup )

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

HTTP_REQ

Parameter

poolgroup can be a specific pool name or an expression that evaluates to a valid pool name.

Returns

The pool group name may be called explicitly or dynamically determined based on a Lua expression. If the pool group name does not exist or cannot be referenced by the virtual service, an error is generated.

  • Explicit Reference: A configuration error will be generated while saving the DataScript.

  • Dynamically Generated Reference: A runtime error is generated, which results in a 500 error return to the client.

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

avi.pool.chash ( string )

Description

Sets the string value that the consistent hash load-balancing algorithm hashes on to choose a server within the selected pool

Events

HTTP_REQ

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 custom-hash in a request, then use its value as input to the Consistent Hash with Custom Data load-balancing algorithm to select a server out of the pool named pool-of-servers. The pool should be configured to have its load-balancing algorithm set to Consistent Hash on Custom Data.

hash = avi.http.get_header("custom-hash")
if hash then
   avi.pool.select("pool-of-servers")
   avi.pool.chash(hash)
end