NITRO: Unleash Power using PowerShell

12:43 PM
NITRO: Unleash Power using PowerShell -

Check ... check ... Have you tried the Java API NITRO program discussed in the last blog (/ blogs / 2011 / 12/01 / nitro-based -Advice on fast-writing-java-program /)? Needless to say, you can not realize the power of this great part by trying these examples. Maybe you are the fan of Microsoft and is the same example using PowerShell you'll certainly try :)

Module NetScaler NITRO API integrated NetScaler SDK for CSharp which is similar to what we have for Java and it helps when you start using these integrated API to code your PowerShell program. The SDK for CSharp is a bundle of documents, samples and library files. The libraries are DLLs containing only object files for the classes used in NITRO. The SDK documents include a starter guide and detailed information about the classes and methods available in the classrooms. SDK can be found under the "Downloads" tab in your Netscaler IU

Let us start writing the PowerShell script to do the following on the Netscaler :.

  1. Login for Netscaler
  2. Add a lbvserver
  3. Set the lbvserver
  4. Get the lbvserver by Name
  5. Remove lbvserver
  6. Disconnect from session

Step 1 :. Load required modules

two library files in the SDK are responsible overall.

  • $ path1 = Resolve-Path Newtonsoft.Json.dll
  • [System.Reflection.Assembly] :: LoadFile ($ path1)
  • $ path = Resolve-path nitro.dll
  • [System.Reflection.Assembly] :: LoadFile ($ path)

Step 2 :. Create a session with the NetScaler

class 'nitro_service' can be used to create a session with the Netscaler. To start with the script, please first create an object for the class nitro_service available nitro.dll.

  • $ nitrosession com.citrix.netscaler.nitro.service = new-object. nitro_service ($ NSIP, "https")
  • $ session = $ nitrosession.login ($ user, $ pass)

You created the session object and connected to the NetScaler using the username and password. Any call setup via NITRO returns an object 'base_response'. This response includes an error code and a message. For a successful transaction, the answer will be "zero" for the error code and "Done" to the message. Any non zero error code is considered a failure

Step 3 :. Add a lbvserver

Now that you have created the session with Netscaler, you can create the LB vserver on NetScaler. To add a lbvserver, please create object for the class of lbvserver and set the required arguments for the object. Mandatory arguments to be lbvserver 'name' and 'servicetype'.

  • $ lbvserver1 = New-Object com.citrix.netscaler.nitro.resource.config.lb.lbvserver
  • $ lbvserver1.name = "lbvip_sample";
  • $ lbvserver1.servicetype = "http";
  • $ ret_value = [com.citrix.netscaler.nitro.resource.config.lb.lbvserver] :: add (nitrosession, $ lbvserver1)

When finished with the object, call the "add" method that takes two parameters, the purpose of the session and lbvserver object. The answer may be treated to all failures

Step 4 :. Take lbvserver

In dynamic situations, you may have to modify the properties of existing entities on Netscaler. To change the properties that you can use the method 'update' available in the corresponding base class. Let's see how to set / update the property 'lbmethod' for lbvserver you created. We will use the same lbvserver object that was created by adding the lbvserver. The setting operation is done by calling the Update method of the class lbvserver

  • $ lbvserver1.name = "lbvip_sample of" ;.
  • $ lbvserver1 .lbmethod = "RoundRobin";
  • $ ret_value = [com.citrix.netscaler.nitro.resource.config.lb.lbvserver] :: update (nitrosession, $ lbvserver1)

Step 5: Get lbvserver

How can you check whether all transactions were made before, have updated successfully Netscaler. Get operation on any entity can be done in two ways.

  1. Get all entities based on type or group
  2. Get a specific entity name of the same

Example below gets the vserver LB by name:

  • $ ret_obj = [com.citrix.netscaler.nitro.resource.config.lb.lbvserver] :: get (nitrosession, $ lbvserver1.name)

here the value return will itself lbvserver object. So variable $ ret_obj will have all the properties of the lbvserver you have recovered the NITRO help. This variable can be analyzed to obtain the values ​​

  • Write-Host "Show lbvserver: lbvserver name -". $ Ret_value.name "servicetype -" $ ret_value.servicetype "port -" $ ret_value.port "IP address -" $ ret_value.ipv46

on $ ret_value.name parameter returns the name of lbvserver. All values ​​related to lbvserver object can be obtained in the same manner. For details on the structure of the lbvserver class, you can view documents in the SDK

Step 6 :. Remove a lbvserver

It is time to remove the LB vserver you created. The operation is similar to other operations such as add and configure. The method used for the removal of resources will "remove".

  • $ ret_value = [com.citrix.netscaler.nitro.resource.config.lb.lbvserver] :: delete (nitrosession, $ lbvserver1)

Step 7: disconnect from session

Learn from last example, it is always advisable to disconnect the session established with the Netscaler for security reasons. Disconnection is again a simple operation that will end the session is established.

  • $ session = $ nitrosession.logout ()

With this you ensured the successful disconnection of the system. Make sure you analyze the response and ensure a successful disconnection. Now you will say that the language and the environment does not matter, it's just easy to use API using NetScaler NITRO NITRO SDK.

Previous
Next Post »
0 Komentar