Create and delete SDRS Anti-Affinity Rules w/PowerCLi – Part 2

Cover

This is Part 2 of SDRS series.

The Part 1 How to configure Storage DRS clusters w/PowerCLi – Part 1 is here.

Part 3 Reconfigure/Edit SDRS Anti-Affinity Rules w/PowerCLi – Part 3 and may be even Part 4 How to get SDRS History/Actions w/PowerCLi – Part 4 are expected in near future.

This article will cover four new functions: Add-SdrsAntiAffinityRule, Remove-SdrsAntiAffinityRule, Get-SdrsAntiAffinityRule and Invoke-SdrsRecommendation from my PowerCLi Vi-Module module.

Add-SdrsAntiAffinityRule

  • As you remember there are two types of anti-affinity rules: VMDK or Intra-VM and VM or Inter-VM. The function allows to create the both of them.

VMDK anti-affinity rules

  • Create Intra-VM or so-called VMDK anti-affinity rule.

  • Lets take our SDRS cluster and retrieve its current configuration. It makes sense to create Intra-VM rules if DefaultIntraVmAffinity property is equal to KeepTogether only.

Get-DatastoreCluster DEV | Get-SdrsCluster
Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule
  • Now, let’s take a VM which has more than one Hard disk. We shall see all VM disks are located on the same Datastore (the Filename property) before rule creation.
Get-VM vm1 | Get-HardDisk

01.SdrsPart2_Get-SdrsCluster

  • We needn’t use the -Harddisk parameter because we are going to add all VM disks to the rule! Also we will use -Enabled switch to activate the rule. The optional -Apply parameter will apply SDRS recommendations immediately after the rule was created.
Get-DatastoreCluster DEV | Add-SdrsAntiAffinityRule -VM $VmHdd2 -RuleName Rule1 -Enabled
  • Wait for two tasks to complete Configure Storage DRS and Execute Storage vMotion for Storage DRS and check your VM. From now the disks of this VM will never meet on the same Datastore (if it is possible of course Emoj).
Get-VM vm1 | Get-HardDisk
  • Note, the -Apply parameter does not run the rule related recommendations, it runs SDRS cluster aware recommendations! Use it in off hours in Production environments.

VM anti-affinity rules

  • To create Inter-VM anti-affinity rule you have to pass at least two VM to the -VMGroup parameter. Let’s say you have ten VM named from vm100 to vm109 and you want to distribute them across SDRS cluster’s Datastores (in the case your cluster contains enough Datastores for this).
Get-DatastoreCluster DEV | Add-SdrsAntiAffinityRule –VMGroup (Get-VM 'vm10[0-9]') -RuleName Rule2 –Enabled -Apply
  • As a result two rules were created.
  • The returned objects contain the same properties for the both rule types, but for Inter-VM rules the HardDisks property always will be empty because it irrelevant.

  • All core logic of Add-SdrsAntiAffinityRule function taken from Set-SdrsAntiAffinity function, written by famous PowerCLi guru Luc Dekens. I only did some customizations and improvements (in my opinion).

Remove-SdrsAntiAffinityRule

  • You more no need the rule. OK, let’s delete it/them. Just pipeline the rule(s) from my Get-SdrsAntiAffinityRule to Remove-SdrsAntiAffinityRule and confirm what rules to delete.

Get-DatastoreCluster DEV | Get-SdrsAntiAffinityRule | Remove-SdrsAntiAffinityRule
Get-DatastoreCluster DEV, LAB | Get-SdrsAntiAffinityRule InterVM | Remove-SdrsAntiAffinityRule

11.SdrsPart2_Remove-SdrsAntiAffinityRule

  • You will be asked to confirm your intentions on per rule basis unless you used -Confirm:$false. There is possible silently delete all rules in particular SDRS cluster or even in all clusters in Inventory! Please use the -Confirm parameter super carefully. By default, it equals to $true (always prompts).
Get-DatastoreCluster DEV, LAB | Get-SdrsAntiAffinityRule -RuleType InterVM | Remove-SdrsAntiAffinityRule -Confirm:$false
Get-DatastoreCluster | Get-SdrsAntiAffinityRule -RuleType InterVM | Remove-SdrsAntiAffinityRule -Confirm:$false
Get-DatastoreCluster | Get-SdrsAntiAffinityRule VMDK | Remove-SdrsAntiAffinityRule -Confirm:$false
  • At this moment the function knows to remove Inter-VM rules only Emoj, I am working on this…

Invoke-SdrsRecommendation

  • The Invoke-SdrsRecommendation function is a programmatic way to click on Run Storage DRS Now button.

12.SdrsPart2_Invoke-SdrsRecommendation

  • The advantage is ability to run it on multiple/all SDRS clusters.
Get-DatastoreCluster DEV | Invoke-SdrsRecommendation
Get-DatastoreCluster | Invoke-SdrsRecommendation -Confirm:$false

13.SdrsPart2_Invoke-SdrsRecommendation

  • The function returns date of the last action (LastAction property), performed by SDRS engine before giving current recommendations (Refreshed property) and cluster name, of course DatastoreCluster.

14.SdrsPart2_Invoke-SdrsRecommendation

Summary

  • Both the functions Add-SdrsAntiAffinityRule and Remove-SdrsAntiAffinityRule utilize two auxiliary functions: Get-SdrsAntiAffinityRule and Start-SleepProgress, included in the module. The Start-SleepProgress function waits for ten seconds before calling the Get-SdrsAntiAffinityRule.

  • The Get-SdrsAntiAffinityRule is too simple to describe it in the article. Let’s just see some examples.

Get-DatastoreCluster | Get-SdrsAntiAffinityRule
Get-DatastoreCluster DEV* | Get-SdrsAntiAffinityRule –RuleType InterVM
Get-DatastoreCluster DEV, TEST | Get-SdrsAntiAffinityRule VMDK
  • For more details about the functions, please take a look at the content based help and examples.
Get-Command –Noun *sdrs*
Get-Help Add-SdrsAntiAffinityRule -Online
Get-Help Remove-SdrsAntiAffinityRule -Examples
Get-Help Invoke-SdrsRecommendation –Full
Get-Help Get-SdrsAntiAffinityRule

<< Part 1 Part 3 >>

You may also like:

Search-Datastore – Browse/Search VMware Datastores
Set-PowerCLiTitle – Connect-VIServer deep dive
Get-RDM – How to get RDM (Raw Device Mappings) disks
Test-VMHotfix/Test-VMPing – Check VMware VM for installed Hotfixes

2 thoughts on “Create and delete SDRS Anti-Affinity Rules w/PowerCLi – Part 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s