Clearly this isn't possible using New-DRSRule as the 'KeepTogether' parameter is boolean which only allows for specifying an affinity or anti-affinity rule.
So is it even possible to define an Orchestrated Restart rule via PowerCLI?
If it is possible, how is it done?
Ok, got it.
No, there is no cmdlet for that, but you can easily write your own function for this kind of rule.
Something like this
$ruleName = 'MyRule'
$ruleMandatory = $true
$firstGroup = 'group1'
$secondGroup = 'group2'
$cluster = Get-Cluster -Name $clusterName
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$newRule = New-Object VMware.Vim.ClusterDependencyRuleInfo
$newRule.VmGroup = $secondGroup
$newRule.DependsOnVmGroup = $firstGroup
$newRule.Enabled = $true
$newRule.Name = $ruleName
$newRule.Mandatory = $ruleMandatory
$newRule.UserCreated = $true
$ruleSpec = New-Object VMware.Vim.ClusterRuleSpec
$ruleSpec.Info = $newRule
$spec.RulesSpec += $ruleSpec
$cluster.ExtensionData.ReconfigureComputeResource($spec,$True)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not 100% sure what you are actually referring to.
Is it the vSphere HA Restart priority of specific VMs?
That you can do with the Set-VM cmdlet and the HARestartPriority parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In the vSphere Webclient GUI, when creating a "VM/Host Rule" the dialogue has the following options:
Field | Content |
---|---|
Name: | text field for name of rule |
Enable Rule: | Check box. |
Type: | Drop down list with these choices: "Keep Virtual Machines Together" "Separate Virtual Machines" "Virtual Machines to Hosts" "Virtual Machines to Virtual Machines" |
With "Virtual Machines to Virtual Machines" selected the rest of the dialogue changes to:
Field | Content |
---|---|
Description: | Virtual machines in the VM group {VM Group Name} will be restarted first. Virtual machines in the VM group {VM group name} will be restarted afterwards, when the cluster dependency restart condition has been met. |
First restart VMs in VM group: | A drop down list of VM groups defined in "VM/Host Groups". |
Then restart VMs in VM group: | A drop down list of VM groups defined in "VM/Host Groups". |
The New-DRSRule commandlet in PowerCLI specifies the rule type as boolean value, which only allows for the creation of either "Keep Virtual Machines Together" or "Separate Virtual Machines" rules. I wanted to know if a "Virtual Machines to Virtual Machines" rule can be created in PowerCLI at all?
Ok, got it.
No, there is no cmdlet for that, but you can easily write your own function for this kind of rule.
Something like this
$ruleName = 'MyRule'
$ruleMandatory = $true
$firstGroup = 'group1'
$secondGroup = 'group2'
$cluster = Get-Cluster -Name $clusterName
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$newRule = New-Object VMware.Vim.ClusterDependencyRuleInfo
$newRule.VmGroup = $secondGroup
$newRule.DependsOnVmGroup = $firstGroup
$newRule.Enabled = $true
$newRule.Name = $ruleName
$newRule.Mandatory = $ruleMandatory
$newRule.UserCreated = $true
$ruleSpec = New-Object VMware.Vim.ClusterRuleSpec
$ruleSpec.Info = $newRule
$spec.RulesSpec += $ruleSpec
$cluster.ExtensionData.ReconfigureComputeResource($spec,$True)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for that LucD, going to have a play with that and see what we can do with it.
Obviously a single rule can only have two groups of VMs, in which group is started and then the second.
If I have three VM groups, say VMG1, VMG2 and VMG3.
If I create 2 rules, one rule with VMG1 and VMG2, and the second rule with VMG2 and VMG3, what happens?
Do I get a start sequence with VMG1 then VMG2 and lastly VMG3, or does it just get messy somehow?
No, you should get the intended order VMG1, VMG2 and finally VMG3
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Brilliant, I'll give it a go.
What is the easiest way to to test this? Get all the VMs running on a host and then kill it?
Yes, have at least 3 VMs running on that ESXi node, each VM in a different group.
Then kill the node
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Is there a way to interrogate the existing VM to VM Dependency rules? Use case is to capture them, so that they can be reinstated in the case of a full site disaster.
I've poked around in the extensiondata of a cluster but not seeing it stored there.
These rules can be found under $cluster.ExtensionData.Config.Rule
This is an array of ClusterRuleInfoobjects
There are multiple types; ClusterAffinityRuleSpec, ClusterAntiAffinityRuleSpec, ClusterDependencyRuleInfo, ClusterVmHostRuleInfo, VirtualDiskAntiAffinityRuleSpec,VirtualDiskRuleSpec
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc. Not sure how I missed them when poking around! Appreciate the steer.