VMware Cloud Community
StephenMoll
Expert
Expert
Jump to solution

Configuring Orchestrated Restart via PowerCLI

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?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

$clusterName = 'MyCluster'

$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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

In the vSphere Webclient GUI, when creating a "VM/Host Rule" the dialogue has the following options:

FieldContent
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:

FieldContent
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?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

$clusterName = 'MyCluster'

$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

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

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?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, you should get the intended order VMG1, VMG2 and finally VMG3


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

StephenMoll
Expert
Expert
Jump to solution

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?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
KenGould
Contributor
Contributor
Jump to solution

@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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

These rules can be found under $cluster.ExtensionData.Config.Rule
This is an array of ClusterRuleInfoobjects
There are multiple types; ClusterAffinityRuleSpecClusterAntiAffinityRuleSpecClusterDependencyRuleInfoClusterVmHostRuleInfoVirtualDiskAntiAffinityRuleSpec,VirtualDiskRuleSpec


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
KenGould
Contributor
Contributor
Jump to solution

Thanks Luc. Not sure how I missed them when poking around! Appreciate the steer.

0 Kudos