Setting up resource pools

Resource pools are objects within vSphere where VM objects with similar performance requirements can be grouped together. Resource pools allow a priority to be set to pools of compute, memory, and disk resources, so that when the contention occurs, the hypervisor can choose which VMs get access to resources first. Resource pools exist within the cluster objects in vSphere or within host objects if a host is not a part of a cluster.

Getting ready

To begin this recipe, you will need to open a PowerCLI window and connect to a vCenter server. For the purpose of this example, we're going to configure two resource pools: Production and Development. The Production resource pool will be configured with the high setting for CPU and memory resources. The Development resource pool will be configured with the low setting for CPU and memory resources.

Sometimes, PowerCLI defines its normal conventions and resource pools is one of them. You can't simply pass a cluster in as the location for a new resource pool. Although it is not shown, when you create a cluster, it creates a default resource pool called Resources, which is similar to how the creation of a datacenter created four subfolders. The location that a New-ResourcePool cmdlet is looking for is a resource pool object.

How to do it…

In order to set up a resource pool, perform the following steps:

  1. The first step is to locate the root Resources folder so that you can use it in the creation of a new resource pool. Since all of the root resource folders are called Resources, you should scope the Get-ResourcePool cmdlet to make sure that the pool is for the correct cluster. If you only have one cluster, this is a nonissue, but you will illustrate it to make the code more reusable:
    Get-ResourcePool -Name "Resources" -Location (Get-Cluster -Name "BigCluster")
    
  2. With this scoping statement, you can use this in the -Location parameter of the New-ResourcePool cmdlet. In addition to the location, you also need to specify a name for the new pool and additional parameters to define the CPU and RAM share settings. Additional parameters can also be defined to set reservations for CPU or RAM and expandable reservations. In our example, you will set the -CPUExpandableReservations and -MemExpandableReservation parameters to $true:
    New-ResourcePool -Name "Production" -Location (Get-ResourcePool -Name "Resources" -Location (Get-Cluster -Name "BigCluster") ) -CPUSharesLevel high -MemSharesLevel high -CpuExpandableReservation $true -MemExpandableReservation $true
    
  3. While this is the most correct way to create the new pool, you need to ensure that you have specified the correct resource pool to contain it. There is a much shorter cmdlet that will accomplish the same in our environment:
    New-ResourcePool -Name "Production" -Location "BigCluster" -CPUSharesLevel high -MemSharesLevel high -CpuExpandableReservation $true -MemExpandableReservation $true
    

    This is much cleaner and more readable code than the previous one and it will accomplish the same thing.

  4. The next step is to repeat the same code for our Development resource pool, except you want to set the share levels to low in this example:
    New-ResourcePool -Name "Development" -Location "BigCluster" -CPUSharesLevel low -MemSharesLevel low -CpuExpandableReservation $true -MemExpandableReservation $true
    
  5. Again, you have to move objects into this resource pool. Moving a VM into the resource pool will not move it out of the folders or other locations where it might be assigned, it will only move the VM in the context of the Host and Clusters view. You will use the Move-VM cmdlet and specify the host and the location:
    Move-VM -Name vCenterSrv -Location (Get-ResourcePool "Production")
    
  6. Lastly, if you have an existing resource pool, but you need to adjust the settings, you can do so with the same parameters using the Set-ResourcePool cmdlet:
    Set-ResourcePool -ResourcePool (Get-ResourcePool Production) -CpuSharesLevel Custom -NumCpuShare 8000
    

How it works…

The New-ResourcePool cmdlet creates a new pool inside the location specified in the cmdlet. If the location is a Host or Cluster, the new pool is automatically placed into the Resources pool at the root of the cluster or host.

The New-ResourcePool cmdlet provides a lot of additional parameters to configure the resource pool from the start. In our example, you specified the shares level, which is one of four enumerated choices: Low, Normal, High, and Custom. With Custom, you also have to specify a number using the -NumCpuShares and -NumMemShares parameters. In addition to share definitions, you can also set the reservations and limits for CPU and RAM. You can specify a number of MHz or MB for reservations and limits on the pool. Limits allow no more than the specified amount of CPU or RAM resources, and reservations guarantee the specified amount of CPU or RAM resources for the pool. There is also the concept of expandable reservations that allows a pool to borrow the specified value if its parent has unallocated resources.

One thing that should start to become clear is that unique names go a long way to shortcutting your code. If a name is unique to a single folder, cluster, host, or an object, there is no need to pass in the location by an object using a Get- cmdlet. Names without spaces also help to shortcut code, since any name with spaces requires quotes around it.

There's more…

Resource Pools in vSphere can be intimidating, but they play a powerful role in keeping things running smoothly. Chris Wahl of WahlNetwork.com has an excellent post about Resource Pools and includes a PowerCLI script to help keep your pools balanced using his formula for computing the appropriate number of shares. For more information, refer to http://wahlnetwork.com/2012/02/01/understanding-resource-pools-in-vmware-vsphere/

See also

  • Creating and reporting vSphere resource pools
  • Moving objects between resource pools
  • Reporting shares, reservations and limits of resource pools, and virtual machines
  • Setting shares, reservations, and limits for similarly classified objects in vSphere