top of page
Search

PowerCli function to configure HA parameters


There are several HA parameters which a end user would have to configure before their environment meets the High-Availability requirement as per their use case. This function allows end users to configure/modify the HA parameters via PowerCli; exactly as they appear on the vCenter GUI.




##Function to set HA configuration parameters
##Written by: sourav.mitra1990@gmail.com
##This function assumes user is connected to a vcenter instance
##Target hosts are in a cluster setup with HA enabled
#Begin function
function ConfigureHA-Param{
#Define all configuration parameters
Param (
[Parameter(Mandatory=$true)][string][ValidateNotNullorEmpty()]$cluster,
[Parameter(Mandatory=$true)][string][ValidateSet("disabled", "lowest", "low", "medium", "high", "highest")]$HostFailureResponse,
[Parameter(Mandatory=$true)][string][ValidateSet("none", "powerOff", "shutdown")]$HostIsolationResponse,
[Parameter(Mandatory=$true)][string][ValidateSet("disabled", "warning", "restartAggressive")]$PDL,
[Parameter(Mandatory=$true)][string][ValidateSet("disabled", "warning", "restartConservative", "restartAggressive")]$APD,
[Parameter(Mandatory=$true)][string][ValidateSet("vmMonitoringDisabled", "vmMonitoringOnly", "vmAndAppMonitoring")]$VMMonitoring,
[Parameter(Mandatory=$true)][string][ValidateSet("allFeasibleDs", "userSelectedDs", "allFeasibleDsWithUserPreference")]$HBDatastore,
[Parameter(Mandatory=$true)][int][ValidateNotNullorEmpty()]$FailoverLevel
)
#Function execution starts
$clusterID= Get-Cluster -Name "$cluster" 

#Set the parameters
$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.Orchestration = New-Object VMware.Vim.ClusterOrchestrationInfo
$spec.Orchestration.DefaultVmReadiness = New-Object VMware.Vim.ClusterVmReadiness
$spec.Orchestration.DefaultVmReadiness.ReadyCondition = 'none'
$spec.Orchestration.DefaultVmReadiness.PostReadyDelay = 0
$spec.DrsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo
$spec.DasConfig = New-Object VMware.Vim.ClusterDasConfigInfo
$spec.DasConfig.AdmissionControlEnabled = $true
$spec.DasConfig.DefaultVmSettings = New-Object VMware.Vim.ClusterDasVmSettings
$spec.DasConfig.DefaultVmSettings.RestartPriority = "$HostFailureResponse"
$spec.DasConfig.DefaultVmSettings.VmComponentProtectionSettings = New-Object VMware.Vim.ClusterVmComponentProtectionSettings
$spec.DasConfig.DefaultVmSettings.VmComponentProtectionSettings.VmStorageProtectionForPDL = "$PDL"
$spec.DasConfig.DefaultVmSettings.VmComponentProtectionSettings.VmReactionOnAPDCleared = 'none'
$spec.DasConfig.DefaultVmSettings.VmComponentProtectionSettings.VmStorageProtectionForAPD = "$APD"
$spec.DasConfig.DefaultVmSettings.IsolationResponse = "$HostIsolationResponse"
$spec.DasConfig.DefaultVmSettings.VmToolsMonitoringSettings = New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.DasConfig.VmMonitoring = "$VMMonitoring"
$spec.DasConfig.HeartbeatDatastore = New-Object VMware.Vim.ManagedObjectReference[] (0)
$spec.DasConfig.HBDatastoreCandidatePolicy = "$HBDatastore"
$spec.DasConfig.AdmissionControlPolicy = New-Object VMware.Vim.ClusterFailoverResourcesAdmissionControlPolicy
$spec.DasConfig.AdmissionControlPolicy.FailoverLevel = $FailoverLevel
$spec.DasConfig.AdmissionControlPolicy.AutoComputePercentages = $true
$spec.DasConfig.AdmissionControlPolicy.PMemAdmissionControlEnabled = $false
$spec.DasConfig.VmComponentProtecting = 'enabled'
$spec.DasConfig.Enabled = $true
$spec.DasConfig.HostMonitoring = 'enabled'
$spec.DpmConfig = New-Object VMware.Vim.ClusterDpmConfigInfo
$modify = $true
$_this = Get-View -Id $clusterID.ExtensionData.MoRef
$_this.ReconfigureComputeResource_Task($spec, $modify)
##End of Function
}

ConfigureHA-Param -cluster "nESXi" -HostFailureResponse high -HostIsolationResponse shutdown -PDL restartAggressive `
-APD warning -VMMonitoring vmMonitoringDisabled -HBDatastore allFeasibleDs -FailoverLevel 1

The table below shows the different configurable parameters available with this function:



Let us take a look at the function in action:


Example 1:


Output:


Example 2:

Output:


Note: Proactive HA configuration and parameters are not configured in this function.







284 views0 comments
bottom of page