Technical Article

Java iControl Objects – LTM iRule

This is the third article in the “Java iControl Objects” series in which I define a set of objects that implement the iControl methods in various iControl interfaces. The previous articles covered the Pool and PoolMember interface.

For this article, I’ve decided to look at the LocalLB Rule interface where you manage the creation of iRules on your BIG-IP LTM. For those that aren’t familiar with iRules, check out the iRules overview page and/or the iRules wiki for a description and various examples.

The Class

iRules at their core are essentially just a text string containing the script code with a name identifying the specific iRule. So, the two main members defining the iRule object are the name and description. The iControl.interfaces object is in there to define communication to the LTM and I’ve added the storage of a Java Exception for some of the classes where exceptions were caught during the processing. That way, after the fact you can go and find out what the core problems were if some of the action methods defined below failed for any reason.

Below the member declarations, I’ve included Java-styled accessor methods along with two constructors used to create new objects. In this example, I’ve included a constructor that takes a iControl.LocalLBRuleRuleDefinition structure as input for assistance in the getList static method defined below.

Action Methods

In the iRule interface, there aren’t any additional accessor methods so I skipped those and went right to the action methods. I’ve defined the following methods

save – Save the current iRule. This first attempts to make a create call and if that fails, it attempts to do a modify. This way an object can be saved whether it exists or not on the system.

load – Load will query the iRule definition for the specified iRule’s name. It will then populate the definition member variable with the iRule syntax.

checkSyntax – Not sure whether your iRule is valid syntax? This method will create a temporary iRule and attempt to save the iRule description. This will return an error if the syntax is invalid and the error message is stored in the lastException member.

delete – This will delete the iRule on the system. It won’t delete the local variable so if you want to undo your delete, you can just issue the save command.

getStatistics – This will return the various performance metrics for the given iRule. This data is valuable for debugging performance.

resetStatistics – This will reset the statistics counters for your iRule.

Static Methods

The iRule interface has a couple of places static methods (methods that can be called without actually creating an instance of the object) can come in handy. I’ve created the getList() and exists() methods that will allow you to return a list of iRule objects for all the iRules on the systems and allow you to check whether a given iRule name is available. The code for these routines can be found below.