hi Luc,
Iam trying to convert following into powercli to enable drs ,HA and admision control .
You could do something like this
function get-clusterproperties_utilities {
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string[]]$clusters
)
foreach ($clu in $clusters) {
$cluster = Get-Cluster $clu
Write-Output "clustername`t`t`t`t: $($cluster.Name)"
Write-Output "HA enabled`t`t`t`t: $($cluster.HAEnabled)"
Write-Output " DRS enabled`t`t`t: $($cluster.DrsEnabled)"
Write-Output " DRS automationlevel`t: $($cluster.DrsAutomationLevel)"
Write-Output " HAadmisioncontrol`t`t: $($cluster.HAAdmissionControlEnabled)"
Write-Output "ESXi"
Get-VMHost -Location $cluster | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Ghz' -f ($_.CpuTotalMhz/1000))`t$('{0:n2} GB' -f $_.MemoryTotalGB)"
}
Write-Output "VM Sizes"
Get-VM -Location $cluster | Group-Object -Property numcpu, memorygb | %{
Write-Output "`t`t$($_.Count) with `t`t$('{0:n2} vCPU' -f $_.Name.Split(',')[0])`t$('{0:n2} GB Mem' -f $_.Name.Split(',')[1])"
}
Write-Output "VM with Reserved Memory"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} GB' -f ($_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation/1KB))"
}
Write-Output "VM with Reserved CPU"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Mhz' -f $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation)"
}
}
$res = Read-Host "do yu wnt to enable cluster properties y/n"
if ($res -eq 'y') {
$clusternamee = @()
$answer = ''
while ($answer -ne 'q') {
$answer = Read-Host "specify array of clusters (end with Q)"
if ($answer -ne 'q') {
$clusternamee += $answer
}
}
Get-Cluster -Name $clusternamee |
Set-Cluster -HAEnabled:$true -DrsEnabled:$true -HAAdmissionControlEnabled:$true -WhatIf
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm afraid that those settings can not be done through a cmdlet, you will have to use the ReconfigureCluster API method.
Something like this for example
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
# HA
$spec = New-Object VMware.Vim.ClusterConfigSpec
$spec.DasConfig = New-Object VMware.Vim.ClusterDasConfigInfo
# HA Enabled
$spec.DasConfig.Enabled = $true
# HA - Admission control
$spec.DasConfig.AdmissionControlEnabled = $true
# III - Resource percentage
$spec.DasConfig.AdmissionControlEnabled = $true
$spec.DasConfig.AdmissionControlPolicy = New-Object VMware.Vim.ClusterFailoverResourcesAdmissionControlPolicy
$spec.DasConfig.AdmissionControlPolicy.FailoverLevel = 1
$spec.DasConfig.AdmissionControlPolicy.ResourceReductionToToleratePercent = 100
# IIIa - Auto sizes
$spec.DasConfig.AdmissionControlPolicy.AutoComputePercentages = $true
$modify = $true
$cluster.ExtensionData.ReconfigureCluster($spec,$modify)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There have been many blog posts, books and VMworld sessions on how to select the optimal admission policy for your environment.
In the end, it all comes down to what you want to cover, and what kind of resources you have at your disposal.
A short, handy start is the Best Practices for Admission Control section in the vSphere Availability document.
But like I said, you will have to evaluate for what you want to cover and what HW you have available.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks iamchecking this
i thought of getinginformation of cluster like below to proceed further to select best admission control policy .
could you suggest if orange color code be best fitted here (without additional foreach loop)as iam not getting info from it.
also blue color can be used using comdlet also.
function get-clusterproperties_utilities
{
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string[]]$clusters
)
foreach($clu in $clusters)
{
$cluster=get-cluster $clu
$output = New-Object -TypeName PSObject
$output|Add-Member -MemberType NoteProperty -Name 'clustername' -Value $cluster.Name
$output|Add-Member -MemberType NoteProperty -Name 'HA enabled' -Value $cluster.HAEnabled
$output|Add-Member -MemberType NoteProperty -Name ' DRS enabled ' -Value $cluster.DrsEnabled
$output|Add-Member -MemberType NoteProperty -Name ' DRS automationlevel ' -Value $cluster.DrsAutomationLevel
$output|Add-Member -MemberType NoteProperty -Name ' HAadmisioncontrol ' -Value $cluster.HAAdmissionControlEnabled
$output|Add-Member -MemberType NoteProperty -Name 'esxi' -Value (get-vmhost -Location $cluster|select name,cputotoalmhz,memmorytotalgb )
$output|Add-Member -MemberType NoteProperty -Name 'vms size' -Value (get-vm -Location $cluster|Group-Object -Property numcpu,memorygb)
$output|Add-Member -MemberType NoteProperty -Name 'reservation mem' -Value (Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation})
$output|Add-Member -MemberType NoteProperty -Name 'reservation cpu' -Value (Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation})
$output
}
$res=Read-Host "do yu wnt to enable cluster properties y/n"
if($res -eq 'y')
{
$clusternamee = @()
$answer = ''
while($answer -ne 'q'){
$answer = Read-Host "speclify array of clusters (end with Q)"
if($answer -ne 'q'){
$clusternamee += $answer
}
}
foreach($c in $clusternamee)
{
$cluu=Get-Cluster $c
$cluu.name
Set-Cluster -Cluster $cluu -HAEnabled:$true -DrsEnabled:$true -HAAdmissionControlEnabled:$true -whatif
}
}
You could do something like this
function get-clusterproperties_utilities {
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string[]]$clusters
)
foreach ($clu in $clusters) {
$cluster = Get-Cluster $clu
Write-Output "clustername`t`t`t`t: $($cluster.Name)"
Write-Output "HA enabled`t`t`t`t: $($cluster.HAEnabled)"
Write-Output " DRS enabled`t`t`t: $($cluster.DrsEnabled)"
Write-Output " DRS automationlevel`t: $($cluster.DrsAutomationLevel)"
Write-Output " HAadmisioncontrol`t`t: $($cluster.HAAdmissionControlEnabled)"
Write-Output "ESXi"
Get-VMHost -Location $cluster | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Ghz' -f ($_.CpuTotalMhz/1000))`t$('{0:n2} GB' -f $_.MemoryTotalGB)"
}
Write-Output "VM Sizes"
Get-VM -Location $cluster | Group-Object -Property numcpu, memorygb | %{
Write-Output "`t`t$($_.Count) with `t`t$('{0:n2} vCPU' -f $_.Name.Split(',')[0])`t$('{0:n2} GB Mem' -f $_.Name.Split(',')[1])"
}
Write-Output "VM with Reserved Memory"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} GB' -f ($_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation/1KB))"
}
Write-Output "VM with Reserved CPU"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Mhz' -f $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation)"
}
}
$res = Read-Host "do yu wnt to enable cluster properties y/n"
if ($res -eq 'y') {
$clusternamee = @()
$answer = ''
while ($answer -ne 'q') {
$answer = Read-Host "specify array of clusters (end with Q)"
if ($answer -ne 'q') {
$clusternamee += $answer
}
}
Get-Cluster -Name $clusternamee |
Set-Cluster -HAEnabled:$true -DrsEnabled:$true -HAAdmissionControlEnabled:$true -WhatIf
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks it is working .
i am analysing what admission control policy is best suited depending on the output .
Hi Luc ,
good morning ,
below is one of the clusters where no resrvation (cpu,mem) on vms. code is also attched(little modified to what we had yesterday)
could you suggest appropriate code for green lines in screenshot(whether commanlet or api).
below is the code
function get-clusterpropertiess_utilities {
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string[]]$clusters
)
foreach ($clu in $clusters) {
$cluster = Get-Cluster $clu
Write-Output "clustername`t`t`t`t: $($cluster.Name)"
Write-Output "HA enabled`t`t`t`t: $($cluster.HAEnabled)"
Write-Output " DRS enabled`t`t`t: $($cluster.DrsEnabled)"
Write-Output " DRS automationlevel`t: $($cluster.DrsAutomationLevel)"
Write-Output " HAadmisioncontrol`t`t: $($cluster.HAAdmissionControlEnabled)"
Write-Output "ESXi"
Get-VMHost -Location $cluster | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Ghz' -f ($_.CpuTotalMhz/1000))`t$('{0:n2} GB' -f $_.MemoryTotalGB)"
}
Write-Output "VM Sizes"
Get-VM -Location $cluster | Group-Object -Property numcpu, memorygb | %{
Write-Output "`t`t$($_.Count) with `t`t$('{0:n2} vCPU' -f $_.Name.Split(',')[0])`t$('{0:n2} GB Mem' -f $_.Name.Split(',')[1])"
}
Write-Output "VM with Reserved Memory"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} GB' -f ($_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation/1KB))"
}
Write-Output "VM with Reserved CPU"
Get-VM -Location $cluster | Where-Object {$_.ExtensionData.ResourceConfig.CpuAllocation.Reservation} | %{
Write-Output "`t`t$($_.Name)`t`t$('{0:n2} Mhz' -f $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation)"
}
$sum_cluster_mem=Get-Cluster -Name $cluster | get-vmhost | Measure-Object -Property MemorytotalGb -Sum | Select -ExpandProperty sum
Write-Output "total configured memory cluster in GB`t`t`t`t: $($sum_cluster_mem)"
$sum_vms_mem=Get-Cluster -Name $cluster | get-vm | Measure-Object -Property MemoryGb -Sum | Select -ExpandProperty sum
Write-Output "total configured memory to vms in GB`t`t`t`t: $($sum_vms_mem)"
$sum_cluster_cpu=Get-Cluster -Name $cluster | get-vmhost | Measure-Object -Property cputotalmhz -Sum | Select -ExpandProperty sum
Write-Output "total configured cpu to cluster in ghz`t`t`t`t: $($sum_cluster_cpu/1000)"
$sum_vms_cpu=Get-Cluster -Name $cluster | get-vm | Measure-Object -Property numcpu -Sum | Select -ExpandProperty sum
Write-Output "total configured cpu to vms in ghz`t`t`t`t: $($sum_vms_cpu*2.40)"
}
$res = Read-Host "do yu wnt to enable cluster properties y/n"
if ($res -eq 'y') {
$clusternamee = @()
$answer = ''
while ($answer -ne 'q') {
$answer = Read-Host "specify array of clusters (end with Q)"
if ($answer -ne 'q') {
$clusternamee += $answer
}
}
$cluster=Get-Cluster -Name $clusternamee
write-host "we are using host failure cluster tolerates =1" -ForegroundColor Green
write-host "we are using define host failover capcity by SLOT POLICY(powered-on vms)" -ForegroundColor Green
$cluster = Get-Cluster -Name $clusterName
# HA
$spec = New-Object VMware.Vim.ClusterConfigSpec
$spec.DasConfig = New-Object VMware.Vim.ClusterDasConfigInfo
# HA Enabled
$spec.DasConfig.Enabled = $true
# HA - Admission control
$spec.DasConfig.AdmissionControlEnabled = $true
# III - Resource percentage
$spec.DasConfig.AdmissionControlEnabled = $true
$spec.DasConfig.AdmissionControlPolicy = New-Object VMware.Vim.ClusterFailoverResourcesAdmissionControlPolicy
$spec.DasConfig.AdmissionControlPolicy.FailoverLevel = 1
$spec.DasConfig.AdmissionControlPolicy.ResourceReductionToToleratePercent = 100
# IIIa - Auto sizes
$spec.DasConfig.AdmissionControlPolicy.AutoComputePercentages = $true
$modify = $true
$cluster.ExtensionData.ReconfigureCluster($spec,$modify)
}
}
If you want those settings, then you can make do with the cmdlet, no need for the API.
Set-Cluster -Cluster $cluster -HAEnabled $true -HAAdmissionControlEnabled $true -HAFailoverLevel 1 -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks .once this is set and since there is no reservation configured .slot size will be automatically taken by some algorithm .is that correct ??
Correct
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks.