If a service request regarding VM affinity is received you should follow this procedure to implement the service request:
Check validity of service request
Create groups if required
Create affinity rule
Update documentation
Vms can only have a (anti-)affinity if they are part of the same cluster. So always check first if the VMs are in the same cluster. If not, deny the request, if they are, continue.
If the request if to host a VM onto specific hosts you first need to create groups, even if it's just one VM of just one host. VM-Host rules only work with groups. See the “Schiphol-Rijk Production” cluster for an example.
To create a group follow these steps:
Right-click the specific cluster and select “Edit Settings”
Go to “VMware DRS” → DRS Groups Manager
Click Add on the Virtual Machines DRS groups of Host DRS Group section
Enter a name and select the VMs/Hosts that should be in the group
Click OK to create the group
To create the actual affinity rule follow these steps:
Right-click the specific cluster and select “Edit Settings”
Go to “VMware DRS” → Rules
Click Add
Enter a name and select the type:
Keep Virtual Machines together
Separate Virtual Machines
Virtual Machines to Hosts
Select the required VMs, or if selected the Virtual Machines to Hosts option the required VM and Hosts group you just created.
Note that in the last case you also have these options:
Must run on hosts in group
Should run on hosts in group
Must not run on hosts in group
Should not run on hosts in group
Save the rulu by clicking OK
Because DRS rules can get lost when DRS gets disabled you should document the rules very precise. Luckily there are export and import scrips:
Note: These scripts are originally created by
LucD
$outfile = "C:\rules.txt"
Remove-Item $outfile
$clusterName = <cluster-name>
$rules = get-cluster -Name $clusterName | Get-DrsRule
foreach($rule in $rules){
$line = (Get-View -Id $rule.ClusterId).Name
$line += ("," + $rule.Name + "," + $rule.Enabled + "," + $rule.KeepTogether)
foreach($vmId in $rule.VMIds){
$line += ("," + (Get-View -Id $vmId).Name)
}
$line | Out-File -Append $outfile
}
$file = "C:\rules.txt"
$rules = Get-Content $file
foreach($rule in $rules){
$ruleArr = $rule.Split(",")
if($ruleArr[2] -eq "True"){$rEnabled = $true} else {$rEnabled = $false}
if($ruleArr[3] -eq "True"){$rTogether = $true} else {$rTogether = $false}
get-cluster $ruleArr[0] | `
New-DrsRule -Name $ruleArr[1] -Enabled $rEnabled -KeepTogether $rTogether -VM (Get-VM -Name ($ruleArr[4..($ruleArr.Count - 1)]))
}
<pre>
Schiphol-Rijk Production,RSSPRDD02 and MOMPRDD01 apart,True,False,MOMPRDD01,rssprdd02
Schiphol-Rijk Production,bt6prdm21 en 22,True,False,bt6prdm21,bt6prdm22
Schiphol-Rijk Production,bt6prdm01 en 02,True,False,bt6prdm01,bt6prdm02
Schiphol-Rijk Production,bt6prdm11 en 12,True,False,bt6prdm11,bt6prdm12
Schiphol-Rijk Production,vCenter Hosts,True,False
</pre>
<pre>
Schiphol-Rijk RDM And Clusters,jos,True,False,josprdd01a,josprdd01b
Schiphol-Rijk RDM And Clusters,ois,True,False,oisprda01a,oisprda01b
Schiphol-Rijk RDM And Clusters,pws prd D,True,False,PWSPRDD01A,PWSPRDD01B
Schiphol-Rijk RDM And Clusters,pws prd Q,True,False,PWSPRDQ01A,PWSPRDQ01B
Schiphol-Rijk RDM And Clusters,rms,True,False,rmsprdd02a,rmsprdd02b
Schiphol-Rijk RDM And Clusters,bt6 prd,True,False,bt6prdd01a,bt6prdd01b
Schiphol-Rijk RDM And Clusters,bt6 acp,True,False,bt6acpd01a,bt6acpd01b
Schiphol-Rijk RDM And Clusters,tms,True,False,tmsprdd02a,tmsprdd02b
Schiphol-Rijk RDM And Clusters,fps,True,False,fpsprdd02a,fpsprdd02b
</pre>
Discussion