Hi,
In addition to my another post, I have to urgently write an iRule to facilitate strict Round Robin event if the Virtual is CMPenabled.
I wrote code as follows but still have two difficulities:
(1) Initializing data in table
It seems “table” command cannot be used in RULE_INIT event.
(2) I’m not clear how to specify variable type: numeric or string (Ooops..)
and having difficulty in calculating variables.
(3) Want to set general variables in RULE_INIT
--> Probably I can just use “static::xxx”
Excuse me for newbee question.
--------------------------------
when RULE_INIT {
}
when CLIENT_ACCEPTED {
set poolname “test-pool”
set num_pool_member 4
set pool_port 80
set ip_pm0 “10.100.11.11”
set ip_pm1 “10.100.11.12”
set ip_pm2 “10.100.12.11”
set ip_pm3 “10.100.12.12”
get next poolmember’s index
set last_mod [table lookup -subtable “rr_table” “last_mod”]
---- Here, not sure how to set correct data tye ------
set new_mod [ expr { expr { $last_mod + 1 } % $num_pool_member} ]
table set -subtable “rr_table” “last_mod” $new_mod
-----
Here I want to check the validily of the variable as “table” cannot be initialized in RULE_INIT
I also want to check if it’s not empty but non-numeric value is set.
if { $last_mod == “” } {
table set -subtable “rr_table” “last_mod” 0 indefinite indefinite
set new_mod 1
}
switch pool member based on the index
switch $new_mod {
0 {
if { [LB::status pool $poolname member $ip_pm0 $pool_port up] } {
pool $::poolname member $ip_pm0 $pool_port
log local0.info “LBed to pm 0”
} else {
continue
}
}
1 {
if { [LB::status pool $poolname member $ip_pm1 $pool_port up] } {
pool $poolname member $ip_pm1 $pool_port
log local0.info “LBed to pm 1”
} else {
continue
}
}
2 {
if { [LB::status pool $poolname member $ip_pm2 $pool_port up] } {
pool $::poolname member $ip_pm2 $pool_port
log local0.info “LBed to pm 2”
} else {
continue
}
}
3 {
if { [LB::status pool $::poolname member $ip_pm3 $pool_port up] } {
pool $::poolname member $ip_pm3 $pool_port
log local0.info “LBed to pm 3”
} else {
continue
}
}
default {
log “no pool to assign for Virtual Server XX”
}
}
}
--------------------------------