PowerShell for Action Based Extensibility (ABX) in vRealize Automation 8

In addition to Python and NodeJS, vRealize Automation 8 also supports PowerShell as a scripting language for writing Action Based Extensibility (ABX). This will allow administrators who have already knowledge of PowerShell as a scripting language to use their skills to quickly develop automation for the lifecycle of their Deployments.

Here, in this post I will demonstrate how we can use PowerShell for Action Based Extensibility. To perform this complete task, we will follow the below steps.

1. Create a PowerShell Action

2. Create a Subscription

3. Create/Update your blueprint to use this PowerShellABX action.

1. Create a PowerShell Action

Login to vRA portal and go to Cloud Assembly > Extensibility > Library > Actions and click on +NEW ACTIONOn the New Action wizard, fill the Name and select Project and click Next


Select PowerShell in script language and write the code & in the right-hand pane choose On Prem in PaaS provider and delete all default entries & Save.

PowerShell code below takes a custom property from the Blueprint and uses it to rename the Virtual Machine before deployment.

function handler ($context, $payload) {

$oldVMName = $payload.resourceNames[0]

$newVMName = $payload.customProperties.userDefinedName

$returnObj = [PSCustomObject]@{

resourceNames = $payload.resourceNames

}

$returnObj.resourceNames[0] = $newVMName

Write-Host “Setting machine name from $($oldVMName) to $($newVMName)”

return $returnObj

}

Writing an ABX action in PowerShell is the same as with Python or NodeJS – we define a main handler function that receives a context and payload object. Context contains details of the execution of the action, while payload gives details about the deployment and event. The payload is a PSCustomObject whose properties match the event that is being subscribed to.

2. Create a Subscription

To create the subscription, navigate to Cloud Assemble > Extensibility > Subscription and +NEW SUBSCRIPTION

Fill all the details like, Name, Description, in the Event Topic click on +ADD and select Compute Allocation, toggle switch Condition and put the filter event as blueprint ID. In the Action/workflow click +ADD and select the Action created in earlier step “PowerShell ABX”, enable Blocking & in Subscription scope either choose Any Project or select a project from +ADD PROJECT and click Save.

3. Create/Update your blueprint to use this PowerShellABX action.

To create a blueprint, navigate to Cloud Assembly > Design > Select Blank canvas from NEW FROM tab in Cloud Template (Blueprint) and add below lines in your blueprint code.

Test your blueprint and deploy a vm to verify. When deploy a vm we can see option to give VM Name, give it a name and click on DEPLOY.

In the Deployment we can see the vm has renamed as RenameVM

Also in the vCenter we can see a vm name RenameVM deployed.

I hope you enjoyed reading this post as much as I enjoy writing it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.