Part 2 – The 4:1 Formula
Part 3 – Powershell Scripts

So in parts 1 and 2 of this series I explained (hopefully) what the resource pool priority pie paradox is and how to punch some key numbers into a formula and figure out what exactly you could set for custom shares on a production and test resource pool in order to come out with that 4:1 ratio.  In this part I'll show you how you can get those numbers from your own environment using the VMware PowerCli without having to do the math yourself.

Just a note, for the script to work you must only have two resource pools, which you assign to variables at the beginning of the script.  Along with the resource pools you need to assign your vCenter server name as well as the cluster name.  You may also need to pump in your credentials if you aren't running this from a trusted client.

Anyways, the script is below, feel free to modify as you please.  If you see a spot where I could be more efficient or if I'm doing anything completely crazy let me know…  You can also download it here if you don't feel much like copying and pasting..:)

#################################################################################
# ResourcePoolPie

#
# This script will poll look at VMs residing in a production and a test resource
# pool and determine how to best set the custom share value in order to maintian
# a 4:1 Production:Test ratio.  Note, you must be setup in a Production and Test
# Environment inside of one cluster.  Its kind of unique to my environment and
# may not apply to everyone elses, but feel free to change and modify what you
# need in order to make it work for you.
#
# The following variables will need to be assigned
#
#   $vcenterserver = ip address of vcenter
#   $clustername = name of cluster containing resource pools
#   $prodname = name of production resource pool
#   $testname = name of test resource pool
#
# Created By: Mike Preston, 2011
#
#
#################################################################################

Add-PSSnapin VMware.VimAutomation.Core
# Assign appropriate values to following variables.
$vcenterserver = ""
$clustername = ""
$prodname = ""
$testname = ""
# establish connection to vcenter server
$connection = Connect-VIServer $vcenterserver
# get cluster information
$clus = get-Cluster -Name $clustername | get-view
# get resource pool information
$prodpool = Get-ResourcePool -Location $clustername -Name $prodname
$testpool = Get-ResourcePool -Location $clustername -Name $testname
# get a list of vms in production and test
$prodvms = get-vm -Location $prodpool | where { $_.PowerState -eq "PoweredOn" }
$testvms = get-vm -Location $testpool | where { $_.PowerState -eq "PoweredOn" }
# initialize counters to zero
$totalprodcpu = 0
$totaltestcpu = 0
$totalprodmem = 0
$totaltestmem = 0
# loop through production pool and total cpu/memory
foreach ($vm in $prodvms)
{
    $totalprodcpu = $totalprodcpu + $vm.NumCPU
    $totalprodmem = $totalprodmem + $vm.MemoryMB
}
# loop through test pool and total cpu/memory
foreach ($vm in $testvms)
{
    $totaltestcpu = $totaltestcpu + $vm.NumCPU
    $totaltestmem = $totaltestmem + $vm.MemoryMB
}
# Begin CPU calculations
Write-Host "CPU Configuration"
Write-Host "=========================================================="
write-host "Production Pool contains" $prodvms.count "Powered On VMs containing" $totalprodcpu "cpus"
write-host "Test Pool contains" $testvms.count "Powered On VMs containing" $totaltestcpu "cpus"
write-host "Cluster has" $clus.summary.effectivecpu "MHZ to hand out"
#populate variables for formula a(4w-3x) = nx

 

$a = $totalprodcpu
$w = $clus.summary.effectivecpu
$n = $totalprodcpu + $totaltestcpu
Write-Host ""
# lets solve x πŸ™‚
Write-Host "Lets plug these numbers into our formula and solve x (Production Share)"
Write-Host "a = total number in production, w = total resources, n = total number in prod and test"
Write-Host "——————————–"
Write-Host "a(4w-3x) = nx) "
Write-Host "$a(4($w) – 3(x)) = $n(x)) "
# lets get some tmp vars initialized
$tmp1 = 4 * $w
Write-Host "$a($tmp1 – 3x) = $n(x)"
$tmp2 = $a * $tmp1
$tmp3 = 3 * $a
Write-Host "$tmp2 – $tmp3(x) = $n(x)"
$tmp4 = $n + $tmp3
Write-Host "$tmp4(x) = $tmp2"
$prodpoolresources = $tmp2 / $tmp4
Write-Host "x = $prodpoolresources"
Write-Host "——————————–"
$prodpoolresources = [Math]::Round($prodpoolresources,0)
$testpoolresources = $w – $prodpoolresources
$prodsharepercpu = $prodpoolresources / $totalprodcpu
$prodsharepercpu = [Math]::Round($prodsharepercpu,0)
$testsharepercpu = $testpoolresources / $totaltestcpu
$testsharepercpu = [Math]::Round($testsharepercpu,0)
# Display recommendations
Write-Host "Recommended Share setting for production $prodpoolresources Mhz split between" $prodvms.count "Vms with" $totalprodcpu "cpus resulting in" $prodsharepercpu "Mhz per cpu"
Write-Host "Recommended Share setting for test $testpoolresources Mhz split between" $testvms.count "Vms with" $totaltestcpu "cpus resulting in" $testsharepercpu "mhz per cpu"
# Begin calculating Memory
Write-Host "=========================================================="
Write-Host "Memory Configuration"
Write-Host "=========================================================="
write-host "Production Pool contains" $prodvms.count "Powered On VMs containing" $totalprodmem "MB of Memory"
write-host "Test Pool contains" $testvms.count "Powered On VMs containing" $totaltestmem "MB of Memory"
write-host "Cluster has" $clus.summary.effectivememory "MB of memory to hand out"
#populate variables for formula a(4w-3x) = nx
$a = $totalprodmem
$w = $clus.summary.effectivememory
$n = $totalprodmem + $totaltestmem
Write-Host ""
# lets solve x πŸ™‚
Write-Host "Lets plug these numbers into our formula and solve x (Production Share)"
Write-Host "——————————–"
Write-Host "a(4w-3x) = nx) "
Write-Host "$a(4($w) – 3(x)) = $n(x)) "
# lets get some tmp vars initialized
$tmp1 = 4 * $w
Write-Host "$a($tmp1 – 3x) = $n(x)"
$tmp2 = $a * $tmp1
$tmp3 = 3 * $a
Write-Host "$tmp2 – $tmp3(x) = $n(x)"
$tmp4 = $n + $tmp3
Write-Host "$tmp4(x) = $tmp2"
$prodpoolresources = $tmp2 / $tmp4
Write-Host "x = $prodpoolresources"
Write-Host "——————————–"
$prodpoolresources = [Math]::Round($prodpoolresources,0)
$testpoolresources = $w – $prodpoolresources
$prodsharepermb = $prodpoolresources / $totalprodmem
$testsharepermb = $testpoolresources / $totaltestmem
# Output results
Write-Host "Recommended Share setting for production $prodpoolresources MB split between" $prodvms.count "Vms with" $totalprodmem " MB of RAM resulting in $prodsharepermb shares per MB"
Write-Host "Recommended Share setting for test $testpoolresources MB split between" $testvms.count "Vms with" $totaltestmem " MB of RAM resulting $testsharepermb shares per MB"
Write-Host "=========================================================="

 

 

Part 2 – The 4:1 Formula
Part 3 – Powershell Scripts