4

We have a VMware cluster that doesn't have SDRS enabled. We would like to know when a VM moves to a particular datastore on that cluster because that datastore is non-performance storage.

I can't find a datastore alarm or other type of alert that would notify me when someone does a storage vmotion to this datastore. Nor can I find an affinity rule or similar to prevent someone from moving certain VMs to this datastore.

Anyone know of a way to accomplish this without SDRS?

ewwhite
  • 194,921
  • 91
  • 434
  • 799
TheCleaner
  • 32,352
  • 26
  • 126
  • 188
  • 3
    This isn't a complete answer, so posting as a comment. I know that the associated datastore(s) is stored in the metadata for each instance, so couldn't you just use one the API for your favorite language and periodically walk through the VM tree and identify any of them that are new to your target datastore? – EEAA Feb 08 '16 at 23:25
  • 1
    If the cluster in question doesn't have SDRS enabled, how would a VM end up there without someone doing it manually? – GregL Feb 09 '16 at 00:28
  • @GregL - that's exactly how it would happen. Problem is that while I can tell the admins "DON'T!" they conveniently forget. – TheCleaner Feb 09 '16 at 14:51
  • 1
    Ah.. Right then. I'm just looking at the possible triggers for an alarm on a Datastore, and the conditional alarm that might work is "File or directory moved to datastore". Alternatively, maybe set a "Datastore Disk Usage (%)" or "Datastore Disk Provisioned (%)" alarm for a certain value so that you know if anything gets moved there. – GregL Feb 09 '16 at 15:21
  • @GregL - yep that would probably work as well on disk provisioned %...didn't even think about that. But the script works well enough for my need. If you want to create an answer I'll upvote it based on the comment though. – TheCleaner Feb 09 '16 at 15:57

3 Answers3

4

A good solution for this would be to use VMware's Storage Policy-Based Management with tags. There may be vendor specific capabilities that you could also take advantage of but as tags are vendor agnostic I'll use those to explain how policies can be leveraged.

A minimal approach would be:

  1. Create a tag category (storage-performance) with two tags (performance, non-performance).
  2. Tag each datastores with one of the tags depending on the "type" of storage
  3. Create two storage policies (performance, non-performance) and use a tag based rule for the policy. For example the performance policy is compatible with datastores with the performance tag. When creating the policy you will be able to see which datastores are compatible with the policy
  4. Associate the desired storage policy with the virtual machines

What this will do is ensure that the users will be warned if they try to migrate a VM to datastore that will not support the VM's policy. If the user ignores this warning then the VM will be marked as out of compliance.

BenM
  • 748
  • 1
  • 8
  • 13
2

In looking at the possible triggers for a Datastore alarm, a few possibilities exist.

For conditionals, you could use:

  • Datastore Disk Usage (%)
  • Datastore Disk Provisioned (%)

While for events these might work:

  • File or directory copied to datastore
  • File or directory moved to datastore

The former two would require you to have known numbers, just above which you'd set the threshold.

The latter two might not even work depending on whether or not an svMotion counts as files being copied/moved to the datastore.

GregL
  • 9,030
  • 2
  • 24
  • 35
1

I went where EEAA was heading and just ended up with a simple PowerCLI provided from here.

and set the "-ge" equal to 1 since the datastore in question should only house the one VM it is intended for.

I have that set to run on our administrative server twice a day.

It doesn't really answer the question itself of when a VM moves to a particular non-SDRS datastore, but it is a workaround that gets me close enough to knowing. Plus it only emails me when the potential that it has happened occurs. And if the admins mess up and then move the VM back before the script runs that's ok.

Code here for posterity:

#
# PowerCLI script to send e-mail if the number of virtual machines per datastore exceeds 48
# Version 1.0
# Magnus Andersson, Real Time Services AB
#
#
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
#
#
# Get login password
$pwd = Get-Content d:vspherescriptspowerclicred | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential “homedomainpowercli“, $pwd
#
#
# Connect to vCenter Server
connect-viserver vc-demo01.home.test
#
#
$sendTo = “magnus@home.test“
$ds = get-datastore
foreach ($datastore in $ds){
$num = Get-Datastore $datastore | Select @{N=”TotalVMs”;E={@($_ | Get-VM ).Count}}
if ($num.TotalVMs -ge 48) {
send-mailmessage -to $sendTo -from vc-demo01@home.test -Subject “Number of VMs per datastore $datastore is” -smtpserver smtp.home.test -body $num.TotalVms
}
else
{
}
}
#
TheCleaner
  • 32,352
  • 26
  • 126
  • 188