Is there PowerCLI script - or a series of commands - that can be used to determine if a VMs resource pool has enough available resources to start the VM WITHOUT triggering a vSphere error?
For performance testing reasons, we use a resource pool with maximums for RAM and CPU. Each VM in the pool has a reservation set for CPU and RAM. Testing automation will attempt to start as many VMs as possible in the pool when testing. The CLI will return an error when starting the VM will exceed the amount of allowed resources. When that happens, an error is shown on the vSphere console "Insufficient resources". Instead of constantly starting the VM, failing, and generating the error - is there a way to check to see if there is enough space?
Thanks,
Jason
Hi Jason,
you can try if the following PowerCLI function is what you need. The function does not look at expandable reservations.
function Get-VmStartPossible { param($VM) $VM = Get-VM $VM $ResourcePool = $VM | Get-ResourcePool $CpuReservationUsed = $ResourcePool.ExtensionData.Runtime.Cpu.ReservationUsed $VMCpuReservation = $VM.ExtensionData.ResourceConfig.CpuAllocation.Reservation $ResourcePoolCpuLimit = $ResourcePool.ExtensionData.Config.CpuAllocation.Limit $MemoryReservationUsed = $ResourcePool.ExtensionData.Runtime.Memory.ReservationUsed $VMMemoryReservation = $VM.ExtensionData.ResourceConfig.MemoryAllocation.Reservation $ResourcePoolMemoryLimit = $ResourcePool.ExtensionData.Config.MemoryAllocation.Limit*1MB if (($CpuReservationUsed + $VMCpuReservation -gt $ResourcePoolCpuLimit) -or ($MemoryReservationUsed + $VMMemoryReservation -gt $ResourcePoolMemoryLimit)) { $false } else { $true } }
You can call the function with:
Get-VmStartPossible -VM MyVM
Hi Jason,
you can try if the following PowerCLI function is what you need. The function does not look at expandable reservations.
function Get-VmStartPossible { param($VM) $VM = Get-VM $VM $ResourcePool = $VM | Get-ResourcePool $CpuReservationUsed = $ResourcePool.ExtensionData.Runtime.Cpu.ReservationUsed $VMCpuReservation = $VM.ExtensionData.ResourceConfig.CpuAllocation.Reservation $ResourcePoolCpuLimit = $ResourcePool.ExtensionData.Config.CpuAllocation.Limit $MemoryReservationUsed = $ResourcePool.ExtensionData.Runtime.Memory.ReservationUsed $VMMemoryReservation = $VM.ExtensionData.ResourceConfig.MemoryAllocation.Reservation $ResourcePoolMemoryLimit = $ResourcePool.ExtensionData.Config.MemoryAllocation.Limit*1MB if (($CpuReservationUsed + $VMCpuReservation -gt $ResourcePoolCpuLimit) -or ($MemoryReservationUsed + $VMMemoryReservation -gt $ResourcePoolMemoryLimit)) { $false } else { $true } }
You can call the function with:
Get-VmStartPossible -VM MyVM
Thanks! This looks like what I need. I'll give it a try.