VMware Cloud Community
aravinds3107
Virtuoso
Virtuoso
Jump to solution

DRS Migration Threshold Output

I am able to get the DRS Threshold migration value from the below,

$cluster.ExtensionData.ConfigurationEx.DrsConfig.VmotionRate

Depending on the value I want to write the output something like below

If value is 3 = Apply Priority 1,2 and 3

If value is 2 = Apply Priority 1,2,3 and 4

Any help?

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster | Select Name,
 
HAEnabled,
 
@{N="HAFailoverLevel";E={
   
if($_.HAEnabled){$_.HAFailoverlevel}else{"na"}}},
 
DrsEnabled,
 
@{N="DRS Migration Threshold";E={
   
if($_.DrsEnabled){
   
$x = $_.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
   
$t = @()
   
$fa = @()
   
$priorities = 1..(6 - $x) | %{
     
$t += $_
     
if($_ -eq (6 - $x)){
       
if($fa.Count -eq 0){
         
$f = "Apply priority {0}"
        }
       
else{
         
$f = "Apply priority $([string]::Join(', ',$fa)) and {$($_ -1)}"
        }
      }
     
else{
       
$fa += "{$($_ -1)}"
      }
    }
   
$f -f $t}
   
else{"na"}}}


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

View solution in original post

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cluster = Get-Cluster -Name MyCluster
$tgtRating = 1,2,3
if($cluster.ExtensionData.ConfigurationEx.DrsConfig.VmotionRate -eq   2){
 
$gtRating += 4
}
$cluster.ExtensionData.DrsRecommendation |
where {$tgtRating -contains $_.Rating} | %{
 
$cluster.ExtensionData.ApplyRecommendation($_.key)
}


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

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso
Jump to solution

It doesnt provide me any output..

Based on the script above I think only when there is a recommendation triggered, it provides the output, Is it correct?

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is correct.

Perhaps I didn't understand the request correctly, do you want apply the recommendation or just display them ?

Or both ?


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

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso
Jump to solution

Just want to display them...

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$cluster = Get-Cluster -Name MyCluster
$tgtRating = 1,2,3
if($cluster.ExtensionData.ConfigurationEx.DrsConfig.VmotionRate -eq   2){
 
$gtRating += 4
}
foreach($recommendation in ($cluster.ExtensionData.DrsRecommendation | where {$tgtRating -contains $_.Rating})){
 
$recommendation.MigrationList |
 
Select @{N="Source";E={Get-View $_.Source | Select -ExpandProperty Name}},
   
@{N="Destination";E={Get-View $_.Destination | Select -ExpandProperty Name}},
   
@{N="VM";E={Get-View $_.VM | Select -ExpandProperty Name}},
   
@{N="Reason";E={$recommendation.Reason}},
   
@{N="ReasonText ";E={$recommendation.ReasonText}},
   
@{N="Rating";E={$recommendation.Rating}}
}


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

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso
Jump to solution

Luc, Sorry I am not clear even now,

I am just looking the corresponding slider value which we get in the vSphere client for the Migration threshold to vMotion rate value

For e.g.: If the vMotion rate is 3 – the slider value in GUI is “Apply Priority 1, 2 and 3 recommendation”

I am working on a reporting where I have a column as below

Cluster Namw

DRS Migration Threshold

Cluster1

Apply Priority 1, 2 and 3 recommendation

Cluster2

Apply Priority 1 and 2 recommendation

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I see,nice challenge :smileygrin:

Try something like this

Get-Cluster | Select Name,

     @{N="DRS Migration Threshold";E={

        $x = $_.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate

        $t = @()

        $fa = @()

        $priorities = 1..(6 - $x) | %{

            $t += $_

            if($_ -eq (6 - $x)){

                if($fa.Count -eq 0){

                    $f = "Apply priority {0}"

                }

                else{

                    $f = "Apply priority $([string]::Join(', ',$fa)) and {$($_ -1)}"

                }

            }

            else{

                $fa += "{$($_ -1)}"

            }

        }

        $f -f $t}}


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

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso
Jump to solution

Thanks Luc, this works perfectly

But I am seeing a little weird issue, when the DRS is disabled I get the value for both “DRS Automation Level” and “DRS migration threshold”. Is this not supposed be a negative value or just show as NA

Output when DRS is Disabled

Name                    : Cloud-HA

vSphere DRS             : Disabled

DRS - Automation Level  : FullyAutomated

DRS Migration Threshold : Apply priority 1, 2 and 3

Output when DRS is Enabled

Name                    : Cloud-HA

vSphere DRS             : Enabled

DRS - Automation Level  : FullyAutomated

DRS Migration Threshold : Apply priority 1, 2 and 3

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that is perfectly normal, since disabling DRS does not erase the vMotionRate value.

The script will need an extra test if you want it to act accordingly.

Get-Cluster | Select Name,
 
DrsEnabled,
 
@{N="DRS Migration Threshold";E={
   
if($_.DrsEnabled){
   
$x = $_.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
   
$t = @()
   
$fa = @()
   
$priorities = 1..(6 - $x) | %{
     
$t += $_
     
if($_ -eq (6 - $x)){
       
if($fa.Count -eq 0){
         
$f = "Apply priority {0}"
        }
       
else{
         
$f = "Apply priority $([string]::Join(', ',$fa)) and {$($_ -1)}"
        }
      }
     
else{
       
$fa += "{$($_ -1)}"
      }
    }
   
$f -f $t}}}


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

aravinds3107
Virtuoso
Virtuoso
Jump to solution

Thanks Luc, that did the work just a update, is it possible add as "NA" if DRS is disabled instead of just a blank cell.

Also I am noticing a similar behaviour when I am looking for HA settings, for eg if HA is disabled , I get the HA properties like host monitoring, failover capacity returns value as  “True”. If you could give me a logic to perform the testing for  HA settings, I will try to complete the other part

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, it's a matter of adding an Else to the If-statement.

Get-Cluster | Select Name,
 
HAEnabled,
 
DrsEnabled,
 
@{N="DRS Migration Threshold";E={
   
if($_.DrsEnabled){
   
$x = $_.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
   
$t = @()
   
$fa = @()
   
$priorities = 1..(6 - $x) | %{
     
$t += $_
     
if($_ -eq (6 - $x)){
       
if($fa.Count -eq 0){
         
$f = "Apply priority {0}"
        }
       
else{
         
$f = "Apply priority $([string]::Join(', ',$fa)) and {$($_ -1)}"
        }
      }
     
else{
       
$fa += "{$($_ -1)}"
      }
    }
   
$f -f $t}
   
else{"na"}}}

I also added the HAEnabled property, you can use this one to test of HA is enabled or not when fetching the other properties you mentioned.

Similar to what I did with the DrsEnabled property.


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

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso
Jump to solution

Sorry Luc I am kind lost, in DRS property we are checking the vMotion rate and based on the value we are writing the output,

But for HA, if its enabled the other property gives the result as true or false, I am unable to get the correct syntax for this testing. Would you mind getting a code for a property  

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster | Select Name,
 
HAEnabled,
 
@{N="HAFailoverLevel";E={
   
if($_.HAEnabled){$_.HAFailoverlevel}else{"na"}}},
 
DrsEnabled,
 
@{N="DRS Migration Threshold";E={
   
if($_.DrsEnabled){
   
$x = $_.Extensiondata.ConfigurationEx.DrsConfig.VmotionRate
   
$t = @()
   
$fa = @()
   
$priorities = 1..(6 - $x) | %{
     
$t += $_
     
if($_ -eq (6 - $x)){
       
if($fa.Count -eq 0){
         
$f = "Apply priority {0}"
        }
       
else{
         
$f = "Apply priority $([string]::Join(', ',$fa)) and {$($_ -1)}"
        }
      }
     
else{
       
$fa += "{$($_ -1)}"
      }
    }
   
$f -f $t}
   
else{"na"}}}


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

Reply
0 Kudos