VRA Cloud/8- How to provide CPU, Memory and Storage utilisation details of cluster during vm provisioning using vRO Powercli action.

This is one of the Interesting use i have come across ,so i decided to blog it .let’s see what is this used case about …
Used case:
As VRA provides self service portal which comes via Service Broker. End User wanted to have catalog item which shows CPU , Memory and Storage consumption of clusters in form before they submit the vm provisioning request.
Also It should show how many ESXi are connected and How many ESXi are in Maintenance Mode .

There are multiple ways to get this information like , we can make rest API to vRops which provides above metrics or We can use vSphere API or third party tools available in market which collects these data. I have taken route of PowerCli since I have used this in past ,It is easy for me to get the data in desire format .

Let’s see How end result will look like in below screenshot.

To Implement this I have designed my VRA Cloud environment like below.
Lab Environment :

As we can see above we have 3 Clusters in vSphere , for each Cluster we have Cloud Zone in VRA . For each cluster we have Datastore Cluster/Datastore and VDS Port Group which is represented by storage profile and Network profile in vra.

Example: I have 3 Clusters in vCenter by name below .

Each Cluster is mapped to Cloud Zone in VRA as below:

Now Lets take a look at Cloud Template of VRA.

formatVersion: 1
    type: string
    description: Choose Cluster
    type: Cloud.vSphere.Machine
      image: Linux
      flavor: Small
        - tag: '${input.Cluster == "vRA_Payload1" ? "vCenter115:vRA_Payload1" : input.Cluster == "vRA_Payload2" ? "vCenter115:vRA_Payload2" : input.Cluster == "vRA_Payload3" ? "vCenter115:vRA_Payload3" : ""}'
        - network: ${resource.Cloud_vSphere_Network_1.id}
    type: Cloud.vSphere.Network
      networkType: existing

It is very simple template , only point to note is Line number 13 which is doing condition check for us. Post this i have release the released the template. I would assume releasing the Cloud template is known to everyone.
Note: I have not set the network or storage constraint , It is not mandate but can be set in same fashion we did for Cloud Zone.
Now before we jump to Custom form configuration ,lets develop the vRO action which would provide us below details.

vRO Action:

  • PowerCli action to get the list of cluster
  • PowerCli action to get cluster utilisation of given cluster.
  • PowerCli action to get ESXi utilisation of cluster.
  • PowerCli action to get datastore utilisation of cluster.

    Here is the code snippet of List of Cluster.
function Handler($context, $inputs) {
  $connection=Connect-VIServer -Server $inputs.vCenterName -User $inputs.vCenterUserName -Password $inputs.vCenterPassword -force
  $cluster=get-cluster|select name
  $clustername = $cluster.name
  $as=disconnect-viserver -Server $inputs.vCenterName -confirm:$False
  return $clustername

Here is the code snippet of Cluster utlisation.

function Handler($context, $inputs) {
    $connection=Connect-VIServer -server $inputs.vCenterName -user $inputs.vCenterUsername -password $inputs.vCenterPassword -force
    $esxi = get-cluster $inputs.ClusterName|Get-VMHost
    $datastore = Get-Cluster $inputs.ClusterName|Get-Datastore|?{$_.Type -eq 'VMFS' -and $_.Extensiondata.Summary.MultipleHostAccess}
    $Cluster_Utilization = [System.Collections.Specialized.OrderedDictionary]::new()
    $Cluster_Utilization['Total Memory in GB'] = [math]::round(($esxi.MemoryTotalGB|Measure-Object -Sum|select -Property Sum).sum)
    $Cluster_Utilization['Used Memory in GB'] = [math]::round(($esxi.MemoryUsageGB|Measure-Object -Sum|select -Property Sum).sum)
    $Cluster_Utilization['Total Storage in GB'] = [math]::round(($datastore.CapacityGB|Measure-Object -Sum|select -Property Sum).sum)
    $Cluster_Utilization['Available Free Storage in GB'] = [math]::round(($datastore.FreeSpaceGB|Measure-Object -Sum|select -Property Sum).sum)
    $Cluster_data = New-Object PSObject -Property $Cluster_Utilization
    $as=disconnect-viserver -Server $inputs.vCenterName -confirm:$False
    return $Cluster_data 


PowerCli action to get ESXi utilisation of cluster

function Handler($context, $inputs) {
    $connection = Connect-VIServer -Server $inputs.vCenterName -User $inputs.vCenterUserName -Password $inputs.vCenterPassword -force
    $esxi_usage = Get-Cluster $inputs.clusterName|Get-VMHost|select Name,
    @{n="Total CPU GHZ";E={([math]::Round(($_.CpuTotalMhz)/1000,2))}},
    @{n="CPU Usage GHZ";E={([math]::Round(($_.CpuUsageMhz)/1000,2))}}
    $as=disconnect-viserver -Server $inputs.vCenterName -confirm:$False
    return $esxi_usage

PowerCli action to get datastore utilisation of cluster.

function Handler($context, $inputs) {
    $connection=Connect-VIServer -server $inputs.vCenterName -user $inputs.vCenterUsername -password $inputs.vCenterPassword -force
    $datastore_usage = get-cluster $inputs.clusterName|Get-Datastore| ?{$_.Type -eq 'VMFS' -and $_.Extensiondata.Summary.MultipleHostAccess} |Select Name,

    return $datastore_usage

Now we have saved all the actions in vRO. Lets switch to Service broker and Complete the Custom Form configuration.

This is how the custom form look like , Project , Deployment Name and Cluster will come by default as per Our Cloud Template.
we have used 3 datagrid elements as read only additionally .
lets take a look at all one by one.

First is Cluster which will be using list_cluster powercli action from vRO. for this below are the configuration settings.

we need to provide vCenter name, username and password

Now Cluster Utilisation datagrid which will be using vro action .

Next is ESXi_utilisation datagrid which will be mapped to vRO action.

Last is Datastore_utilisation which will be using vRO action.

If you have followed the article till now then your catalog Item is ready which shows the CPU,Memory and Storage utilisation of Cluster, ESXi and Datastore.

Feel free to share the feedback ,Queries and share it with other people.
Happy Learning !

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 )

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