Did you have good time writing Java and Powershell programs discussed in last blogs (/blogs/2011/12/07/nitro-unleash-the-power-using-powershell/). Question is whether the support is limited to these selective programming languages?? You know the answer, isn’t it 🙂 … NITRO APIs can be used in any of the scripting languages as far as you can do basic HTTP based programming. Most of the scripting languages today, provide built-in HTTP modules to simplify the scripting experience and it helps with NITRO as well. With scripting languages we do not have SDKs but you can simply build a module for NITRO and use the functions in your scripts.
Let us discuss a Perl based NITRO implementation which utilizes a Perl module having core methods nitro_pm. We will discuss the scripting aspect assuming you have the module with you. The module has simple functions defined as:
As you see with these functions you can do most of the day to day operation and let us now take a look at how you will use these functions in the script. We will do following simple tasks which put together the script:
- Login to NetScaler
- Adding LB vserver
- Getting LB vserver details
- Setting/Modifying LB vserver
- Removing LB vserver
- Logout from NetScaler
Let us go over step by step procedure on how we can accomplish this.
Step 1: Import relevant libraries
- use nitro;
- use Storable qw(dclone);
The “nitro” library provides functions for session creation/termination, dealing with LB vserver configuration, handling the response etc.
Step 2: Logging into the NetScaler and creating a session
Before you do any functional operation using NITRO API, must have a valid session established by performing login to the NetScaler system.
- $session = nitro::ns_login($nsip,$user,$pass);
The above code provides a NITRO session with NetScaler on given IP address and performs login with given username and password. You need to parse and handle the response to check for any error.
Step 3: Adding LB vserver
Once you have established valid session, it is very easy to start with specific LB vserver configuration.
- my %lbvserver_hash=();
- $result = nitro::add_object($session,”lbvserver”,$lbvserver_hash);
We are creating a LB vserver hash and setting various properties in the hash. The “add_object” method adds the lbvserver on the session created.
Step 4: Getting LB vserver details
Show operation is straight forward and only requires single API call.
- $result1 = nitro::get_object($session,”lbvserver”);
This call returns you the complete structure for the LB vserver “lbvip1”. You can parse the result and get further data.
Step 5: Setting/Modifying LB vserver
LB vserver has several properties which you may want to change at runtime using the “modify_object” method.
- my %lbvserver_hash_modify=();
For setting the properties we define a LB vserver hash and set respective key->value pairs.
Step 6: Remove LB vserver
Let us delete the LB vserver configuration we have created in this example. It is again a simple operation with single API call to remove the configuration.
We are using the same session and calling the “delete_object” method for removing the LB vserver.
Step 7: Logging out of NetScaler
As usual logging out of the session is quite important and here is the API
With this you have ensured successful logout from the system. Be sure to parse the response and ensure a successful logout.