Forum Discussion

Maxim_Taskov_90's avatar
Maxim_Taskov_90
Icon for Nimbostratus rankNimbostratus
Jun 26, 2008

Match URI Path and Choose Pool Plus Pool Availability Check

Hi ...

 

 

I am trying to create a rule with the following logic and assign it on a single virtual server:

 

 

1. If URI path matches string class MyURI (listing about fifteen URI paths) AND the active members of Pool2 are more than zero, choose Pool2.

 

 

2. If URI path does not match string class MyURI OR Pool2 has zero active members, choose Pool1.

 

 

I came up with the following ... please tell me if the logic will be processed correctly, that will satisfy the above two requirements and if this is the most efficient way to accomplish my objective:

 

 

when HTTP_REQUEST {

 

if { [matchclass [HTTP::uri] starts_with $::MyURI] } {

 

if { [active_members Pool2] > 0 } {

 

pool Pool2

 

} else {

 

pool Pool1

 

}

 

}

 

}

 

 

Thanks!

6 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    That logic looks correct to me. You could compress the two checks into one if statement combined with an and, but it's logically the same thing, just a tiny bit less code.

     

     

    Colin
  • Thanks Colin. I knew about the option of single AND rather than multiple IF statements but I never had a good luck with the AND option. The last iRule I wrote did not work at all with the AND statement. It started working as soon as I switched to a multiple IF statement.

     

     

    Anyway, thanks for the sanity check.

     

     

    Regards, Maxim
  • Do you have a default pool on the VIP? Using the rule you posted above, you're not explicitly specifying a pool for requests which don't match the first condition.

     
     when HTTP_REQUEST { 
         if { [matchclass [HTTP::uri] starts_with $::MyURI] } { 
             if { [active_members Pool2] > 0 } { 
                 pool Pool2 
             } else { 
                 pool Pool1 
           } 
        } else { 
           pool Pool1 
        } 
     } 
     

    Or combined:

     
     when HTTP_REQUEST { 
        if { [matchclass [HTTP::uri] starts_with $::MyURI] and [active_members Pool2] > 0} { 
           pool Pool2 
        } else { 
           pool Pool1 
        } 
     } 
     

    Aaron
  • Thanks for the reply Aaron. Yes, I forgot to mention this but I do have a default pool configured at the VIP for requests that do not fit the iRule conditions.

     

     

    Is that a good configuration or should I try to handle all possible scenarios in the iRule?

     

     

    Maxim
  • If I assign a pool in any scenario in an iRule, I normally assign it for all. In general, it makes it easier to follow the logic of the iRule.

     

     

    Aaron