Code Snips – Holodeck DRS Rules
There’s some tasks that I always like to do after deploying a fresh holodeck environment.
This example shows how to automatically configure DRS rules to pin the vCenter to the first ESX host, and NSX to the second ESX host. This helps me easily find the VMs when starting up the environment.
Here’s a PowerCLI example to create the required DRS Groups and Rules. All hostnames are using the Holodeck standard.
# Script to pin vCenter to Host 1 and NSX to Host 2 in Holodeck Environments
Import-Module VMware.PowerCLI
# Set Site - A or A2
$HoloSite = "A"
If ($HoloSite -eq "A") {
$vCenter = "vcenter-mgmt.vcf.sddc.lab"
$Host1 = "esxi-1.vcf.sddc.lab"
$Host2 = "esxi-2.vcf.sddc.lab"
}
ElseIf ($HoloSite -eq "A2") {
$vCenter = "vcenter-mgmt.vcf2.sddc.lab"
$Host1 = "esxi-1.vcf2.sddc.lab"
$Host2 = "esxi-2.vcf2.sddc.lab"
}
Else {exit}
Connect-VIServer $vCenter
# Create Host Groups
New-DrsClusterGroup -Name "Host1" -Cluster "mgmt-cluster-01" -VMHost $Host1
New-DrsClusterGroup -Name "Host2" -Cluster "mgmt-cluster-01" -VMHost $Host2
# Create VM Groups
New-DrsClusterGroup -Name "vCenter" -Cluster "mgmt-cluster-01" -VM "vcenter-mgmt"
New-DrsClusterGroup -Name "NSX" -Cluster "mgmt-cluster-01" -VM "nsx-mgmt-1"
# Create DRS Rules
New-DrsVMHostRule -Name "Pin vCenter" -Cluster "mgmt-cluster-01" -VMHostGroup "Host1" -VMGroup "vCenter" -Type ShouldRunOn -Enabled:$true
New-DrsVMHostRule -Name "Pin NSX" -Cluster "mgmt-cluster-01" -VMHostGroup "Host2" -VMGroup "NSX" -Type ShouldRunOn -Enabled:$true
Disconnect-VIServer $vCenter -Confirm:$false