vMSC Site Affinity

Hi,

This is my first real post, so cut me some slack and don't be prejudiced :).

I wrote a simple powershell script to set "VM Site Affinity" within a VMware vSphere Metro Storage Cluster environment.

Please also take a look at this paper [^n] from VMware by Duncan Epping [^n]. This technical paper explains, amongst many other stretched/metrocluster settings, how and why site affinity is important and preferred!


### What does it do? The script sets a VM-to-Host soft affinity rule (should not must) in a vMSC scenario where site affinity is preferred, based on the configured datastores per site in a stretched environment. And is designed to run periodically (from every 5 minutes to one time a day).

It sets DRS Host groups and DRS VM groups for all existing clusters in a stretched datacenter and creates DRS Rules with soft VM-to-Host affinity based on the VM's used datastores. The scripts needs to know the ESXi Hosts per site and datastores per site; see the VARS section below. It also mails you a report if needed every runtime and tells you which VM's use datastores from both sites.
Only works with two sites!

Next step probably is adding support for Tags and Folders.
Let me know what you think of it and where it needs improvement or extra features!

``` ### VARS $reportemailserver = 'mailserver.local' $reportemailsubject = 'vMSC Site Affinity' $reportemailadresfrom = 'vMSC@local' $reportemailadresto = 'jsanten@local' $vcenterserver = 'algpvcenter.local' # (single vcenter)

Site names (suffix for DRS groups/rules)

$SiteA_name = '_MER A'
$SiteB_name = '_MER B'

comma seperated datastores, datastore clusters per site

$siteA_datastores = 'nfsvm_01a_ds01_tier1','nfsvm_01b_ds02_tier1'
$siteB_datastores = 'nfsvm_02a_ds03_tier1','nfsvm_02b_ds11_tier2'

comma seperated esxi hosts per site

$siteA_hosts = 'algpvmesx01.local','algpvmesx03.local','algpvmesx05.local'
$siteB_hosts = 'algpvmesx02.local','algpvmesx04.local','algpvmesx06.local'

$doReport = $True # Option to report/mail
$logfile = "c:\test.log"
$RunDRS = "1" # 0 for no, 1 for yes to run DRS immediately afterwards

</font>

<br/>
### Code
[Github - vMSC Site Affinity.ps1](https://github.com/janjaaps/powershell/blob/master/VMWare/vMSC_Site_Affinity.ps1) [^n]
<script src="https://gist.github.com/janjaaps/24cfcab0b424ffaf410e.js"></script>

<font size=3>
<b>notes & links</b>
[^n]: Techpaper http://www.vmware.com/files/pdf/techpaper/vmware-vsphere-metro-storage-cluster-recommended-practices.pdf
[^n]: Blog Duncan Epping http://www.yellow-bricks.com/
[^n]: the bits https://github.com/janjaaps/powershell/blob/master/VMWare/vMSC_Site_Affinity.ps1
</font>

SHARE THIS POST

Jan Jaap van Santen

 the Netherlands    http://bit.ly/1Zu0KuL

 IT Specialist/Architect Started around the age of 10, which gives me over 20 years of IT experience. I play the drums and automate the house with a bunch of Pi's.