Jump to content
Welcome to our new Citrix community!
  • StyleBook automation using NetScaler Console's NITRO API: A SysAdmin primer

    Steven Wright
    • Validation Status: Validated
      Assigned To: Steven Wright
      Has Video?: No

    In this two-part blog series, I describe how to rapidly create services on your NetScaler's using Citrix Application Delivery Management (ADM) StyleBook automation to accelerate migrations. In the example, we create 300 load balancers across an estate of several NetScaler's within 15 minutes.

    My first post was aimed at DevOps. In this post, I target Sysadmin employees and focus on a pre-prepared script that I wrote. The script helps you to achieve our goal of rapidly creating load balancing virtual servers.

    You can download the script and its two supporting files here.

    Note: The script requires Python 3 and jinja2, that you can install with pip using the command

    pip install jinja2

    Prepare the StyleBook template("template.txt")

    The first of the script's two supporting files is named template.txt.

    The template.txt file is already preprepared for the simple HTTP load balancers that we create in this post, and you don't need to modify it. However, I do want to explain how you can make those modifications, in case you want to target other StyleBooks or introduce extra parameters.

    On the second line of the template.txt, you can find the namespace, version, and the name of the targeted StyleBook.


    If you want to change the template file's target, you can view the namespace, version, and the name of another StyleBook within Citrix ADM's web interface.




    On lines five to 12 of the template.txt, you can find placeholder names that correspond to the columns in a CSV file called lbvserver.csv, which is also included with the script.

    CSV columns

    svcservers: list

    As you can see from the placeholder named svcservers: list, if the columns in the CSV file contain a list of items, such as a list of back-end servers for a load balancing virtual servers, we note this by appending ": list" to the placeholder's name.

    You can find a template with each value that our script must submit to the StyleBook at line 14. Each item in the template matches one of the placeholder values you created earlier, and the template includes a loop where it encounters a list.


            "targets": [{"id": "<<targetadc>>"}],
                    "lb-appname": "<<name>>",
                    "lb-virtual-ip": "<<lbvirtualip>>",
                    "lb-virtual-port": "<<lbvirtualport>>",
                    "lb-service-type": "<<lbservicetype>>",
                    "svc-service-type": "<<svcservicetype>>",
                    "svc-servers": [
                        <% for server in svcservers %>
                            "port": << svcserverport >>,
                            "ip": "<< server >>",
                            "add-server": true
                        <% endfor %>

    Again, you need to edit the template file only you're modifying the script to target an alternative StyleBook or you're introducing extra parameters.

    Preparing the script

    As we saw in Part 1, you need an ID and secret to allow the script to log in into your Citrix ADM environment. If you're using the Citrix ADM service, you can create the ID and secret by doing the following steps:

    1. Sign in to the Citrix Cloud portal.
    2. Select Identity and Access Management from the menu.
    3. Select the API Access tab.
    4. Name your Secure Client, and click Create Client.




    After you have the ID and secret, replace the placeholder example values within the create2.py python script.

    # Set my login variables for ADM
    # You can create an ID and secret by selecting the Identity and Access Management tab in your Cloud portal
    Id = "1707d2ff-e200-46be-848a-93faf2076d6b"
    Secret = "DIH1CzF_GSZG2zNnEVShLA=="`

    Preparing the Excel CSV template

    Now that you've set the ID and secret values, you can run the script with the "-a" parameter to display a list of NetScaler's and their identifiers.


    python create2.py -a


    The following NetScaler instances IDs can be referenced within your CSV file.
    Name - IP address - ID for use in CSV.
    1\. bob - - a0de40bb-e186-44bb-871b-d60f112b0a3a

    Here, we can observe that I have an NetScaler with the host name "bob" on IP address "" with the unique identifier "a0de40bb-e186-44bb-871b-d60f112b0a3a." You must note each identifier because we need them later.


    Prepare a list of load balancing virtual server ("lbvserver.csv")

    The second of the script's two supporting files is named lbvserver.csv.

    Each row in the lbvserver.csv file includes the properties for a single StyleBook, in this case, the properties for a single HTTP Load Balancing virtual servers.

    Each column in the lbvserver.csv file is the source for the placeholders within the template.txt file. The columns and placeholders are in the same order, with the first column being the first placeholder and so on.

    I have expanded the lbvserver.csv file to contain 300 rows (300 HTTP Load Balancing virtual servers) for this post. If my customer had a similar requirement, I would likely populate an initial CSV with all the expected values. Then, they would forward the CSV internally to ensure that the names, naming conventions, and IP addresses were all as desired.

    As you can observe by comparing the columns to the template.txt file, column A specifies the unique identifier of the NetScaler that we target, and columns B to H are the input parameters for the StyleBook. You can include lists in the parameters with ":" used as a separator.

    After modifying the lbvserver.csv file to reflect the virtual servers that you want to create, you must save in "CSV" rather than "CSV (UTF8)" format.




    Running the script (python create2.py)

    Having populated the script with an ID and secret that allow access to your Citrix ADM environment and updated the columns to reflect which NetScaler you want to build on and the properties, we are now ready to create our load balancing virtual servers.

    We can now run the script and create a Citrix ADM config pack along with the resultant NetScaler configuration.


    python create2.py

    Output (shortened)

    Creating ADM Config Pack based on CSV row: 1
    {"configpack": {"job_id": "1926702141"}}
    Creating ADM Config Pack based on CSV row: 2
    {"configpack": {"job_id": "2520889571"}}
    Creating ADM Config Pack based on CSV row: 3
    {"configpack": {"job_id": "2581540139"}}
    Creating ADM Config Pack based on CSV row: 4
    {"configpack": {"job_id": "1440135035"}}
    Creating ADM Config Pack based on CSV row: 5
    {"configpack": {"job_id": "3264746514"}}

    The script takes around two to three seconds per row and completes the 300 rows in just under 15 minutes. After completion, the resultant Config Packs will be visible within ADM.


    Ongoing maintenance

    In addition to creating the virtual servers rapidly from a pre-agreed Excel CSV file, this script-based approach also allows management of the resultant virtual servers using ADM and future changes without a need to understand the underlying commands on their NetScaler's.

    You can view each of the resultant Config Packs by selecting Applications, Configuration, Config Packs from within the Citrix ADM web interface. By selecting Edit, you can then manage and update the Config Pack as your needs change.













    Next steps

    We have now created 300 load balancers across our estate using an adaptable template that allows you not only to create load balancers but any other StyleBook based configuration.

    If you want to understand how the script works, you can read through the first article in this series .

    User Feedback

    Recommended Comments

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Create New...