Forum Discussion
D_Tech_19468
Nimbostratus
Jul 01, 2013changing SNAT pool every week by iRule
Hi All,
Would like to check is there any way to write an iRule about this.
- Require to change snatpool every week - Wednesday
- After Wednesday, the server will stick to the ne...
D_Tech_19468
Nimbostratus
Jul 03, 2013Posted By Kevin Stewart on 07/03/2013 05:29 AM
I didn't ~exactly write it to your specifications. ;) The above iRule is based on weeks of the year (1-52). The "%W" means the week of the year starting on Monday, so every Monday the value would cycle (next week). We'll take the modulus 4 of that number to get a value between 0 and 3. Example:
Week = Value
1 = 1
2 = 2
3 = 3
4 = 0
5 = 1
6 = 2
...
50 = 2
51 = 3
52 = 0
A few additional points:
1. This runs on every client request (CLIENT_ACCEPTED or HTTP_REQUEST). Also consider that at midnight on Sunday, should someone be in an active session, the snat/snatpool would change. I'm not 100% certain what the affect of that would be mid-session.
2. This is a VIP-global setting, so when you say "server A using using snatpool A", understand that the snat/snatpool is applied to all servers in the pool.
3. It's still possible to get it to rotate on a Wednesday, but would require a little extra work.
4. Because this calculation is triggered on every client request, you may not want to log all of that.
Hi Kevin,
Thanks for your reply.
I roughly have some idea about this.
I had wrote a iRule myself but i am not sure is workable or not? Perhaps you can help me to review?
It means, snatpool will take effect on 1 week - Monday, with NAT_A_pool, but i am not sure tuesday, wednesday... until next week - Monday will stick to NAT_A_pool
if {[IP::client_addr [IP::client_addr] equals 192.168.1.1] {
set FixDate "Monday"
set TodayWeekDay [split [clock format [clock seconds] -format {%A}]
set CurDay [split [clock format [clock seconds] -format {%e}]
set CurTime [clock seconds]
set FixTime [clock scan {12:00}]
set x [CurDay - 1]
if {(TodayWeekDay equals "$FixDate") && (CurTime equals FixTime)} {
if {(x equals 0 >= 6) {
snatpool NAT_A_pool
pool Default_A_GW
elseif {(x equals 7 >= 13) {
snatpool NAT_B_pool
pool Default_B_GW
elseif {(x equals 14 >= 20) {
snatpool NAT_A_pool
pool Default_A_GW
else
snatpool NAT_B_pool
pool Default_B_GW
else {
if {(x equals 0 >= 6) {
snatpool NAT_A_pool
pool Default_A_GW
elseif {(x equals 7 >= 13) {
snatpool NAT_B_pool
pool Default_B_GW
elseif {(x equals 14 >= 20) {
snatpool NAT_A_pool
pool Default_A_GW
else
snatpool NAT_B_pool
pool Default_B_GW
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects