PowerCLI

 View Only
  • 1.  enabling cluster properties through powercli

    Posted Nov 21, 2018 09:14 AM

    hi Luc,

    Iam trying to convert following into powercli to enable drs ,HA and admision control .

    while DRS and HA is quite straitforward with set-cluster command but iam finding little confusion configuring Admission control .
    i think this is also using set-cluster but how to decide what policy is best suited .not entirely powercli question but if could suggest something on it .


  • 2.  RE: enabling cluster properties through powercli

    Posted Nov 21, 2018 10:14 AM

    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)



  • 3.  RE: enabling cluster properties through powercli

    Posted Nov 21, 2018 10:18 AM

    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.



  • 4.  RE: enabling cluster properties through powercli

    Posted Nov 22, 2018 01:25 AM

    Thanks iamchecking this



  • 5.  RE: enabling cluster properties through powercli

    Posted Nov 28, 2018 01:49 AM

    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

        }

    }



  • 6.  RE: enabling cluster properties through powercli
    Best Answer

    Posted Nov 28, 2018 06:12 AM

    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

      }

    }



  • 7.  RE: enabling cluster properties through powercli

    Posted Nov 28, 2018 06:39 AM

    thanks it is working .

    i am analysing what admission control policy is best suited depending on the output .



  • 8.  RE: enabling cluster properties through powercli

    Posted Nov 29, 2018 03:33 AM

    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)

      }

    }



  • 9.  RE: enabling cluster properties through powercli

    Posted Nov 29, 2018 06:17 AM

    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



  • 10.  RE: enabling cluster properties through powercli

    Posted Nov 29, 2018 07:26 AM

    thanks .once this is set and since there is no reservation configured .slot size will be automatically taken by some algorithm .is that correct ??



  • 11.  RE: enabling cluster properties through powercli

    Posted Nov 29, 2018 07:32 AM

    Correct



  • 12.  RE: enabling cluster properties through powercli

    Posted Nov 30, 2018 06:23 AM

    thanks.