Forum Discussion

Brian_Deitch_11's avatar
Brian_Deitch_11
Historic F5 Account
Sep 22, 2011

Dynamic query of all pools

I'm working on a dynamic iRule that will load balance based on the URI. I have that part working fine but the pool selection deviates from our standard. I need to figure out how I can query all the pools that are on the LTM so I can select the right pool.

This is the iRule in question:


when HTTP_REQUEST {
      Grab the 1st folder after the hostname
     set lbfolder [string tolower [URI::path [HTTP::uri] 1 1]]
      Strip out the "/"
     set lbfolder pool_[string trim $lbfolder "/"]
      log local0. "testing01 $lbfolder"
if { [catch {pool $lbfolder} exc] } {
      If a client sends a uri that does not match a pool, send to default pool or throw message
     pool default
     HTTP::respond 200 content "No matching pool for that URI"
    }
}

As you can see, the current irule construct the pool selection by pool_URI but I need to get pool_URI_port. I'm hoping I can create a dynamic class of all the pool members, match lbfolder to the class and select the correct pool from there.

Thanks in advance.

4 Replies

  • Hi Brian,

     

     

    I am confused on exactly what you are looking for.

     

     

     

    I need to figure out how I can query all the pools that are on the LTM so I can select the right pool.

     

     

     

    What criteria are you going to use to determine which pool is the right pool? It seems to me like you would have to narrow down the list of pools (list the pools in a Data Group, etc.) that you want to compare against and determine the match criteria before you could make a selection decision.

     

     

    Could you clarify?
  • Hi Brian,

     

    I think a good approach is to create the dynamic class listing all the pool members via cron job and a shell script. Luckily one has already been created as a solution for another problem.

     

     

    Go to the following link

     

    http://devcentral.f5.com/wiki/iRules.Pool__Member__Status__Page_on_a__Virtual__Server_v10.ashx

     

     

    While this link is for an iRule regarding pool status, it still contains a cron script to which you can extract pool information into a class file which can be used for any other application.

     

     

    I hope this helps

     

    Bhattman
  • You could also just assume the pool exists, but use catch (http://www.tcl.tk/man/tcl8.4/TclCmd/catch.htm) to handle a non-existent pool error. This would save the complexity of a separate cron job and datagroup of pool names.

    
     Assign the dynamic pool name, catching any errors for a non-existent pool
    if {[catch {pool $my_dynamic_pool} result] == 1}{
       log local0. "Error assigning pool $my_dynamic_pool: $result"
       pool some_default_pool
    } else {
       log local0. "Successfully assigned pool $my_dynamic_pool: $result"
    }
    

    Aaron
  • Brian_Deitch_11's avatar
    Brian_Deitch_11
    Historic F5 Account
    Michael,

    I want to take the lbforlder variable and determine if it contains any of the characters that would be found in any of the existing pools. In a perfect world, my current iRule would work but our naming structure is pool_appname_port. Since I can't determine what port the pool is on, I would hope to scan the list of current pools and select from there.

    Bhattman,

    I've seen that article and tested it. That works but I want to see if I can do it in an iRule.

    Hoolio,

    That logic makes the iRule more robust but still doesn't fix my problem of constructing my pool name.

    All,

    Currently I build the pool name and it looks like this pool_login. But in reality it should look like pool_login_8080. But keep in mind, the ports are random so adding

    set lbfolder pool_[string trim $lbfolder "/"]_8080 

    wouldn't work because the port could different, e.g., 7777, 80, and so on.