Forum Discussion

Chris_Phillips's avatar
Chris_Phillips
Icon for Nimbostratus rankNimbostratus
Sep 20, 2006

check if pool exists

Hi,

 

 

any nice way to find if a pool exists? i'm dynamically assigning connections to pools based on the HTTP::host header and want to catch the connection if the pool name doesn't exist. currently the iRule chokes at runtime if i do "pool pool_that_does_not_exist".

 

 

Thanks

 

 

Chris

7 Replies

  • You have the answer in your request....use TCL's catch command.
  • Here's an example from deb that you can modify to fit your needs:

    
    when HTTP_REQUEST {
      set myNode [findstr [HTTP::uri] "node=" 5 "&"]
      if {[catch {node $myNode}]}{
        pool myPool
      } else {
        node $myNode
      }
    }
  • super. i keep forgetting about making use of real tcl. not that i knew about catch in tcl beforehand anyway.

     if [ catch { pool "pool_$http_host" } ] {
        log local0. "ERROR on assiging pool of pool_$http_host"
        HTTP::respond 200 content "error message here" 
    }
    thanks muchly so.
  • Actually... in your example there you're actually using the node command twice, i assume this isn't actually necessary? i'm only assigning the pool once in my example and it seems to be working.
  • In the if statement, the node not existing will result in a load balancing decision being made, otherwise (else), it will send the connection to the node. So whereas the node command is used twice, it will only be called once, by the if OR by the else.
  • surely not, if the catch(node) command succeeds then the catch() itself is false. therefore the else { node } is excuted, so you will have run the node command twice.
  • DOH! You're right, my bad.

     

     

    In the example it is necessary to use it twice, once to validate the node exists, and once to actually send the traffic there. If it doesn't exist, load balance the traffic to pool myPool

     

     

    I think I remember reading on a thread that the node doesn't technically have to exist in the configuration to assign it, so this might be a customer requirement. Also, since the information is dynamic, it might not be formatted correctly and will thus throw an error.