Hello
I'm trying to automate affinity rules for drs groups manger. The idea is to let certain VMs run on
assigned esx hosts (Type "Run VMs on Hosts" / "Should run on hosts in group").
Background: We've esx hosts in two datacenters interconnected with 10Gig and a netapp metrocluster on each site hosting nfs exports. I have created two groups of type "Host DRS Groups" (esx hosts in datacenter a go into one, hosts in datacenter b go into the other) plus two groups of type "Virtual Machine DRS Groups" (VMs hosted on nfs export a go into one while VMs hosted on nfs export b go into the other). This way we can prevent nfs/iscsi traffic to run across datacenters.
Creating the rules manually in a small cluster does work. However with dozens of VMs in other clusters there must be a way to automate the task and have it run regualary. I would let powercli generate a list of VMs according to nfs export (location of .vmdk is either on site a or site b) then import this into the relevant Virtual Machine DRS Group.
Using get-drsrule -Cluster "cluster" | Export-CliXml does not show details for HOST DRS Groups or Virtual Machine DRS Groups. Is it possible to do this at all? I recon using set-drsrule would let me import the rules.
Any help / ideas is appreceated!
Regards
Sascha
Thank you very much Luc for your quick response. I have to find now how to compare by script the VM affinity host and where (esx host) their actually running.
Regards,
Philippe
hi LucD
i am looking for a script that can separate Windows VMs & Linux VMs onto a separate DRS hostgroup so i can have the windows VMs running on a particular set of hosts in a cluster and linux VMs separate. how do i go about scripting this.
regards
Suresh
I hacked together a script using just machines
#https://communities.vmware.com/message/1666605#1666605
#https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.cluster.GroupSpec.html
# Loading PowerCLI Snapins
function LoadSnapin{
param($PSSnapinName)
if (!(Get-PSSnapin | where {$_.Name -eq $PSSnapinName})){
Add-pssnapin -name $PSSnapinName
}
}
LoadSnapin -PSSnapinName "VMware.VimAutomation.Core"
#Function for updating the Resource VM Groups
function updateDrsVmGroup ($clusterName,$VMFilter,$groupVMName)
{
#Get Cluster Information
$cluster = Get-Cluster -Name $clusterName
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$groupVM = New-Object VMware.Vim.ClusterGroupSpec
$groupVM.operation = "edit"
$groupVM.Info = New-Object VMware.Vim.ClusterVmGroup
$groupVM.Info.Name = $groupVMName
#Perform your VM selection here.
Get-VM -Name $VMFilter | % {$groupVM.Info.VM += $_.Extensiondata.MoRef}
$spec.GroupSpec += $groupVM
#Apply the settings to the cluster
$cluster.ExtensionData.ReconfigureComputeResource($spec,$true)
}
$CredentialID="domain\user"
$vCenterServer="vCenter1"
$cred = Get-Credential $CredentialID
Connect-VIServer -server $vCenterServer -credential $cred
# Calling the function. I've found the group names to be case sensitive, so watch for that.
updateDrsVmGroup -clusterName "Lab1" -VMFilter "ABC*" -groupVMName "MACHINE-GROUP"
Disconnect-VIServer -Confirm:$False