Vous êtes sur la page 1sur 70

604: Automating NetScaler Deployments and

Monitoring using the NetScaler 10.5 NITRO API

Hands-on Lab Exercise Guide

Brian Tannous

May 2015

|1 |
Table of Contents
Table of Contents....................................................................................................................... 2
Overview .................................................................................................................................... 3
Lab Preparation: ....................................................................................................................... 6
Attach XenCenter to Your XenServer .................................................................................... 6
Exercise 1: Becoming Familiar with REST ................................................................................. 9
Exercise 2: Getting Started with NITRO ....................................................................................18
Exercise 3: Getting Configuration and Statistics ........................................................................29
Exercise 4: Adding, Updating, and Deleting Configurations.......................................................43
Exercise 5: Enable Interceptor ..................................................................................................54
Exercise 6: NITRO Web Client ..................................................................................................55
Exercise 7: Interceptor ..............................................................................................................60
Exercise 8: Advanced NITRO Automation via Python ...............................................................65

|2 |
Overview
Hands-on Training Module
Objective
 This training will provide hands-on experience with using NetScaler VPX virtual appliances
to automate monitoring and the configuration of NetScaler via the RESTful NITRO API.

Prerequisites
 This training focuses on automating the configuration and monitoring of NetScaler. It is
assumed that the student already knows the basics of NetScaler configuration, basic load
balancing, web servers and web traffic flow. While not necessary, it is recommended that
the student already knows the basics of HTTP methods, JSON, and XML.
o Please note that we will be working extensively with the above technologies and
some familiarity is recommended but not completely necessary. Each configuration
request we make to NITRO will utilize the raw JSON data type. Keep this in the back
of your mind, raw JSON. Whitespace in JSON is not vital, but double quotes
and brackets are. An example is:
{“example”:true}

Is equal to

{
“example”: true
}
 While not necessary at this time, I encourage everyone to check out these resources to
further your NITRO experience and knowledge.
o http://blogs.citrix.com/2014/09/03/automating-netscaler-using-nitro-restful-services-
recommended-settings-and-best-practices-for-a-generic-implementation-of-a-
netscaler-appliance/
o http://blogs.citrix.com/2014/09/18/automating-netscaler-using-nitro-restful-services-
video-introduction/

Audience
 Citrix Partners, Customers, Sales Engineers, Consultants, Technical Support.

|3 |
Lab Environment Details
The system diagram of the lab is shown below:

The Student Desktop is accessed remotely using Citrix Receiver running on your workstation. All
Windows applications such as the XenCenter (the XenServer GUI management tool), are accessed
from the Student Desktop. The tools required for this lab, POSTMAN and Chrome, are also
accessed from the Student Desktop. The last lab section covers automation via python, which will
be accessed from the Debian TOOLS server.

Lab Guide Conventions


This symbol indicates particular attention must be paid to this step
Special note to offer advice or background information
Text the student enters or an item they select from a dropdown menu is printed like
reboot
this
Start Bold text indicates reference to a button or object

Focuses attention on a particular part of the screen (R:255 G:20 B:147)


Shows where to click or select an item on a screen shot (R:255 G:102 B:0)

|4 |
List of Virtual Machines Used
VM Name IP Address Description / OS
AD.training.lab 192.168.10.11 Active Directory Server / Win 2012 R2
StudentDesktop 192.168.10.10 Student Desktop / Win 7
NetScaler: NS1 192.168.10.20 NetScaler 10.5 VPX (NSIP)
NetScaler: NS2 192.168.10.30 NetScaler 10.5 VPX (NSIP)
NetScaler: NS3 192.168.10.40 NetScaler 10.5 VPX (NSIP)
WebServer: WWW1 192.168.10.50 Debian 6 Web Server
WebServer: WWW2 192.168.10.51 Debian 6 Web Server
ToolsServer: TOOLS1 192.168.10.60 Debian 6 Tools / Web Server

Required Lab Credentials


The credentials required to connect to the environment and complete the lab exercises are shown
within the step by step instructions and are summarized below:
VM Name Username Password Description
NetScaler:
nsroot nsroot NetScaler 10.5 VPX Appliance
NS1 – NS3
WebServer:
citrix Password1 Debian 6 Web Server
WWW1 – WWW2
ToolsServer:
citrix Password1 Debian 6 Tools / Web Server
TOOLS1

Reserved IP Ranges
IP range Description
192.168.10.20 – 192.168.10.49 NetScaler SNIPs and VIPs

|5 |
Lab Preparation
Attach XenCenter to Your XenServer
Overview
XenCenter is a graphical user interface application used for managing one or more XenServers.
You will be using XenCenter to manage the XenServer needed for the lab.

Step by step guidance


Step Action
1. Before we begin, if you encounter a dialog requesting an update do Java or a request to
restart your computer to apply changes during the lab, please select No or Restart
Later.

2. From your Student Desktop, launch Citrix XenCenter.

|6 |
Step Action
3.

Double-click on the xenserver entry in the left pane of XenCenter.

4. Enter your physical XenServer parameters from your welcome screen.

Username admin
Password Your XenServer password

You may find it easier to copy


and paste the password to
ensure it is entered correctly.

Click Add.

5.
Your Physical XenServer name will be different.

XenCenter will connect and synchronize to your physical XenServer.

|7 |
Step Action
6.

Summary
You have connected to your XenServer.

|8 |
Exercise 1: Becoming Familiar with
REST
Module Description and Summary
In this exercise, you will get started and familiar with RESTful services within the lab environment.
We will begin by looking at a RESTful testing service running within the lab using a standard web
browser, then we will move on to becoming acclimated with the REST client POSTMAN. Becoming
familiar with RESTful services is important for automating NetScaler via NITRO as NITRO is a
RESTful API. You will utilize all of these fundamentals in later exercises.

Step by step guidance


Estimated time to complete this exercise: 30 minutes.

Step Action
1. On the student landing desktop virtual machine, launch Google Chrome. Click the
TOOLS bookmark in the bookmark bar. This will open the http-bin REST testing service.

|9 |
Step Action
2. Open the Google Chrome Developer Tools by clicking on the menu at the top
right of the browser and heading to More tools, followed by Developer tools.

3. Open the Network tab and be sure that the Record Network Log button is lit red.

| 10 |
Step Action
4. Next, click on the /get endpoint.

5. Congratulations! You just completed a REST call. We used the HTTP method GET to
connect to the endpoint /get. The server replied with the JSON payload of our headers,
args, origin, and url of the request. Look at the Network tab to see the HTTP Method,
HTTP Status, and check out the JSON payload replied in the body of the browser.

| 11 |
Step Action
6. Now that we have seen that RESTful services operate over standard HTTP methods and
we can access some of them by just using a standard web browser, we will open the
REST client Postman. Postman is a Google Chrome packaged app extension that
allows you to create and intercept REST requests much easier than using some
alternatives. Open Postman via clicking on the icon on the Student Desktop.

7. Let’s start by running the same HTTP GET to the /get endpoint in Postman. Open the
Collections tab and expand Exercise 1: RESTful Services. Finally open the /get
endpoint.

| 12 |
Step Action
8. Verify the URL endpoint is /get (Hint: In the URL, the endpoint is the section after the
FQDN or http://tools.training.lab. In our example the URL is http://tools.training.lab/get,
therefore the endpoint is /get) and that the HTTP Method is GET (the HTTP Method is
defined in the dropdown box).
Click on Send. Notice that the body of the response is the same as before, and the
HTTP STATUS is a 200 OK.

| 13 |
Step Action
9. Now, let’s use the HTTP Method GET to request the /status/:StatusNumber endpoint.
Select the /status/:StatusNumber endpoint. Here we place a HTTP GET request to
the server specifying which HTTP Status for it to return by requesting the status code in
the URL. Verify the request is to the /status/<Status> endpoint and the HTTP
Method is GET.
Finally click on Send and verify the HTTP status returned is 418.

Note: HTTP Status Code 418 might look a little funny with the teapot and all, but it is
actually a RFC defined status code originally made as an april fools joke.
http://tools.ietf.org/html/rfc2324 More standard HTTP status codes would be 200, 201,
404, 500, ect. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

10. Try another HTTP Status in the request. You can try any HTTP Status Number (a few
examples would be 200, 201, 302, 401…etc.) in the example we switch 418 to 500.
Click Send and verify the HTTP Status returned is what you requested.

Note: The tools.training.lab server will just echo your status you requested! That is all
this service actually does…echo’s requests.

| 14 |
Step Action
11. Open the /post With Params endpoint. Here we are going to make an HTTP POST to
the service.
Verify the endpoint URL is /post and click on URL params, if not expanded already.
Here we are passing parameters to the server via keys and values. Verify our parameter
exampleParam1 is set with the value of exampleValue1. (You might have noticed the
?exampleParam1=exampleValue1 after the endpoint in the URL. This is where URL
parameters reside. If you add more parameters in the fields below you will notice them
appear up in the URL as well.)
Click on Send. Verify the response returned has an HTTP Status of 200 OK, meaning
all is well and verify that the args returned in the body are the URL parameters we
requested.

Note: In this example our tools server just echoes back our requested parameters, as
expected!

| 15 |
Step Action
12. Open the /put With JSON Data endpoint. Here we are going to make an HTTP PUT to
the service and in our request we will send some JSON data.
Verify the endpoint URL is /put and click on raw, if not expanded already. Here we are
passing a payload to the server via JSON data. Verify that the data is specified.
Remember that raw json idea at the beginning of this lab guide? Here is the start. We
are passing a raw type of data in our request. The data is formatted JSON.
Also, remember from the prerequisites that whitespace in JSON is not vital, but double
quotes and brackets are.
Click on Send. Verify the response returned has an HTTP Status of 200 OK, meaning
all is well and verify that the data returned in the body is the payload data we
requested.
The tools server echoed our data as expected!

| 16 |
Step Action
13. Finally we are going to create your own delete request and send it to the server. Click on
the Reset button.
Once the request has been reset enter http://tools.training.lab/delete for the
request URL. Select DELETE for the HTTP Method. Input some JSON data into the
payload, select raw and enter:
{
“Example”: 1
}
Click Send. Verify that the HTTP STATUS returned is a 200 OK and the payload data
has been returned back to you.

Exercise Summary
In this exercise, you were able to utilize HTTP-Bin, Google Chrome, and Postman to become
familiar with RESTful services and the tools that we will be utilizing in this lab. If you wish, take a
moment to explore the other endpoints and items in the postman collection.

| 17 |
Exercise 2: Getting Started with
NITRO
Overview
In this exercise, you will begin to get familiar with the RESTful NetScaler NITRO API.
In this exercise you will:

 Download the NetScaler NITRO REST documentation

 Create a NITRO connection to the NetScaler

 Save the NetScaler configuration via NITRO

 Reboot the NetScaler via NITRO

 Close a NITRO connection to the NetScaler

Step by step guidance


Estimated time to complete this exercise: 30 minutes.

| 18 |
Step Action
1. In this first step we will learn where to download the latest NetScaler NITRO documentation.
We already a have a local copy of the documentation stored on the Student Desktop for you
to use, so this step is purely informational.
First, login to NS3 within Google Chrome. The user name is: nsroot and the password is:
nsroot

Next, head to the Downloads tab at the top right of the NetScaler GUI.

Scroll down and you will find the NITRO section with the SDK and documentation for all of
the programming languages the NITRO API has documentation or an SDK for. In our lab
we will be using the REST methods to connect to the NetScaler, therefore the
documentation we will be using is the NITRO API Documentation. As stated above, this
already is downloaded and available on the Student Desktop so you do not need to
download it yourself.
Details: The API docs have been downloaded, extracted, and placed at
C:/users/localuser/NitroDocs and a bookmark has been made to the index page in your
browser.

| 19 |
Step Action
2. Logout of NS3. This is important as Postman and Chrome share the same session and cookie information. If
you did not logout of NS3 here you would run into issues with Postman and NITRO.

3. We can head to the NetScaler NITRO REST API Documentation by clicking on the NITRO
API Docs within the Google Chrome browser. Here we can see the Getting Started Guide,
as well as the sidebar that contains the REST resources available to us via the API.

The documentation will be your go-to place for all information relating to the NITRO API.
For example, below you can see the configuration -> basic -> nstrace functionality
expanded. This resource allows you to interact with nstrace.

| 20 |
Step Action
Info This is not necessary now, but at any time responses to your requests get hung up or stuck
and you are sure you have the request correct, it is a good troubleshooting step to close and
reopen postman, and then perform a logout followed by a login.

4. Our first step in any and every interaction with NITRO is to perform a login to authenticate
our user. In this step we will head to the Getting Started Guide and go to page 8, which
contains all of the NITRO login information to build our REST request. Make note of the
URL, Method, Headers, and Payload as we will use this information in the next step.

| 21 |
Step Action
5. Login
In this step we will perform a login to the NetScaler. To do so open Postman and click on
the Reset button.
Enter http://ns3.training.lab/nitro/v1/config/login as the request URL and set
the HTTP Method to POST as the documentation above states. Select Headers, if not
already selected, and enter the Content-Type header with its value as
application/vnd.com.citrix.netscaler.login+json

Note: The Content-Type header is an important field when performing a HTTP POST, PUT,
UPDATE, and DELETE to NITRO (HTTP GETs are a different subject and we will detail
them later). When performing these operations be sure to include this header, with the
appropriate value. The value must match the function in the URL that you are performing.
Therefore, in our example we are performing a login via the request URL of
/nitro/v1/config/login this must match the header of
application/vnd.com.citrix.netscaler.login+json Be sure to notice this value in subsequent
steps.
Also, remember from the prerequisites that whitespace in JSON is not vital, but double
quotes and brackets are.
Finishing our request, we will select raw as our payload and enter the data of:
{
"login":
{
"username":"nsroot",
"password":"nsroot",
"timeout":900
}
}

| 22 |
Step Action
6. Submit the response by clicking on Send. Verify that you are logged in by receiving a HTTP
Status of 201 Created. Also, verify that the NITRO_AUTO_TOKEN exists in the Cookie by
clicking the Cookies tab.

Note: The NITRO_AUTH_TOKEN is an important piece of all communications via NITRO.


Each NITRO request you must include the cookie containing the NITRO_AUTH_TOKEN so
that you can operate via your session. The Postman client automatically takes care of
including the cookie within your requests, so you do not need to worry about it for this lab,
but if you develop your own scripts aware of the token and cookie and be sure to include
them.
Troubleshooting Note:
If you do not see the Cookies tab as shown below, look at the top right of the Postman application. Be
sure that the traffic light is lit up green. If not, click it once and it will light from grey to green.
(Screenshot below) You will have to logout and login to see the cookie populate, but don’t worry about it
now – you can see the cookie in later steps.

Troubleshooting step, if needed:

| 23 |
7. Save Configuration
Within Google Chrome head to the NetScaler API Docs. Head to Configuration -> NS ->
nsconfig and find the save method. Make note of the same fields as above: URL, HTTP
Method, and payload.
Note: The URL in the documentation is incorrect as it should be
http://ns3.training.lab/nitro/v1/config/nsconfig

Build your request to save the configuration of the NetScaler using the resources you took
note of above. Enter http://ns3.training.lab/nitro/v1/config/nsconfig as your
request URL and HTTP Method of POST. This time be sure to select URL params and
Headers as we need to pass both to NITRO with this request as per the documentation.
Enter a URL Parameter Key of action with the value of save add the Content-Type
header with the value matching our url of
application/vnd.com.citrix.netscaler.nsconfig+json Finally, select raw as the
payload and enter the data of:
{
"nsconfig":
{
}
}

| 24 |
Step Action

8. Send the request to save the configuration by clicking Send. You can verify that the request
was successful by looking at the HTTP status of 200 OK.

| 25 |
9. Logout
The next step is to logout or disconnect from the NetScaler. First we look up the
documentation in the Getting Started Guide. In the guide we will look for disconnecting
from the appliance. Here we make note of the URL, HTTP Method, Request Header, and
payload. (pg.10)

.
We enter http://ns3.training.lab/nitro/v1/config/logout as the request URL and
the HTTP Method of POST. Be sure to select headers and fill in the Content-Type
header’s value of application/vnd.com.citrix.netscaler.logout+json Finally we will
select raw as our payload type and set the data of:
{"logout":
{
}
}

Click on Send and verify that the logout occurred by receiving a 401 Unauthorized as your
HTTP Status.

| 26 |
Step Action

| 27 |
Step Action
10. Challenge! Reboot the NetScaler using NITRO
Using the API documentation at Configuration -> NS -> Reboot build the request to reboot
your NetScaler and send it to NS3.training.lab. You will be using the reboot method.

Also, the return value might not be a 200, as the API can and will send return values or
HTTP status codes per request, verify that the NetScaler rebooted via either firing up
XenCenter and checking the NS3 console, or opening CMD and pinging ns3.training.lab.
Hints below!
Hint 1:
Your payload information will be { “reboot”: { } }
Note: Remember, whitespace in JSON doesn’t matter.
Hint 2:
Are you logged in?
Hint 3:
Your URL will be http://ns3.training.lab/nitro/v1/config/reboot with the HTTP Method of
POST
Hint 4:
Be sure to set that Content-Type header correctly! (application/vnd.com.citrix.netscaler.reboot+json)

Exercise Summary
In this exercise, you connected to NetScaler using the NITRO API. We performed logging in,
logging out, saving the configuration, and rebooting the appliance.

| 28 |
Exercise 3: Getting Configuration
and Statistics
Overview
In this exercise, you will work with the NITRO API to request and retrieve configuration and
statistics from NetScaler.
In this exercise you will:

 Utilize the NITRO API to get the enabled NetScaler Modes and Features

 Utilize the NITRO API to get all available Load Balancing Virtual Servers

 Apply filters on returned results

 Utilize the NITRO API to get statistics for various aspects of the NetScaler appliance

Step by step guidance


Estimated time to complete this exercise: 20 minutes.

Step Action
1. The first step of any interaction with NITRO is to login. Open Postman and head to the
History tab. From here we can see the login method that we utilized earlier. Click on
this method and hit send. Be sure you receive a 201 as the HTTP Status in the
response area.

Note: If you are currently logged in your HTTP status received will be a 599. If there is an
issue with your session and you receive a 401 try to perform a logout followed by a login.

| 29 |
Step Action
2. Let’s begin by getting the configuration of the NetScaler modes that are enabled and
disabled.
Like always, we will begin with the documentation. We can find the nsmode
documentation by heading to the NITRO API Docs in Google Chrome and heading to
Configuration -> NS -> nsmode. Find the get method. Here we will make note of the
URL and HTTP Method.

| 30 |
Step Action
3. As per the documentation, now we will head to Postman, click on Reset and fill in the
request URL of http://ns3.training.lab/nitro/v1/config/nsmode with HTTP
Method of GET. We will open the Headers and add the Accept header with value of
application/vnd.com.citrix.netscaler.nsmode+json

Note: You may notice that the header we are including in our request is different than the
header that was included in the previous requests. When performing an HTTP GET to
NITRO we need to include the Accept header instead of the Content-Type header. The
value of the header remains the same and we still need to follow the same rule as the
Content-Type header in that the value must match the function that we are performing.

4. We will send the response by clicking Send. Acknowledge the 200 status meaning all is
well and make note of the response body. The items that were sent in the mode
element highlighted below are all enabled. You can also see individual elements below
and if they are enabled, value of true, or disabled, value of false.

| 31 |
Step Action
5. Compare this to the modes that you see enabled in the NS3 NetScaler GUI.
To do so, head to Google Chrome and open NS3. Login using the default credentials of
username nsroot and password nsroot.

Head to the Configuration tab and expand the System element in the sidebar. Head to
Settings and click Configure Modes.

Here we see the same modes that are enabled and disabled as above.

| 32 |
Step Action
6. Challenge! Let’s get the NetScaler features that are enabled and disabled.
Reference the NITRO API Docs in Google Chrome by heading to Configuration -> NS -
> nsfeature.

Reference the results you got from the NITRO API to the NS3 GUI. You should see the
same items enabled and disabled.

Hint!
Think about your Accept header. Here are the relevant bits of information from step 3.
URL: http://ns3.training.lab/nitro/v1/config/nsmode

Accept:application/vnd.com.citrix.netscaler.nsmode+json

What is our URL this time? What does the accept header need to be? Look at the
underline ;)

| 33 |
Step Action
7. Next we will get all available load balancing virtual servers and their configurations.
We will head to the documentation by opening Google Chrome, heading to NITRO API
Docs and clicking Configuration. We will go to lb followed by lbvserver. Find the get
method. Make note of the URL and the HTTP Method. Like before, since we are
getting content the method is an HTTP GET.

8. We will open Postman and click on the Reset button.


We will fill in the request URL of
http://ns3.training.lab/nitro/v1/config/lbvserver with HTTP Method of GET.
Select the Headers and fill in the Accept header’s value of
application/vnd.com.citrix.netscaler+json

| 34 |
Step Action
9. Next we will click Send. Acknowledge the HTTP Status of 200 and the body that was
returned. We should see two lbvservers, WWW and TOOLS. For information about each
returned item you can refer to the documentation.

| 35 |
Step Action
10. Having all of the data in one call can be great, but sometimes we might only require a
subset of data to be returned. This concept applies to most GET methods in NITRO.
In this request we want to only return the name, load balancing method, and persistence
type of the WWW virtual server.
To do so we edit the request URL to be
http://ns3.training.lab/nitro/v1/config/lbvserver/WWW Here we add WWW at
the tail end of the url. This tells NITRO to only return the lbvserver WWW.
We will add a URL parameter to limit the data that gets returned by adding the attrs
URL Parameter Key with value of name,lbmethod,persistencetype Be sure not to
include spaces. (Note: If you do not see URL Parameter Key and Values click the URL
Params button)
Since this is a NITRO GET method we need to be sure to include the Accept header and
its value of application/vnd.com.citrix.netscaler.lbvserver+json

11. Click send and notice HTTP Status of 200 and the body that was returned. We
successfully only returned the WWW virtual server with a few data points.

| 36 |
Step Action
12. Challenge!
Apply your knowledge of getting configuration elements within NITRO to get the list of
names and ports of all of the services enabled within NS3. Your response body should
be:

Hint: The Service documentation can be found in the documentation at Configuration ->
Basic -> Service and your method will be get.

| 37 |
Step Action
13. Now we will use the HTTP GET method to get statistics from the NetScaler. The first
thing that we will get would be general NetScaler stats.
Head to the NITRO API Docs and open Statistics -> NS -> NS and find the get method.
Make note of the URL and the HTTP Method.

14. Fill in the request URL of http://ns3.training.lab/nitro/v1/stat/ns with the


Accept header of application/vnd.com.citrix.netscaler+json Be sure your HTTP
method is GET.

| 38 |
Step Action
15. Click Send and make note of the objects that you received such as the CPU Usage, and
Memory usage.

16. Next, let’s get details about the NetScaler’s interfaces.


Open the NITRO API Docs and head to Statistics -> Network -> Interface. Find the get
method and make note of the URL and HTTP Method.

| 39 |
Step Action
17. Open Postman and enter http://ns3.training.lab/nitro/v1/stat/interface as
the request URL with the Accept header of
application/vnd.com.citrix.netscaler+json Be sure to select GET as the HTTP
Method.

18. Click on Send and notice the interfaces and their statistics such as uptime, transmit
receive rate and send rate.

| 40 |
Step Action
19. Lastly, get the statistics of the WWW Load Balanced Virtual Server.
Open Google Chrome and head to the NITRO API Docs. Open Statistics -> Load
Balancing -> lbvserver. Find the get method and make note of the URL and the HTTP
Method.

20. Enter http://ns3.training.lab/nitro/v1/stat/lbvserver/WWW as the request URL


with the HTTP Method of GET. Add the Accept header with value of
application/vnd.com.citrix.netscaler+json You may notice that we are filtering
here similar to how we filtered with the configuration section by adding WWW after the
lbvserver in the URL.

| 41 |
Step Action
21. Click Send and note the statistics of the WWW lbvserver. Here we can see things such
as health, state, request and hit rate, amongst others.

If you wish, you can filter the data points in the response the same way that we did earlier
by passing in the attrs url param with the value of the elements you wish to retrieve.

Exercise Summary
In this exercise, you retrieved configuration and statistics via the NITRO API from the NetScaler
appliance. We first retrieved the enabled and disabled NetScaler modes and features. Next we
worked with the configuration of load balancing virtual servers and filtering. These methods of
getting and filtering content and configuration can be applied to all various configuration methods of
the NetScaler appliance such as Content Switching or Policy. We finally wrapped up with getting
statistics from various aspects of the appliance.

| 42 |
Exercise 4: Adding, Updating, and
Deleting Configurations
Overview
In this exercise, you will further your NITRO skillset by utilizing the add, update, and delete
functionality of the NITRO API. For this exercise we will be utilizing NS2, which is a fresh, clean
configuration NetScaler.
In this exercise you will:

 Utilize NITRO’s update method by enabling NetScaler Features.

 Utilize NITRO’s add method by adding a Load Balanced Virtual Server

 Utilize NITRO’s delete method by deleting a Load Balanced Virtual Server

Step by step guidance


Estimated time to complete this exercise: 30 minutes.

Step Action
1. Use your knowledge (or the postman history) to perform a login to NS2.training.lab.
Step 3 Exercise 2 should help if you need assistance. Remember to change the url to
NS2.training.lab

| 43 |
Step Action
2. For this exercise we will be utilizing NS2, which is a fresh, clean configuration
NetScaler. Since our ultimate goal is to enable a load balanced virtual server we will
need to first enable the load balancing feature.
We will head to the NITRO API Docs on Google Chrome and open the Configuration
-> NS -> NSFeature element. We will find the enable method.
Make note of the URL, HTTP Method, and Request Payload.

| 44 |
Step Action
3. Create the request by opening Postman, clicking Reset and entering
http://ns2.training.lab/nitro/v1/config/nsfeature?action=enable for the
request URL. Set the HTTP Method to POST. We will set the URL Parameter Key to
action with a value of enable as per the documentation. We will also include the
Content-Type header with value of
application/vnd.com.citrix.netscaler.nsfeature+json The payload will be set
to raw with the data of:
{
"nsfeature":
{
"feature":
[
"lb"
]
}
}

4. Finally click Send. You should see a status of 200 OK meaning that the feature was
enabled.

| 45 |
Step Action
5. Next we need to add a load balancing virtual server.
We open the NITRO API Docs and head to Configuration -> Load Balancing ->
lbvserver. Find the add method. Make note of the URL, HTTP Method, and
Request Payload.

| 46 |
Step Action
6. Open Postman, click reset and enter
http://ns2.training.lab/nitro/v1/config/lbvserver as the request URL. We
will set the HTTP Method to POST and configure a header of Content-Type with
value of application/vnd.com.citrix.netscaler.lbvserver+json The payload
will be set to raw with the data of
{
"lbvserver":
{
"name":"WWW",
"servicetype":"http",
"ipv46":"192.168.10.32",
"port":80
}
}

7. Click on Send. You should see an HTTP status of 201 Created if the virtual server
was added.

| 47 |
Step Action
8. The next step of adding a load balanced virtual server is to add some services to load
balance.
First we need to create the services.
To do so we head to the NITRO API Docs and open Configuration -> Basic ->
Service. Find the add method. Make note of the URL, HTTP Method, and Request
Payload.

Note: The items in red are the required fields.

| 48 |
Step Action
9. Now we will build the request.
Open Postman, and click on reset. We will enter
http://ns2.training.lab/nitro/v1/config/service as the request URL with the
Content-Type header and value of
application/vnd.com.citrix.netscaler.service+json We will set the payload
data to raw and fill in the field with
{
"service":
{
"name":"WWW1",
"servicetype":"http",
"ip":"192.168.10.50",
"port":80
}
}

10. Send the request and notice that the HTTP Status returned should 201 Created,
meaning the service was created.

| 49 |
Step Action
11. Now we will bind the newly created service to the load balancing virtual server that we
also just created.
We will open the NITRO API Docs and head to Configuration -> Load Balancing ->
lbvserver_service_binding. Find the add method. We will make note of the URL,
HTTP Method, and Request Payload.

| 50 |
Step Action
12. To bind the service we will create the request above.
Open Postman and click on Reset. Enter the request URL of
http://ns2.training.lab/nitro/v1/config/ with the Content-Type header and
value of application/vnd.com.citrix.netscaler+json The data type will also be
set to raw and we will fill in the field with
{
"lbvserver_service_binding":
{
"name": "WWW",
"servicename": "WWW1"
}
}

Note: Here you might notice single quotes in the screenshot vs double quotes in the text
above. Double quotes are the JSON standard and should be used, but NITRO will still
accept single quotes as long are you are consistent. Although, you should really stick
to double quotes.

13. Challenge!
Add a service named WWW2 with IP Address 192.168.10.51, service type of http, and
port 80. Bind that newly created service to WWW.

| 51 |
Step Action
14. Test your newly created load balancing virtual server by opening Google Chrome and
heading to the URL http://192.168.10.32. You should be able to click refresh and see
that the service IP changed from 192.168.10.50 to 192.168.10.51 if you successfully
completed the challenge above.

15. Now we will delete the load balancing virtual server that we just created.
We will open the NITRO API Docs and head to Configuration -> Load Balancing ->
lbvserver. We will find the delete method. Make note of the URL and HTTP Method.

| 52 |
Step Action
16. Open up Postman and click Reset.
Enter the request URL of
http://ns2.training.lab/nitro/v1/config/lbvserver/WWW and HTTP Method of
DELETE. Set the Accept header to
application/vnd.com.citrix.netscaler+json

17. Click Send and notice that the Status is a 200 OK, meaning that the virtual server has
been deleted.

Exercise Summary
In this exercise, you utilized the add, update, and delete functionality of the NITRO API. We first
went through and enabled a NetScaler feature. Then we added a load balancing virtual server,
followed by adding a few services. We bound those services to the load balancing virtual server
and tested the server. We finally deleted the virtual server that we just created.

| 53 |
Exercise 5: Enable Interceptor
Overview
In this exercise, you will enable the Postman Interceptor Google Chrome extension. The
interceptor extension allows you to track and intercept all RESTful communication that occurs
between your browser (Google Chrome) and the server, in our case NITRO and the NetScaler.
In this exercise you will:

 Enable Postman Interceptor.

Step by step guidance


Estimated time to complete this exercise: 2 minutes.

Step Action
1. We are going to enable Postman Interceptor to capture our next exercise to review later. To do so,
open a Google Chrome browser window and click on the stoplight at the top right corner of the
browser. Turn the Request Capture on by clicking the button and turning the switch ON

Exercise Summary
In this exercise, you enabled Postman Interceptor to capture all RESTful browser communication.
We will review this data in a future exercise. This quick exercise might feel a bit out of place, but
you will see why we did it here in an upcoming exercise.

| 54 |
Exercise 6: NITRO Web Client
Overview
In this exercise, you will learn about and utilize the built in NITRO web client.
In this exercise you will:

 Add a load balancing virtual server using the NITRO web client.

 Bind services to the newly created virtual server using the NITRO web client.

 Delete a load balancing virtual server using the NITRO web client.

Step by step guidance


Estimated time to complete this exercise: 20 minutes.

Step Action
1. To get to the NITRO web client first open the NS2 bookmark within Google Chrome.
Login using the username nsroot and password nsroot. Click on the
Documentation tab at the top right and select NITRO Client.

| 55 |
Step Action
2. We are going to create the same load balancing virtual server that we created in
exercise four. Begin by heading to Configuration -> Load balancing -> lbvserver.
Select an add operation. Specify the following attributes
Name: WWW
Servicetype: HTTP
Ipv46: 192.168.10.32
Port: 80
Click on GO.

3. Verify that the virtual server was created by acknowledging the same HTTP status of
201 created you saw in exercise 4.

| 56 |
Step Action
4. Next we will specify a load balancing virtual server service binding.
Expand Configuration -> Load Balancing -> lbvserver_service_binding.
Select the add operation. Specify the following attributes:
Name: WWW
Servicename: WWW1
Click GO.

5. Verify that the service was bound to the virtual server by checking for a 200 OK HTTP
status.

| 57 |
Step Action
6. Test that your newly created virtual server works by heading to http://192.168.10.32 in
Google Chrome.

7. Delete the load balancing virtual server by heading to Configuration -> Load
Balancing -> lbvserver.
Select the delete operation. Specify the resource name of WWW. Click GO.

| 58 |
Step Action
8. Verify that the resource was deleted by receiving a 200 OK HTTP Status.

Exercise Summary
In this exercise, you created a load balancing virtual server, bound a service, and deleted that
virtual server using the built in NITRO web client.

| 59 |
Exercise 7: Interceptor
Overview
In this exercise, work with Postman interceptor to capture NITRO configurations and replay them
back to the NetScaler.
In this exercise you will:

 View the HTTP methods that were called from the NITRO web client.

 Edit a configuration on the NetScaler using the Web GUI and view the captured method via
Postman Interceptor.

Step by step guidance


Estimated time to complete this exercise: 5 minutes.

Step Action
1. Open Postman and click on the History tab.

Here you can see that Postman interceptor captured the NITRO requests that we sent the
NetScaler via the previous exercise and posted them into our history. We could edit these
requests and send them back to the NetScaler via Postman to perform the same or similar
configurations.
In the example above we successfully captured the configuration of the load balancing
virtual server creation.

| 60 |
Step Action
2. Now we will use the standard NetScaler GUI and capture a configuration into Postman.
Open the NS2 bookmark in Google Chrome and login using the credentials username
nsroot and password nsroot.
Head to the configuration tab.
Open Traffic Configuration -> Load Balancing -> Virtual Servers.

Note: You may need to close and reopen Google Chrome to reset our session into the
NetScaler if you see login issues.

3. Click Add.

| 61 |
Step Action
4. Enter the name WWW and IP address of 192.168.10.32. Click Continue.

5. Click on No LBVServer to Service Binding.

6. Click Bind.

| 62 |
Step Action
7. Select WWW1 and WWW2 and click Insert.

8. Click Save.

9. Click Continue.

| 63 |
Step Action
10. Open Postman and scroll through your history. You will see three POST methods.
Here we see the GUI sending a NITRO request to NetScaler creating the load balancing
virtual server as well as two service binding operations. These are the same requests we
have been doing through this lab!

Note: If you do not see these methods double check that Postman Interceptor is enabled
by performing exercise 5. Delete the WWW virtual server and try this exercise again.

Exercise Summary
In this exercise, you saw how you can use postman and postman interceptor to capture your
NITRO requests to the NetScaler appliance via both the NITRO web client and the NetScaler GUI.

| 64 |
Exercise 8: Advanced NITRO
Automation via Python
Overview
In this exercise, you will use a prescripted python environment to utilize the NITRO Python SDK to
configure NS1.
In this exercise you will:

 Configure NS1 using a python script. This script will configure load balancing virtual
servers, services, bindings, and features of the NetScaler automatically. It will finally print
out statistics of the environment.

 Challenge you to create a script to print out statistics of the environment.

Step by step guidance


Estimated time to complete this exercise: 15 minutes.

Step Action
1. To begin, open putty.

| 65 |
Step Action
2. Connect to TOOLS1 by clicking on TOOLS1, hitting Load, and clicking Open.

3. Login using the password: Password1.

4. Execute the script to automate the configuration of NS1 by running the command
python ns1conf.py

| 66 |
Step Action
5. The script executes to configure the NetScaler.

6. Verify the load balancing virtual server has been created by heading to
http://192.168.10.22 in Google Chrome.

7. You can view the contents of the python script if you wish by typing the command:
more ns1conf.py

| 67 |
Step Action
8. The next steps I challenge you to create your own python script to output the total hits
and hit rate of the lbvserver WWW.
You will need to create this code on the tools server that you are already connected to.
This is pretty much already done for you, you just need to edit the previous script. Let’s
copy the script by running the command cp ns1conf.py ns1monitor.py and edit it by
running nano ns1monitor.py Edit this by removing all unnecessary elements to
configure the netscaler, leaving the monitoring section. Exit by running CTRL+X and run
the script by running python ns1monitor.py If all went correctly you should have a script
that only shows the hits and hit rate of the WWW lbvserver. If you wish you can use the
python API documentation and experiment with your own scripts.
You will want to utilize the python API documentation hosted on the NetScaler. Typically
you would access this API documentation by logging in to the NetScaler and going to the
Downloads tab, but there has been a substantial update to the documentation since
creation of the lab environment and I recommend you download it from this link:
https://citrix.sharefile.com/d-s84ddde5420144678
From there, you will need to extract the few layers of files, and head to the nitro-python-
1.0/doc/html/index.html page. Here I went to config -> lb -> lbvserver and you are able to
see the class methods of each element.

Good luck!

| 68 |
Exercise Summary
In this exercise, you ran the automation configuration script for NS1 and possibly created your own
script to monitor the lbvserver.

| 69 |
Revision: Change Description Updated By Date
1.0 Original Version Brian Tannous May 2015

About Citrix
Citrix (NASDAQ:CTXS) is a cloud company that enables mobile workstyles—empowering people to
work and collaborate from anywhere, securely accessing apps and data on any of the latest
devices, as easily as they would in their own office. Citrix solutions help IT and service providers
build clouds, leveraging virtualization and networking technologies to deliver high-performance,
elastic and cost-effective cloud services. With market-leading cloud solutions for mobility, desktop
virtualization, networking, cloud platforms, collaboration and data sharing, Citrix helps organizations
of all sizes achieve the speed and agility necessary to succeed in a mobile and dynamic world.
Citrix products are in use at more than 330,000 organizations and by over 100 million users
globally. Annual revenue in 2012 was $2.59 billion. Learn more at www.citrix.com.

| 70 |

Vous aimerez peut-être aussi