AutoScale vSphere Workloads with vRA and PowerShell based NetScaler NITRO API’s

AutoScale vSphere Workloads with vRA and PowerShell based NetScaler NITRO API’s

AutoScale vSphere Workloads with vRA and NetScaler NITRO API’s

Hello Folks – I hope all of you enjoyed our previous write-up in which we demonstrated how to

Auto-scale a vSphere deployment with NSX.

This blog post follows the similar setup Techniques so, please use the earlier blogpost as a reference.

Also note there was a recent change in the code for “Find All Childs” made by my good friend and VMware Colleague Sajal Debnath – Solution Architect and a vRA Scripting expert to get find the child objects, some times when the scaleout actions is invoked it scaled out to more number of vm’s as against the number of the vm’s requested. hence this code was updated.

Ok so lets talk about what we would be covering here.

We had a request from a customer recently who was using NetScaler for his load balancing and he wanted a similar solution for what we had achieved with NSX.

NetScaler exposes all of its REST API’s and all this automation can be attained with NITRO API’s.

If you want to learn more on how to get started with NetScaler you can go ahead and have a look at the below links.

The below YouTube upload highlights the load balancing process in detail – you can skip to 1:14 for more details.

Ok so how this solution was made possible is by accessing the REST API’s with PowerShell and performing the manual steps in an automated way.

The PowerShell module i used was an excellent creation done by Esther Barthel, “A huge shout out to her” which exposes all the REST API’s for Netscaler, you can download the module from the below link.

Ok so next lets move on and look at the cmdlets and the sequence in which the load balancer services need to be configured.

Connect to the NetScaler Appliance and store the session details in a variable.

Next add the server to the NetScaler console.

If you login to the GUI you can see the server added sucesfully.


Next we will add the services using below command.

We can see the service created in the GUI.

Once this is done, the final step is to attach this server to the virtual server.

In the GUI we can see this successfully done.

Ok, next lets map all this steps into a vRO Workflow.

For this the first step was to add a PowerShell Host and configure a workflow to invoke the PowerShell script which is basically a combination of the above mentioned commands to use NITRO API’s to create the lb entries.

Here are some of blogs which I did a long back which can help you to setup the environment to invoke the PowerShell scripts.

Below you can see the scriptable task which basically create’s the script args which if fed as an input to the PowerShell script, as you can see i feed in the vmname and its ipaddress as parameters which are required for the above mentioned Nitro cmdlets to function.

Once i had the workflow ready as above i attached it as an input to the AutoScale Workflow which i had detailed in my earlier blogpost, i had to make some changes in the workflow as the problem that i saw was that the AutoScale workflow did not get the name of the new vm created as a output parameter,

I am still trying to figure out how to get this from an internal property, hence to fix this as i had very less time i had to make the below modifications in the “Count VMs in Layer” workflow, create a duplicate of it so once the auto scale action is completed I again head over to the blueprint deployment and count the vms in it, put it in an array, next I iterate through the array and find the VM’s which match the name “Web-Tier” in it, hence now I again get an array of only web-servers, now I sort the array and slice out the last element from the array which is the newly created VM which would be now set as an output parameter for the AutoScale workflow as a whole :).

Also Note, vRA machine naming prefix always keeps incrementing  its values.



Also note lets say you want to scale out the App-Tier and DB-Tier and add it to the netscaler lb, as in most customer environments we have different naming conventions assigned to them you can put the above logic in an multiple switch case statement of or an if else condition which can be matched against the virtualMachine name which is base input to the auto-scale workflow and the all the vms from that layer can be found and we can now get the newly created vm name in either App / DB Tier too.

And below you can see now the modified workflow which give the scaleoutvm parameter as an input to the Net-Scaler-Config workflow.

Wow!! 🙂 , now that was a lot of amount of work, so now what would effectively happen is that each time the auto-scale workflow is triggered the new Web-Server created as a part of auto-scale would be automatically added to the netscaler load balancer.

After a few trial hit and run’s i was able to get this working as expected and saw the VM name which is incremented as a part of workflow gets fed in into the netscaler workflow and the records get created successfully.

Here is the SNMP alert for High CPU utilization as they show up in vRO Logs.

Here are the details on the workflow.

Here you can see a view from the NetScaler GUI front where we see the IP added.

Also note here we use CPU Usage % per virtual machine to define the Alert and Symptom in vROPS which triggers the SNMP trap which is internally used by vRO to launch the auto scale workflow

Below is the alert generated, For auto scale workflow , we are generating load using – tool for CPU and I saw the basic auto scaling works with this

Here’s the Symptom

Here’s the Alert Definition

And the SNMP notification setup for this alert

I hope you enjoyed this blogpost and found the information useful 🙂

Here’s a video which shows the Entire solution.

Attached the vRO Workflow package and NetScaler LB PowerShell Script for your reference which make this magic possible

If you found this information useful, also check out how to use Web-Hook Shim’s to enhance this solution.

VMware WebHook Shim and AutoScale with vRO

Please follow and like us:

Share this post

3 thoughts on “AutoScale vSphere Workloads with vRA and PowerShell based NetScaler NITRO API’s

Post Comment