This is typically easily done with an “ip” type datagroup. You can probably write a small script to create an empty datagroup and then add all the records in it. The key would be the CIDR network and the value would be the pool name.
The iRule snippet you need is
if { [class match [client_addr] equals ] } {
set poolname [class match -value [client_addr] equals ]
pool $poolname
} else {
pool default-pool
}
Here is a sample data-group
ltm data-group internal dg_1 {
records {
10.0.0.0/8 {
data pool1
}
}
type ip
}
This is may be more scholastic/less practical for your use, but you could split into roughly 5 equal parts with a one-liner where pools are labled pool0-4.
pool "pool[expr [getfield [IP::client_addr] "." 2] % 5]"