Automation

 View Only
  • 1.  DRS Reporting

    Posted May 25, 2012 02:54 PM

    Hi

    I doubt I'm the only one who has ran into this so far with PowerCLI 5.0.

    With vSphere 4.1 (I think) one could start setting up Host groups & VM groups, and then used advanced DRS ability to pair them up with affinity or anti-affinity.  I have found functions to create new groups & add to existing (thank you Arnim & Luc - http://communities.vmware.com/message/2040365 ) but I'm having a hard time  finding a report that could give me the content of these advanced DRS rules (with groups & associated rule configuration) that we have in our environment.

    I have had extremely bad luck with Onyx (it's always crashing on me) so I'm wandering in the dark about this.  Thoughts?



  • 2.  RE: DRS Reporting

    Posted May 25, 2012 03:48 PM

    Hey!

    I feel like the link you provided all the information you would need already... http://www.van-lieshout.com/2011/06/drs-rules/

    Does that not provide what you want?



  • 3.  RE: DRS Reporting

    Posted May 25, 2012 03:58 PM

    Hi

    Well, not in my opinion, though I can be wrong.  I looked at Arnim's functions from Luc's suggestion, and it looks like it compiles object information in memory before calling the "ReconfigureComputeResource_Task", passing in the object & its information.  From these three functions, I can't really understand how I could extract information from existing DRS rules & groups.



  • 4.  RE: DRS Reporting

    Posted May 25, 2012 06:24 PM

    I am looking more at the example they provided of...

    Get-DrsRule –Cluster CL01 | Select Name, Enabled, KeepTogether, VMs


  • 5.  RE: DRS Reporting

    Posted May 25, 2012 06:31 PM

    Oh, I understand your comment now.

    The Get-DRSrule indicated in the blog entry works for the so-called 'legacy' DRS rules.  It doesn't have any insight into the VM group & ESX Host group associations.



  • 6.  RE: DRS Reporting
    Best Answer

    Posted May 26, 2012 01:14 AM

    I created a function that should give you everything, rules and groups.

    function Get-DrsRuleAndGroup{
      param(
        [string]$ClusterName
      )   $vms = @{}   $hosts = @{}   $vmGroup =@{}   $hostGroup = @{}   $cluster = Get-Cluster -Name $ClusterName
     
    Get-VM -Location $cluster | %{     $vms.Add($_.ExtensionData.MoRef,$_.Name)   }   Get-VMHost -Location $cluster | %{     $hosts.Add($_.ExtensionData.MoRef,$_.Name.Split('.')[0])   }   $cluster.ExtensionData.ConfigurationEx.Group | %{     if($_ -is [VMware.Vim.ClusterVmGroup]){       $vmGroup.Add($_.Name,$_)     }     else{       $hostGroup.Add($_.Name,$_)     }   }   foreach($rule in $cluster.ExtensionData.ConfigurationEx.Rule){     New-Object PSObject -Property @{       Name = $rule.Name
          Enabled = $rule.Enabled
         
    Mandatory = $rule.Mandatory
          Type = &{         switch($rule.GetType().Name){         "ClusterAffinityRuleSpec" {"Affinity"}         "ClusterAntiAffinityRuleSpec" {"AntiAffinity"}         "ClusterVmHostRuleInfo" {"VmHostGroup"}         }       }       VM = &{         if($rule.Vm){           [string]::Join('/',($rule.Vm | %{$vms[$_]}))         }       }       VMGroup = $rule.VmGroupName
          VMGroupVM = &{         if($rule.VmGroupName){           [string]::Join('/',($vmGroup[$rule.VmGroupName].Vm | %{$vms[$_]}))         }       }       AffineHostGroup = $rule.AffineHostGroupName
          AntiAffineHostGroup = $rule.AntiAffineHostGroupName
         
    HostGroup = &{         if($rule.AffineHostGroupName -or $rule.AntiAffineHostGroupName){           if($rule.AffineHostGroupName){$groupname = $rule.AffineHostGroupName}           if($rule.AntiAffineHostGroupName){$groupname = $rule.AntiAffineHostGroupName}           [string]::Join('/',($hostGroup[$groupname].Host | %{$hosts[$_]}))         }       }     }   } } Get-DrsRuleAndGroup -ClusterName MyCluster | Select Name,Enabled,Mandatory,Type,VM,VMGroup,VMGroupVM,AffineHostGroup,AntiAffineHostGroup,HostGroup |
    Export-Csv C:\Drs-Rules-Groups.csv -NoTypeInformation -UseCulture

    This is still a early version of the function, but it should provide the information you want.



  • 7.  RE: DRS Reporting

    Posted May 29, 2012 01:45 PM

    Hi Luc - thanks for the response.

    This is exactly what I was looking for.  I had to make a minor adjustment on line 11, but that was probably more a copy/paste issue than anything.

    Once question, though - the "VM" column was blank.  Is that to be expected for a cluster that just has group-based DRS rules?  Can this script work in a mixed-mode environment with 'standard/legacy' rules and the vm/host group rules?

    Thanks again Luc -your time is appreciated



  • 8.  RE: DRS Reporting

    Posted May 29, 2012 01:49 PM

    That is correct, the VM column will only have entries for the standard affinity/anti-affinity rules.



  • 9.  RE: DRS Reporting

    Posted Mar 29, 2016 05:16 PM

    DRS script fails if DRS is not enabled? DRS script fails ExtensionData is not populated...

    --------------------------

    $cluster.ExtensionData.ConfigurationEx.Group | %{

    if($_ -is [VMware.Vim.ClusterVmGroup]){

    $vmGroup.Add($_.Name,$_)

    }

    else{

    $hostGroup.Add($_.Name,$_)

    }

    }

    ------------------------------------------------

    f we have extensive variance in our environments,Script needs to do explicit checking.

    Is $_.Name is null, then error, if $_ is null, error.

    However, DRS may not be enabled, or configured, the script will need to handle this potential.


    Please guide me on how to handle the script, if DRS is not enabled.


    Thank you,

    Basavaraj
    LucDDRS Reporting



  • 10.  RE: DRS Reporting

    Posted Mar 30, 2016 05:08 AM

    This is a rather old script.

    In the mean time we created the DRSRule module, see DRSRule – a DRS rules and groups module

    I would suggest to use that module