Monthly Archives: October 2014

Script to throttle mass vMotions or svMotions

I wrote the shell of this as new datastores were added to environments and we rearranged VMs, and it got a little better each time until I finally made it a full function when we were going to migrate to new storage arrays in a few separate environments.

It’s purpose is to make sure not too many of my storage vMotions are running at once and impacting other VMs.  It sits in the middle of your script or one-liner pipeline.  It looks at the active tasks and counts how many storage or host vMotions are running.  If more than the throttle limit are running the script sleeps for a bit and checks again.  If less than the limit are running then it exits, passing control to the next action.

You  can configure counting running (s)vMotions at the vCenter or cluster level, the number of (s)vMotions allowed to be running at once, and the sleep interval.

I found the cluster option handy because we have multiple clusters in each vCenter connected to separate storage so the IO load in one cluster doesn’t impact other clusters.  If a host is put into maintenance mode and 20 vMotions are queued in one cluster the storage vMotions in another cluster can keep going.

It’s a bit long to post the code inline so I’m only using the github link.