How to utilize VRO PowerCli actions to make the VRA custom form dynamics for cluster, network and Folder in vRealize Automation 8

Recently I was working on used case where we need to make the custom form dynamics in VRA 8 . Dynamic custom forms ease the job because we do not need to hard code everything .

There are multiple ways to do this like you can use JavaScript which is being used in vro from long time

or

You can use Python and Utilize Rest API calls , Python support is added in VRA 8 design along with PowerCli.

I will be covering PowerCli language for the dynamic selection for Cluster, network and Folder

Now lets look at Yaml side configuration which is required

formatVersion: 1
inputs:
  newVMName:
    type: string
    title: NewVMName
  Cluster:
    type: string
    title: Enter Cluster
  Network:
    type: string
    title: NetworkPortGroup
  Application:
    type: string
    title: Choose Application
  Sub-Application:
    type: string
    title: Choose Sub-Application
resources:
  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      newVMName: '${input.newVMName}'
      abxaction: 'yes'
      image: VMwareCode-CentOS
      flavor: VMwareCode-small
      folderName: '${"VRM/" + (input.Application) + "/"+ (input.Sub-Application)}'
      constraints:
        - tag: '${input.Cluster}'
      networks:
        - network: '${resource.Cloud_vSphere_Network_1.id}'
  Cloud_vSphere_Network_1:
    type: Cloud.vSphere.Network
    properties:
      networkType: existing
      constraints:
        - tag: '${input.Network}'

As we see in highlighted row , I am taking input of 4 inputs which we will be using in custom form and I am using tags to force those values

To make the tagging work ,I have assigned same tag name as object l

Before I jump to VRO side. lets take a look how my Custom form looks like.

As you see I am getting drop down list for Enter Cluster field , To make this field Dynamic I have created VRO action and mapped to custom form.

Lets have a look PowerCli vro Action first ,Later we will see the mapping in custom form.
function Handler($context, $inputs) {
  $connection=Connect-VIServer -Server vcsa.vmwarecode.com -User administrator@vsphere.local -Password VMware123! -force
  $cluster=get-cluster|select name
  $clustername=@()
  $clustername = $cluster.name
  $as=disconnect-viserver -Server vcsa.vmwarecode.com -confirm:$False
  return $clustername
}

Either you can use the admin account or Service Account which has admin rights

Once we create action lets jump to custom form and Map the above created action .

In Custom form i chose drop down for dynamic list for Enter cluster field

In default value section I have given one of the cluster name and Value source I have set as External Source.
Since we have chosen string of array in vro and drop down in custom form , when you search for action name you will see it will reflect there

Note: com.vmwarecode/ is my Package name where I have saved all my actions, It will be different for you.

Now next task is chosen the Network Port Group based on Cluster name.

Lets have a look how does network portgroup looks like in Custom form

As you see in above screenshot , for NetworkPortGroup field the drop down is coming and those values are based on Cluster which we chose in last above step.

Lets take a look at VRO action for this one.

function Handler($context, $inputs) {
    $connection=Connect-VIServer -Server vcsa.vmwarecode.com -User administrator@vsphere.local -Password VMware123! -force
    $cluster= $inputs.clusterName
    $pg=Get-Cluster $cluster|get-vmhost|Get-VDSwitch|Get-VDPortgroup|select name 
    $pgname=$pg.name
    $as=disconnect-viserver -Server vcsa.vmwarecode.com -confirm:$false
    return $pg.name
    
}

As we see we are taking input for the clusterName then getting the Portgroup mapped to ESXi host which are mapped to cluster.

Once vro action is configured ,Lets have a look at Custom form settings.

As we see we are using external value for this field also and mapping the VRO action nameed getVirtualPortGroup
Also we are using Canvas field and mapping with Enter cluster field from canvas.

Now next task is choose the Folder name dynamically where VM will be provisioned .

Before we start coding for Folder , lets review the current architecture of Folders in vCenter.

As we can see in above screenshot , we have Main Folder Called VRM. Under that I have 2 Sub Folder called Dev and Prod

Under Dev I have 2 more sub folders called App-dev and AppTest
Under Prod I have 2 more sub folders called App-Prod and App-Test.

If we noticed we have same sub-folder named called App-Test in Dev and Prod Folder

Now lets have a look at folders in Custom form.

Once we select for Choose Application field, we will see child folders for above selected.

Lets look at VRO actions for both fields one by one.

Lets look at choose application vro action which is named as getParentFolder

function Handler($context, $inputs) {
    $connection=Connect-VIServer -Server vcsa.vmwarecode.com -User administrator@vmwarecode.com -Password VMware123! -force
    $foldername=Get-Folder|?{$_.Parent -match "VRM"}|select Name
    $connremoved=Disconnect-VIServer -Server *  -Confirm:$false
    return $foldername.name
}

Lets look at Choose Sub Application VRO action.

function Handler($context, $inputs) {
   $connection=Connect-VIServer -Server vcsa.vmwarecode -User administrator@vmwarecode.com -Password VMware123! -force
   $as=$inputs.parentFolder
   $folder=Get-Folder|?{$_.Parent -match $as}|select Name
   $connremove= Disconnect-viserver -server * -confirm:$False
   $foldername=@()
   $foldername=$folder.Name
   return $foldername
}

VRO actions are completed here , lets jump tp custom form for folder.

Here is the configuration for Sub-Application field.

Caution: As this is lab environment ,Here we are entering the Username and Password inside the action .
It may conflict with security concern of your organization if any
.

How to remove machine from VRA which are stuck in provisioning status in VRA 8

Past I have written article where I showed how to remove the deployment from VRA if those are stuck here .
Recently I have come across the situation where we do not have deployment but machines are stuck Under Machine TAB in VRA.

This is what we see below is expected

Here is the screenshot where you see stuck in provisioning



To remove those machines which are stuck ,We can utilize the api to force delete those machines.

Along with deleting the stuck machines you can use same module for multiple things like below and take reference .

  • How to login to VRA 8
  • How to list total deployment
  • How to delete the deployment
  • How to list the Blueprint
  • How to release the blueprint
  • How to list the machines in VRA
  • How to delete the machines



We are covering above How to delete the machine in this article , for rest of the steps are attached in my previous blog.

No need to worry about if you are not from python background or do not know code, Just follow the below instruction and we are good .



  1. Please follow the detailed instruction Here python installation and required module before we use this module –Do not skip this step.
  2. Download the file from Above and unzip and copy the file by name VRA8 and paste the file in directory where python is installed
    general path in windows is : C:\Users\Administrator\AppData\Local\Programs\Python\Python39
  3. I am using Python 3.9 for example ,It will be different as per your version.
  4. Once the step 1-3 is completed , all we need to do is run the below commands.

from VRA8 import vraClass
as1 =vraClass(vrafqdn="vra82.vmwarecode.com", username="administrator", password="VMware123!")
as1.getMachines()

Once we get the ID from above getmachines , we will run the deleteMachine to remove the stuck machine from VRA.

as1.deleteMachine(id='89af5f50-cb28-40ac-8734-d4dcc265fb8c')

Once we get the response 202 , Go to browser and refresh the browser you will see the VM is no longer in list ,Also we run the getMachines once again.

Happy Learning , Feel free to share your queries and feedback on this .

How to rename the VM during the Deployment in VRA/VRO7.6(vRealize Automation 7.x)

Often there are situations where we want to automate the name generation of the VMs and There are multiple ways to do that in VRA.

We can use Machine Prefix feature which is inbuilt in VRA . we can navigate to Portal by below
Infrastructure => Compute Resources => Machine Prefixes


Another way is to use the VRO , As we all know we can Integrate anything in VRO , all we need is plugin. Another used case we can do is to Integrate with naming server then pass the value to VRA for VM Name or if we want to specify on runtime.

Recently I was working on used case , where I want to provide the VM name at the time of submitting the request , that is what we are covering on this Post .

Here is my request/ Custom form look like.

Before start the VRO part lets complete the pre-requisite for VRA /VRO configuration .

  • Click on Blueprint and click on custom property tab and add the below properties as in the screenshot .
  • Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Requested value must be * .
  • VMNewName value must be blank .
  • Down the package from above and unzip the package .
  • Open VRO legacy Client .

Once VRO client is open , Change the view to Design and Import Package.

Choose the File which we download from above step.




Click open and Import the package certificate .

Select All files while importing.

  • Click Import selected elements
  • Once done we should be able to see the VMwareCode folder and Rename VM workflow.
  • Click on Rename VM workflow and click on edit
  • Click on Not SET for Host which is highlighted and choose the IAAS host from VRA plugin.
  • Click Select and Save and close and continue anyway — This step is required to get the value of VM and update the value
  • VRO configuration is done , Now lets configure the subscription in VRA.
  • To Configure the subscription login to vra and click on Administrator => Events => Subscription.
  • Click on New Subscription and choose the Machine Provisioning.
  • Click Next and Choose based on condition.
  • Click Next and Choose the workflow which we created in above step.
  • Click Next and choose the option for priority and blocking , Blocking means If workflow fails it will stop there and build will mark as failed.
  • Now Last step is left to create/edit the custom form for blueprint .
  • Go to the blueprint and click on custom form .
  • We will see the NewVMName field under the vSphere Machine section.




Once Done we are good to Test with provisioning
Note: I have choose HOST option also in my form which may not be available for you as this require separate configuration.

Here is the result of test provisioning.



How to delete deployment in VRA 8 using Python(API)

Often there are situation where deployment will get stuck in progress or We lost control to manage the deployment using GUI. In those situation we can utilize the APIs and get the task done.

But for VRA8 taking the bearer token is bit tedious task as we need to obtain 2 different token then make it as bearer token. To make it easier I have created Python Module where you just need to provide the Admin credentials and perform the operation .

To start the Process we need to meet the pre-requisites which are explain in below steps.

No need to worry about if you are not from python background or do not know code, Just follow the below instruction and we are good .

  1. Please follow the detailed instruction Here python installation and required module before we use this module –Do not skip this step.
  2. Download the file from Above and unzip and copy the file by name VRA8 and paste the file in directory where python is installed
    general path in windows is : C:\Users\Administrator\AppData\Local\Programs\Python\Python39
  3. I am using Python 3.9 for example ,It will be different as per your version.
  4. Once the step 1-3 is completed , all we need to do is run the below commands.
from VRA8 import vraClass
as1 =vraClass(vrafqdn="vra82.vmwarecode.com", username="administrator", password="VMware123!")
as1.getDeployments()

as1.getDeployments() -By Default this will list the 10000 deployment , We need to get the deployment ID from the list.

As we see , I have total 22 deployment in my environment and Now I will trigger the delete deployment request for deployment name Test11 for that ID is -6130ead4-638f-4050-ae7d-9279ee51ffa8.

as1.deleteDeployment(id="6130ead4-638f-4050-ae7d-9279ee51ffa8")


Here response 202 means API has been triggered to delete . Now if we do getDeployment() again we only see 21 entries.


There are some additional function also which are part of this python module
Like getBlueprint() & releaseBlueprint()

Here is the quick look of both of them

as1.getBlueprint()
as1.releaseBlueprint(id="cf9641b4-0242-4555-abae-26d8b72f542d", version=11)




Happy Learning , Feel free to share your queries and feedback on this .