Hi all,
I'm trying to convert a simple PowerCLI script to a vCO flow (or actions in the future, when debug will be available for them...)
The PowerCLI script is very simple, it loops through all the VMs of a cluster, and output the average vRAM / vCPU per VM.
The problem is that the action getAllVMsOfCluster take an awfull lot of time (more than 3 min !) to return on a cluster with ~200 VMs, whereas the Get-VM cmdlet on the same cluster take 10-20sec.
I think that the Get-VM cmdlet uses a view and the getAllVMsOfCluster Action simply loops through the objects return by the sdk/mob...
Is there a way to speed the process (other than using the PowerShell plug-in, which I'm trying to avoid as much as possible).
Below is the PowerShell and the vCO version of this simple script:
Here is the PowerCLI script:
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
$vms = $cluster | Get-VM
$nbVMs = $vms.length
$nbvCPUs = 0
$nbvRAM = 0
foreach ($vm in $vms)
{
$nbvCPUs += $vm.NumCpu
$nbvRAM += $vm.MemoryMB
}
$nbvRAM = $nbvRAM / 1024
$nbvRAM = $nbvRAM / 1024
$avgvRAMPerVM = $nbvRAM / $nbVMs
$avgvCPUPerVM = $nbvCPUs / $nbVMs
Write-Host "nbVMs: $nbVMs"
Write-Host "nbvCPUs: $nbvCPUs"
Write-Host "nbvRAM: $nbvRAM"
Write-Host "avgvRAMPerVM: $avgvRAMPerVM"
Write-Host "avgvCPUPerVM: $avgvCPUPerVM"
I converted this to a vCO flow that looks like this :
Input:
cluster as VC:ClusterComputeResource
Output:
avgvRAMPerVM as number
avgvCPUPerVM as number
Flow:
Action: getAllVMsOfCluster
Input: Flow Input "cluster"
Output: Flow Attribute "vms" as Array of VC:VirtualMachine
Scriptable Task: "Do the maths"
Input: Flow Attribute "vms" as Array of VC:VirtualMachine
Output:
Flow Output avgvRAMPerVM
Flow Output avgvCPUPerVM
Script:
var nbVMs = vms.length;
var nbvCPUs = 0;
var nbvRAM = 0;
for (var i in vms)
{
nbvCPUs += vms[i].config.hardware.numCPU;
nbvRAM += vms[i].config.hardware.memoryMB;
}
nbvRAM = nbvRAM / 1024;
avgvRAMPerVM = nbvRAM / nbVMs;
avgvCPUPerVM = nbvCPUs / nbVMs;
System.log("nbVMs: " + nbVMs);
System.log("nbvCPUs: " + nbvCPUs);
System.log("nbvRAM: " + nbvRAM);
System.log("avgvRAMPerVM: " + avgvRAMPerVM);
System.log("avgvCPUPerVM: " + avgvCPUPerVM);