IRule To Source Nat based on Load Balanced Pool

i want to source nat based on the Pool choosen for load balancing

ie :

1-if choosen pool for load balancing is PoolX , source nat using snat-pool-X

2- if if choosen pool for load balancing is PoolY , source nat using snat-object-Y ( thsi SNAt object contains mapping between Origin address & translation address

Can some one help me to get this IRule ?

Hi sshssh,

How are you selecting the pools? In general, you could select a SNAT pool based on the selected pool using a switch statement or datagroup to map pool names to snat pool names:

when LB_SELECTED {

 Check the selected pool name
switch [LB::server pool] {
pool1 {
 LB pool was pool1, so select the corresponding snat pool
snatpool pool1_snatpool
}
pool2 {
snatpool pool2_snatpool
}
default_pool {
 LB pool was not pool1 or pool2, so select a default snat pool
snatpool default_snatpool
}
}
}

Aaron

Thanks alot

and if i want ( when LB selected , if pool=pool1 & if src-ip=X.X.X.X ) the snat using snat pool= Y

ie : i want to add another condition for src ip

e.g.

when LB_SELECTED {
    Check the selected pool name
   switch [LB::server pool] {
      pool1 {
          LB pool was pool1, so select the corresponding snat pool
         if {[IP::addr [IP::client_addr] equals X.X.X.X]} {
            snatpool Y
         } else {
            snatpool pool1_snatpool
         }
      }
      pool2 {
         snatpool pool2_snatpool
      }
      default_pool {
          LB pool was not pool1 or pool2, so select a default snat pool
         snatpool default_snatpool
      }
   }
}

Thanks alot , last question , what is the difference between “if” & “switch”

what is the difference between “if” & "switchJoe has written good article about them. hope it is helpful.

Comparing iRule Control Statements by Joe

http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086424/Comparing-iRule-Control-Statements.aspx

Thanks , it is perfect