VMware Cloud Community
Unkyrona
Contributor
Contributor
Jump to solution

Resource Pool Automation

I'm currently being tasked with trying to automate resource pool allocation in our clusters.  Currently our operations team is struggling to size the resource pools automatically, or systems are migrated and the resource pool shares are not reset to the proper amount.  Is there a way I can automate the share amounts based on the memory and CPU for all the VM's in an existing pool.

Example.

Resource pool has 7 VMs in it totaling 100,000 Memory and 10,000 CPU shares.  System is migrated out and now the resource pool needs to be 80,000 memory and 6,000 CPU.  Is there a way to get Orchestrator to do the math for this and edit the resource pool accordingly?

Ben

0 Kudos
1 Solution

Accepted Solutions
TheVMinator
Expert
Expert
Jump to solution

Check out Duncan Eppings post here:

http://www.yellow-bricks.com/2010/02/24/custom-shares-on-a-resource-pools-scripted/

These scripts were done in powershell but the idea was a weekly script you could run to automatically keep resource pool shares in balance as you discussed.  What you would need to do is tweak it to meet your needs then either run this on a powershell host from vCO, or take the logic and translate it into javascript code.

Hope that is helpful!

View solution in original post

0 Kudos
6 Replies
HariRajan
Hot Shot
Hot Shot
Jump to solution

Just giving my inputs here , ; vCOPS can show you the perfect size of the VM's and resource pool , whether we are over provisioned and under provision it can project to us . Considering this as an INPUT and does we can proactively change that ?!.

This is just an addition input for your question  since I have vCOPS . I am also looking the answer for your question here.

Thanks & Regards in Plenteous . Hari Rajan
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

Check out Duncan Eppings post here:

http://www.yellow-bricks.com/2010/02/24/custom-shares-on-a-resource-pools-scripted/

These scripts were done in powershell but the idea was a weekly script you could run to automatically keep resource pool shares in balance as you discussed.  What you would need to do is tweak it to meet your needs then either run this on a powershell host from vCO, or take the logic and translate it into javascript code.

Hope that is helpful!

0 Kudos
Unkyrona
Contributor
Contributor
Jump to solution

Exactly what I was looking for!

Thanks!

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

you're welcome.  If you manage to recode this in javascript, can you share the code?

0 Kudos
Unkyrona
Contributor
Contributor
Jump to solution

I wasn't able to convert to javascript yet, but I did clean up the script.  If you want to play around with it, please feel free.  I ran this against a test environment with no issues. It WILL cough up an error about not being able to find the "resources" resource pool, but continues to run normally.

#add VCLI snapin

Add-PSsnapin VMware.VimAutomation.Core

#connect to vCenter server specified by user

$vCenterServer = read-host "Please enter vCenter server name"

#username and password can be specified here. Be careful as to what password is provided as whoever can see this script can know the password.

#$userName = read-host "Please input username"

#$userPassword = read-host "please input password"

#gather credentials for individual run

$myCredentials = Get-Credential

#connect to VCenter server with credentials from user

connect-viserver $vCenterServer -Credential $myCredentials

#connect to vCenter server with credentials specified in script

#connect-viserver $vCenterServer -username $userName -password $userPassword

#set resource pool gathering

#can specify resource pool name here using "". Right now is set to calculate ALL resource pools.

$ResourcePools = Get-ResourcePool

#main loop to look at every resource pool in vCenter

foreach ($ResourcePool in $ResourcePools)

{

    $numvcpus = 0

    $totalmemory = 0

    $numvms = 0

   

    $pool = Get-ResourcePool -Name $ResourcePool

    #gathers information about the resource pool

    foreach ($VM in ($pool| get-VM | where {$_.Powerstate -eq "PoweredOn"})) #checks only for VMs that are powered on

    {

        #count number of CPUs

        $NumvCPUs += ($VM).NumCpu

        #count how much memory is allocated

        $TotalMemory += ($vm).MemoryMB

        #count number of VMs

        $NumVMs += 1

      

       

    }

  

   #dislays output

    Write-Host "Discovered " $NumvCPUs "running vCPUs in resource pool " $ResourcePool

    Write-Host $TotalMemory "MB of memory allocated in resource pool" $ResourcePool

    Write-Host "Discovered " $NumVMs "running virtual machines in resource pool " $ResourcePool

   

    #calculates the CPU and MEM into the type of share values you need

    $PoolCPUShares = 1000 * $NumvCPUs

    $PoolMemShares = ($TotalMemory / 1024) * 1000

    #sets the resource pool values based on what is gathered

    Set-Resourcepool -Resourcepool $Pool -CPUsharesLevel Custom -NumCpuShares $PoolCPUShares -MemSharesLevel Custom -NumMemShares $PoolMemShares

       

}

I think the easiest way to do this is to get the Powershell plugin and have VCO call the powershell script from a utility server we have set up.  I'm not good enough with javascript to do the conversion.

Message was edited by: Unkyrona

0 Kudos
kchristensen
Contributor
Contributor
Jump to solution

Hi Ukyrona,

I have recently published a vRO workflow on flowgrab that I wrote to manage resource pool share allocations for nested resource pools. It is based on the single-level resource pool share management powershell script that Duncan Epping published on the earlier linked blog post, but has been adapted to parse resource pool hierarchies settings values on all resource pools.

This vRO workflow can;

  • Work with nested resource pools
  • Calculate shares based on powered on or off VMs in a resource pool
  • Apportion shares between sibling resource pools based on a max share value

Heres a link to the project on flowgrab; FlowGrab: View Project

0 Kudos