Forum Discussion

Andy_Herrman_22's avatar
Andy_Herrman_22
Icon for Nimbostratus rankNimbostratus
Jul 09, 2007

Dynamic Pool Names

I'd like to be able to select which pool to use based on some data in the HTTP request, but I don't want to have to hard code the pools in the iRule. Is it possible to dynamically create the pool name (stored in a variable) and then select the pool using that?

 

 

The pool command seems to take the name as if it's a literal, not a variable, meaning you do:

 

 

pool my_pool1

 

instead of

 

pool "my_pool1"

 

 

Is it possible to use strings or variables as the pool name? For instance, could I do

 

something like:

 

 


when HTTP_REQUEST {
   Pool number stored in pid query param
  set poolID [findstr [HTTP:uri] "pid=" 4 "&"]
  set poolName "my_pool$poolID"
  pool $poolName  
}

 

 

or maybe

 


when HTTP_REQUEST {
   Pool number stored in pid query param
  set poolID [findstr [HTTP:uri] "pid=" 4 "&"]
  pool "my_pool$poolID"
}

 

 

(my code might not be quite right. I haven't written an iRule in about a year and my dev F5 box isn't working right now so I can't test it).

2 Replies

  • Absolutely. The only issue you lose is load time validation. If you try to use a dynamic pool name that isn't defined in the configuration, you'll get a runtime error causing the connection to abort. You'll want to enclose your pool command with a "catch" statement to ensure that the runtime error doesn't occur and if it does either assign a default pool, redirect the user somewhere, or use an HTTP::respond to return status content directly to the client.

     

     

    Here's a post on the "catch" statement:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&forumid=5&postid=10280

     

    Click here

     

     

     

    -Joe