How to configure Auto-Scaling for Private Cloud

Purpose:

Have you checked the auto-scaling feature provided in public cloud solutions like AWS and Azure and wished to get the same feature in your private cloud environment? Do you have an existing private cloud environment or building a new one and want to make it auto-scale enabled? This post covers this exact topic. It details what auto-scaling is and provides step by step guide on how you can build one using various VMware products.

Introduction:

In recent months, during my interactions with customers, one requirement came up pretty often than others. That is of auto-scaling. Seems majority of customers who deploy Private Cloud require auto-scaling in some or other formats. Since out of the box vRealize Automation provides "Scale-Out" and "Scale-In" functions (albeit manual), these can be used in conjunction with other products to provide auto-scaling functionality. I had to configure this feature for multiple customers, so thought of writing a blog post detailing the steps. Readers can follow the blog to do it themselves. Also, auto-scaling is very dynamic in nature. Typically auto-scaling parameter requirement changes from environment to environment. Keeping that mind I have explained the steps involved so that you can customize it as per your need.

Required prior knowledge:

Though you can simply import the package in vRealize Orchestrator and follow the guide to configure other products, having a knowledge of the following will help you further configure it.

  • Working knowledge of vRealize Orchestrator
  • If you want to customize the workflows, then you need to know a bit of JavaScript
  • For configuration of Webhook Shims, basic knowledge of Linux will help (though not strictly required, John Dias did an amazing job providing step by step guide).
  • Familiarity with vRealize Operations Manager will help
  • Working knowledge of vRealize Automation is required
  • If you want to replicate my example of multi-tier application with application installation at runtime. Then you need to know NSX usage and advanced configuration of blueprints in vRealize Automation.

If you are using vRealize Automation 7.2 and prior then this blog post on NSX integration with vRA will help. Integration method has changed in 7.3 and it is simplified a lot. Check the VMware documentation on how it is done in vRA 7.3.

On how to configure Software components you can check my earlier blog post here.

Acknowledgement:

Before I start writing this blog I need to say thanks to few people. Though I demonstrated this feature (with PowerCLI and vCenter) 2 years back to a customer, it was never a true auto-scaling solution. So, here it goes:

  • First and loudest thanks to Carsten Schaefer for com.vmware.pso.cemea.autoscaling package. It had the main "Scale Up Blueprint Layer based on VM MOID" and "Scale Down Blueprint Layer based on VM MOID". All my other works are based on these two core workflows. These two workflows do the actual task. So thanks a lot mate for your hard work and help.
  • Thanks to Vishal Jain, Diwan Chandrabose, Ajay Kalla and team for the Load balancer handling script. Normally when an alert is fired, it is based on a VM. But when network load comes from Load-Balancer and it fires an alert, we get the load balancer name. The script co-relating the load balancer to the corresponding virtual machine is written by the team. They showed how we can use NSX and vROps integration to handle load balancer parameters. Thanks a lot guys for this.
  • Last but not least Vinith Menon, I was wondering how I would put a load on the test website. I was thinking of using JMeter. But it was too much to just put HTTP requests on a web page. Your one liner is absolutely fantastic and time saver for me. Thanks a lot brother for that.

My friend Vinith Menon also have written a blog post on auto-scaling. You can check it here.

Where to get the package for auto-scaling?

I have created a single vRealize Orchestrator package containing all the workflows, SNMP Policy and Action items. Download the package from the GitHub repository (https://github.com/sajaldebnath/auto-scaling-vra) and import it into vRealize Orchestrator server. Rest of the details are provided in the rest of the blog post.

What is included in the package?

The following workflows are included in the package:

  • Scale Down Blueprint Layer based on VM MOID
  • Scale Up Blueprint Layer based on VM MOID
  • Scale Down vRA Deployment based on LB Load - SNMP
  • Scale Up vRA Deployment based on LB Load - SNMP
  • Scale Down vRA Deployment based on CPU-Mem Load - vROps REST Notification
  • Scale Up vRA Deployment based on CPU-Mem Load - vROps REST Notification
  • Scale Down vRA Deployment based on LB Load - vROps REST Notification
  • Scale Up vRA Deployment based on LB Load - vROps REST Notification

The helper workflows are:

  • Count VMs in Layer
  • Get VM Name from vROps REST Notification
  • JSON Invoke a REST operation
  • Submit to vRA

The action items are:

  • getCatalogResourceForIaasVmEntity
  • findObjectById
  • getVirtualMachineProperties

The included SNMP policy is:

  • vROps SNMP Trap for NSX

Note, the first two workflows are core workflows (written by Carsten) all other workflows depends on these two to get the work done. If you are not using Webhook Shims, then you do not need to configure workflows which ends with "vROps REST Notification". Also, for SNMP, you do not need to configure "Get VM Name from vROps REST Notification" and "JSON Invoke a REST operation" workflows. Alternately, if you are not going to use SNMP traps, then you do not need to configure the SNMP policy.

Pre-Requisites:

Before you can run everything you need to have the environment ready. I used the following versions:

  • vRealize Automation 7.3
  • vCenter & vSphere 6.5
  • vRealize Operations 6.5
  • vRealize Orchestrator 7.3 (internal to vRA)
  • NSX 6.3
  • Webhook Shims

The workflows should work with other versions as well. You need to have these products installed, configured and integrated to follow the example end to end.

UPDATE::

How to handle the SNMP trap data?

My friend Senthil asked me to provide the SNMP trap handling script as well. So provided below is the script which I used to Handle the SNMP trap data. If you are using the SNMP method for monitoring the traps, then use the following script to handle the on trap tasks and fire the respective workflow.

// Handling SNMP Trap
System.log("SNMP Trap Received");
System.log("Agent: " + event.getValue("agent"));
var key = event.getValue("key");
var snmpResult = SnmpService.retrievePolicyData(key);
// Get data as Array of Properties
var result = System.getModule("com.vmware.library.snmp").processSnmpResult(snmpResult);
​
 //System.log("Enterprise: " + snmpResult.enterprise);
// Log data
System.getModule("com.vmware.library.snmp").logResult(result);
var dataMatch = 1
var lb = 0
// Setting the workflow ID's
var wfIdCpuDown = "2e8e822b-f919-4453-97e8-ce5dacd816f4";
var wfIdCpuHigh = "14d602b6-e1ff-4d15-83af-4f9a97928940";
var wfIdLbDown = "7daf80e6-852a-4a10-a3df-5d54b182f5b0";
var wfIdLbHigh = "db9fdd03-1c11-4305-9d22-3536c3374971";
// Processing the trap data. Element 19 has the alert name
// So checking the presence of particular Alert Name
// Element 4 has the Object name which fired the alert. So if the corrent alert is present then
// getting the object name from Element 4
if ( result[18].get("value") == "VM vCPU Usage High - Sajal"){
​ System.log("Trap Found::"+result[18].get("value"));
​ var vmName = result[3].get("value");
​ System.log("VM Name : " + vmName);
​ var wfId = wfIdCpuHigh;
}
else if ( result[18].get("value") == "VM vCPU Usage Down - Sajal"){
​ System.log("Trap Found::"+result[18].get("value"));
​ var vmName = result[3].get("value");
​ System.log("VM Name : " + vmName);
​ var wfId = wfIdCpuDown;
}
else if ( result[18].get("value") == "LB Load High - Sajal"){
​ System.log("Trap Found::"+result[18].get("value"));
​ var lbName = result[3].get("value");
​ var endIndex = lbName.indexOf(" Load Balancer");
​ var vmName = lbName.substring(0, parseInt(endIndex));
​ lb = 1
// System.log("LB Name : " + vmName+ " Var lb value:"+lb);
​ var wfId = wfIdLbHigh;
}
else if ( result[18].get("value") == "LB Load Down - Sajal"){
​ System.log("Trap Found::"+result[18].get("value"));
​ var lbName = result[3].get("value");
​ var endIndex = lbName.indexOf(" Load Balancer");
​ var vmName = lbName.substring(0, parseInt(endIndex));
​ lb = 1
// System.log("LB Name : " + vmName+ " Var lb value:"+lb);
​ var wfId = wfIdLbDown;
}
else {
​ System.log("No data match");
​ dataMatch = 0
}
// If the actual alert is found then getting the Moref of the Object in vCenter and calling the workflow
if ( dataMatch == 1) {
 if ( lb == 1) {
 var vmMoref = vmName // System.log("Calling out workflow for LB: "+ vmMoref);
 // runWF(wfId,vmMoref);
 }
 else {
 var vm = findVms(vmName);
 System.log("The VM is:"+ vm);
 if(vm instanceof VcVirtualMachine)
 {
 System.log("Sucessfully located the vm object" + vm.name);
 }
 var vmMoref = vm.id;
 System.log("VM MoRef is " + vmMoref );
 System.log("Calling out to workflow run function");
 }
 runWF(wfId,vmMoref);
 }
 // This function finds the Moref of the object in terms of vCenter server
function findVms(vmName){
 var vms = VcPlugin.getAllVirtualMachines();
 var vmResult = null;
​ for(var b=0; b < vms.length; b++ ){
​ if( vmName == vms[b].name){
​ vmResult = vms[b];
​ break;
​ }
​ }
​ return vmResult;
​ }
 // This function calls out the workflow
 function runWF(wfid, vmMoref)
 {
 var workflowToLaunch = Server.getWorkflowWithId(wfid);
 if (workflowToLaunch == null)
 {
 throw "Workflow not found";
​ }
​ var workflowParameters = new Properties();
​ if ( lb == 1) {
​ workflowParameters.put("lbName",vmMoref);
​ }
​ else {
​ workflowParameters.put("targetId",vmMoref);
​ }
 // System.log("Launching Workflow. Please refer to that workflow for specific logs."+ wfid+" :VM Info:"+vmMoref);
 var wfToken = workflowToLaunch.execute(workflowParameters);
 return wfToken;
 }

How to configure auto-scale?

Conclusion:

You can use the steps detailed in the video to configure auto-scaling in your environment. This is an amazing feature. It will be a real help if you can test it out and let me know the outcome. Also, any further suggestions are welcome. I hope this helps you as it helped me. Do provide me feedbacks on this. Also, let me know if I missed something or you need further clarification.