Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 178304

VM - Host-DS Affinity/Stretched cluster environment

$
0
0

Hi,


We have a stretched cluster active/active. We need to ensure VM's are running on their local SAN storage as such.  DRS is Automated so VM/host affinity is fine. I found a script that works against another smaller vSphere 5.5 estate, but the below does not work for my larger vSphere 6.0 estate.

 

Each host has a three letter prefix of its data center as do the Datastores. So each DC relates to its Host and VMFS DS.

 

I also need to exclude multiple servers  not just one. At the end of it, an output in an email of a VM that is running across the DC link out of its neighboring SAN is what I want to achieve.

Is the script incorrect for vSphere 6, how is the best way to troubleshoot step by step and ensure the formatting is correct to achieve the correct results? Help appreciated

 

 

 

$vms = Get-View -ViewType VirtualMachine -Property Name,Datastore,"Runtime.Host",  "Runtime.PowerState"

#

#

$emailbody = foreach($vm in $vms){

    if ($vm.Name -ne "vM name" -and $vm.Name -ne "balh")

    {

       if ($vm.Runtime.PowerState -eq "poweredOn")

       {

        $esx = Get-View $vm.Runtime.Host -Property Name

        if ($esx.Name.Split('.')[0] -ne "rara" )

        {

            $ds = Get-View $vm.Datastore -Property Name

            if ($ds | where {$_.Name.Substring(1,3) -notmatch $esx.Name.Substring(0,3)})

          

            {

         

              

                       $vm | Select Name,

                        @{N="Host";E={$esx.Name.Split('.')[0]}},

                        @{N="DataStore";E={[string]::Join(',',($ds | %{$_.Name}))}} | out-string

 

 

 

#write-host $emailbody

              

            }

        }

        }

    }

}

 

 

$MailSender = "xx"

$MailSmtpServer = "aa"

$MailSendingTo = "rar"

 

 

 

 

if ($emailbody)

 

 

{

 

 

write-host "These VMs are misconfigured and will fail during an outage of either data center, and they will fail with an outage of the link between data centres.  Fix the VMware DRS rule on $MailSender so these VMs run on host and disks in the same data center.  These VMs with disks and hosts spanning two locations are at risk of needless loss of service to our customers:

 

 

$emailbody"

 

 

$emailbody2 = "These VMs are misconfigured and will fail during an outage of either data center, and they will fail with an outage of the link between data centres.  Fix the VMware DRS rule on $MailSender so these VMs run on host and disks in the same data center.  These VMs with disks and hosts spanning two locations are at risk of needless loss of service to our customers:

 

 

$emailbody"

 

 

 

Send-MailMessage -from $MailSender -to $MailSendingTo -subject "alert: VM Host/Disk affinity violations" -body $emailbody2 -smtpServer $MailSmtpServer

 

 

}

 

 

else

 

 

{

 

 

write-host "ok: host/datastore affinity is correct for all VMs in $MailSender"

 

 

$emailbody2 = "host/datastore affinity is correct for all VMs in $MailSender"

 

 

 

Send-MailMessage -from $MailSender -to $MailSendingTo -subject "ok: no VM Host/Disk affinity violations" -body $emailbody2 -smtpServer $MailSmtpServer


Viewing all articles
Browse latest Browse all 178304

Trending Articles