Forum Discussion

schmal_111133's avatar
schmal_111133
Icon for Nimbostratus rankNimbostratus
Mar 20, 2013

Build a named table in RULE_INIT condition

Hi all,

I have a class that map from virtual server IP to the server itself IP, I want to convert it to a table in the RULE_INIT condition in order to be able to modify it if some server have been faulted.

I applied the below irule:

when RULE_INIT {
    foreach static::IP [eval class get ProxyIP] {
       table set -subtable "PRE_Map" [lindex $static::IP 0] [lindex $static::IP 1] indefinite
   } 
}

Some one have any good idea for work around or that my only way is to build the table in the client accepted event?

And another small question, is the F5 sync named tables between redundant pair?

Thanks!!

5 Replies

  • It looks like it is not possible to create table in the RULE_INIT

     

    i believe so.

     

    As fantastic as the new session table is, it does have its limitations. You can't use the table command in RULE_INIT or any other global event.v10.1 - The table Command - The Fine Print by Spark https://devcentral.f5.com/tech-tips/articles/v101-the-table-command-the-fine-print

     

    You can't access the session table in RULE_INIT or any other global event, that's true. However, don't forget that entries in the session table deliberately expire, so even if you could initialize them in RULE_INIT, they may be gone later, and your iRule has to cope with that (that's one reason there are so many variations on things like the set command).CMP compatible strict Round Robin (spark's reply)

     

    https://devcentral.f5.com/community/group/aft/1174561/asg/50

     

    Some one have any good idea for work around or that my only way is to build the table in the client accepted event?can static array be used instead?

     

    SNAT pool persistence by Aaron https://devcentral.f5.com/wiki/irules.snat_pool_persistence.ashx

     

  • Hi Nitass, thanks for the reply.

     

    I am familiar with the static array and in the beginning I thought using it but I need that the information to be synced between both F5 (active and standby), as far as I know table should be synced while static array not, please correct me if I wrong.

     

     

    Thanks again :)
  • One other thing worth mentioning. The static namespace used in RULE_INIT is intended to be, as the name implies, static and unchanging. The static namespace was created to provide a CMP-compatible global variables, meaning that variables created in this namespace are visible across TMM instances. If you write to a static variable somewhere else (sort of odd that you should even be able to, but I digress), it effectively "de-CMPs" the variable - a bad thing.

     

     

    Alternatively consider that tables are global by default, so you could use any other event to "prime" the table if it didn't exist and use it anywhere and for any connection.
  • as far as I know table should be synced while static array not, please correct me if I wrong. not sure if i am lost. since it is static, do we have to synchronize it??
  • the thing is that it shouldn't be static, I want that this information (table/array) will be synced between both F5.

    Let me explain what I am trying to achieve, I have demand to create mapping between virtual server to a node, that means the for N VS I will have N nodes and map on to one, in addition I have on server that it is the backup for all the servers and if one fails the backup server and the failed server are switched (the VS map changes to the backup and the the failed server become to be the backup server).

    I need this mapping will be synchronized between the F5 and this is why I want to use the tables because as far as I know the tables are synced.

    Since that I am not able to create the mapping in the rule init I did it on the client accepted:

     
    when CLIENT_ACCEPTED {
    set Server_IP [table lookup -subtable "Server_Map" [IP::local_addr]]
    
    if {[table lookup -subtable "BacupServer" 1] eq ""}{
    set BckSrv "[class search -value Backup eq 1]"
    table set -subtable "BacupServer" 1 $BckSrv indefinite
    }
    
    if {$Server_IP eq ""}{
    set Server_IP "[class search -value ProxyIP eq [IP::local_addr]]"
    table set -subtable "Server_Map" [IP::local_addr] $Server_IP indefinite
    }
    set status "[LB::status node $Server_IP]"
    if {$status eq "down"}{
    set BackupServer [table lookup -subtable "BacupServer" 1]
    table set -subtable "Server_Map"  -mustexist [IP::local_addr] $BackupServer
    table set -subtable "BacupServer"  -mustexist 1 $Server_IP
    set Server_IP $BackupServer
    }
    node $Server_IP
    }
    

    I hope that I am clear on what I am trying to achieve, if not please let me know I will try to be more clear.

    Thanks a lot! 🙂