Wersquo;re kicking off the first in a series of blog posts taking an in-depth look at some of the new cmdlets that were made available with the PowerCLI 6.5.1 release. This first post is going to be covering the cmdlets targeted at managing DRS groups and their associated rules.
These new cmdlets are as follows:
If yoursquo;ve never used DRS groups and DRS affinity rules or donrsquo;t know what they are, these are a way to control which VMs are able to exist on which hosts. This control is leveraged through either affinity or anti-affinity rules that are configured at the cluster level. These rules are configured between groupings of VMs and groupings of hosts. These rules also have types, which basically describes how the enforcement should work. The types are: Must Run On, Should Run On, Must Not Run On, Should Not Run On
Please see the documentation for more information about: DRS Affinity Rules
Taking A Closer Look – A Use Case Demonstration
We have been given a lab environment and our end result is to have the even numbered App VMs run on the even numbered hosts whenever possible, and likewise with the odd numbered VMs and hosts.
First, a look at the lab environment:
Wersquo;ll start by taking a look at the DRS Cluster Group cmdlets. These are used in order to create, manage, and remove VM and host based DRS groups. These cluster groups are then referenced by the DRS VM-Host affinity rules, which wersquo;ll discuss in a bit.
Letrsquo;s create the first host DRS group, which will be for the odd numbered hosts. This can be done with the lsquo;New-DrsClusterGrouprsquo; cmdlet while specifying a name, the cluster, and the desired hosts. A command for our sample environment looks like this:
New-DrsClusterGroup -Name HostsOdd -Cluster Demo -VMHost esx01.corp.local,esx03.corp.local
Wersquo;ll repeat a similar process for the even hosts, only this time wersquo;ll store the cluster and desired hosts in their own variables:
We now have the required host DRS groups, so we can move forward and create the VM DRS groups. These are created with the same lsquo;New-DrsClusterGrouprsquo; cmdlet, except wersquo;ll now use the VM parameter and specify the VMs for each group.
Starting again with our odd numbered VMs, wersquo;ll use the following command:
New-DrsClusterGroup -Name VMsOdd -Cluster $cluster -VM app01,app03,app05
If yoursquo;ll notice, thatrsquo;s nowhere close to all of the necessary odd numbered VMs. Wersquo;ll now make use of the lsquo;Set-DrsClusterGrouprsquo; cmdlet to add the remaining VMs (which Irsquo;ve already stored into a variable). This cmdlet also requires usage of either the lsquo;Addrsquo; or lsquo;Removersquo; parameter in order to specify what kind of modification is being requested.
The command to add the remaining odd system should be similar to the following:
Set-DrsClusterGroup -DrsClusterGroup VMsOdd -VM $VMsOdd –Add
Wersquo;ll repeat a similar process for the even VMs’ DRS group:
Before moving on to creating the VM-Host affinity rules, letrsquo;s review the DRS groups wersquo;ve created to this point with the lsquo;Get-DrsClusterGrouprsquo; cmdlet.
This cmdlet also has a couple parameters to help gain additional information. The lsquo;Typersquo; parameter can be used to specify whether to return VM groups or host groups. The lsquo;VMrsquo; and lsquo;VMHostrsquo; parameters can be used to only return DRS groups belonging to that VM or host.
Some examples of these parameters in use:
Moving on to the creation of the rules… Wersquo;ll be using the lsquo;New-DrsVMHostRulersquo; cmdlet along with several parameters. These parameters will be lsquo;Namersquo;, lsquo;Clusterrsquo;, lsquo;VMGrouprsquo;, lsquo;VMHostGrouprsquo;, and lsquo;Typersquo;. Most of those should be self-explanatory, but lsquo;Typersquo; may not be. Thanks to tab complete, wersquo;ll see that the type options are lsquo;MustRunOnrsquo;, lsquo;ShouldRunOnrsquo;, lsquo;MustNotRunOnrsquo;, and lsquo;ShouldNotRunOnrsquo; and apply to how the rule is enforced against the cluster.
Remembering that our goal is to have the even VMs run on the even hosts whenever possible, wersquo;ll issue the following command:
New-DrsVMHostRule -Name 'EvenVMsToEvenHosts' -Cluster $cluster -VMGroup VMsEven -VMHostGroup HostsEven -Type ShouldRunOn
Wersquo;ll do a similar command for the odd rule:
Our objective should be complete and we can verify that by using the lsquo;Get-DrsVMHostRulersquo; cmdlet. The output should be similar to the following:
These VM-Host rules can also be modified once theyrsquo;ve created with the lsquo;Set-DrsVMHostRulersquo; cmdlet. This cmdlet has the ability to rename the rule, enable or disable it, and modify either the VMGroup and/or the VMHostGroup.
The rules can easily be disabled using the following command:
Get-DrsVMHostRule | Set-DrsVMHostRule -Enabled $false
This environment happens to be a lab, so before wrapping up this post we should probably clean it up. We can do this while utilizing the lsquo;Remove-DrsClusterGrouprsquo; and lsquo;Remove-DrsVMHostRulersquo; cmdlets. The commands could look like the following:
Remove-DrsVMHostRule -Rule EvenVMsToEvenHosts,OddVMsToOddHostsGet-DrsClusterGroup | Remove-DrsClusterGroup
These eight new cmdlets are a terrific addition to the PowerCLI 6.5.1 release. They are also a great compliment to the already existing DRS cmdlets! Start using them today and let us know your feedback!
The post Spotlight on the New DRS Groups and VM-Host Rule Cmdlets! appeared first on VMware PowerCLI Blog.