AutoScale your Deployments in vRA with PowerVRA and PowerShell

AutoScale your Deployments in vRA with PowerVRA and PowerShell

AutoScale your Deployments in vRA with PowerVRA and PowerShell

Hello Folks!, Today i wanted to share with you something amazing i was able to get done using PowervRA and vRealize Automation 7.3.

If you have not used it before i would like to tell you its a Gem of a technology built by two amazing gentlemen and PowerShell MVP’s – Jon and Craig , Thanks Guys! for making this and thanks for the all support you extend to integrate PowerVRA with the upcoming releases of vRealize Automation.

This module allows you to automate almost anything in vRA by accessing its Rest API’s.

The module has about 117 cmdlets as of now (PowervRA 2.2.0) which allow you to do this.

Well moving on, you might have noticed i have been hooked onto exploring API’s for vRA with vRO and that did involve me going deep into Java Scripting and lots of learning! to upgrade my skillset as i am basically a PowerShell guy ๐Ÿ™‚ .

Based on the learning posted a series of Blogs on how to invoke AutoScale action’s for a deployment resource in vRA in an automated way, if you have not looked at it till now, please have a look at the set of links posted here which showcase this.

Auto-Scale vRA workloads with vROPS,vRO and NSX

AutoScale vSphere Workloads with vRA and PowerShell based NetScaler NITRO APIโ€™s

VMware WebHook Shim and AutoScale with vRO

Ok so the question which i asked myself is why dont’t i used my existing skills and try to build a solution using PowerShell itself, i tried invoking the REST API’s for vRA but that was a lot of research and to save time i used PowervRA to build this solution.

The solution i built for Scale-Out and Scale-In with PowerShell fully utilizes the cmd’s present in PowerVRA module and a bit of trickery too ๐Ÿ˜‰ to get the data in the right format, you would see this as you read on.

Ok, so let me start with the AutoScale Action

I would be walking you through the script step by step and also give a link to the entire script too – so you can just copy paste it into your Code / ISE environment, make necessary modifications and re-use it.

First connect to your vRA environment with PowerVRA using the below command

Next lets extract the REST API call to get the Parent Resource of the destination machine which needs an auto scale out due to the increase load, we would be extracting the Parent Resources ID.

Once we extract the Parent Resource ID, lets extract the list of Resource Actions which can be performed on this deployment.

As you can see below we get a list of all actions which can be performed on the Parent Deployment

Here in our example ๐Ÿ™‚ , we are interested in the Scale-Out Action, so lets extract the resource ID for the same.

Ok great!, so now that we have the Scale Out ID, lets have a look at how this Resource Action Template for Scaleout looks like, as this is the same format vRA expects to invoke the scale out operations.

Great!, so we have all the details now, ok so in this example we are specifically scaling out the Web-Tier so i would do a bit of data manipulation to clear out the Data format for App and DB Tier as this is something which does not need a scale-out currently, also along with this we need the cluster size to be incremented by 1 so that we get a new Web-Server in the Web-Tier.

Voila!, as you can see now i have the cluster node count for Web-Tier increased to 4 hence we would get a new web-server

Ok so now we have the data in the proper format, lets invoke the rest call to Request a vRA resource action as below. Also as you can see below, i gave a sleep for just 3 seconds so that the request ID is picked up by Get-vRARequest and i placed a while loop so that we wait for the successful completion of the request.

As you can see below the request has been submitted and we are waiting for it to complete.

Now if i login to my vRA portal we would see that yes!! the Scale-Out Request is indeed in progress

Amazing! isn’t it ๐Ÿ™‚

We would wait now for the Request to complete, once its successful – lets say you want the name of the newly provisioned VM. what if you want to do some day-2 tasks on it lets say update the details in a CMDB etc.

The vRA view

Now what we would do is again head over to the parent resource, then Invoke the vRA REST method to get the child objects, extract only what is required lets say Web-Tier, sort it in a descending order to extract the name of the newly created VM !!

And as you can see the VM Name Matches the above screenshot!

Woah!! now that was one of the most exciting post i have written so far!, and it had been a long dream to do this with PowerShell!

Ok so now for the Scale In Part it Remains the same, the only change we make is to get the Resource ID for the Scale-IN action and along with this reduce the cluster count by 1.

Here’s a screenshot from the execution view

If i login to the vRA portal, i can see now the Scale-IN request is in progress.

Wow!, so now you can see the True Power of Automation, if you have access to the REST API’s almost anything is possible, Just imagine if its not only Scale action you can perform on a deployment, it can be used to invoke any resource action which the deployment provides.

Well now if you want to automate it with vRO and vROPS , you can have a look at some of my previous posts on how to invoke these scripts via Web-Hook Shims

I Hope You Enjoyed this blogpost and found the information useful.

Here is the Link to the PowerShell Script in its Raw Format

Please follow and like us:

Share this post

Post Comment