vSphere 5 Top 10 – Storage DRS

During our presentation at the Dutch VMUG Event 2011, Alan and myself showed how several entries of the Top 10 vSphere 5 Features session could be automated with the help of PowerCLI. In the session we showed several demos.

This post is the first in a series, that will publish and document most of the scripts we used for the demos.

On the first position in the Top 10 we have Storage DRS. This feature brings intelligent placement of VMs and storage load balancing based on space usage and IO metrics. See part 4, part 5 and part 6 in Cormac‘s excellent series on vSphere 5 Storage Features.

In the current PowerCLI version (5, build 435426) there is apparently only 1 cmdlet that works with Datastore Clusters, the Get-DatastoreCluster cmdlet. Unfortunately the cmdlet doesn’t seem to provide everything we came to expect from the regular PowerCLI objects. There is for example no ExtensionData property that would give us access to the server-side object for a Datastore Cluster.

The other basic actions (create, remove, configure) around Datastore Clusters are, for the time being, unfortunately missing from PowerCLI. And as you might have guessed, I felt the need to have some functions in my toolkit, that would allow me to do some basic stuff with Datastore Clusters.

The functions

Please note that the VMware vSphere API Reference refers to a Datastore Cluster as a StoragePod.

Annotations

Line 73: To configure a DatastoreCluster we need the StorageResourceManager

Line 76-82: A kind of Object By Name logic. This will allow the function to access the Pod parameter as a Name in a string, or as an object returned by the Get-DatastoreCluster cmdlet or as a StoragePod object.

Line 83-84: The Set-DatastoreCluster function can be used to change settings of the DatastoreCluster but also to add Datastores to the DatastoreCluster. To avoid calling the ConfigureStorageDrsForPod method when no settings have to be changed, these lines check if only the Datastore parameter was passed.

Line 85-119: These lines set up the parameters for the call to the ConfigureStorageDrsForPod method. Since the script calls this method in ‘incremetal’ mode, we only set the properties in the StorageDrsConfigSpec object that are actually set. Hence all the tests in this part of the code.

Line 122-130: This part of the function adds the Datastores to the DatastoreCluster with the MoveIntoFolder method.

Line 133: Since we want to use the functions in pipeline constructs, the function places the DatastoreCluster in the pipeline as a StoragePod object.

Line 186-207: Note that the New-DatastoreCluster function uses all the defaults that are defined in the description of the StorageDrsConfigSpec object in the VMware vSphere API Reference

Line 209-213: The Object By Name functionality for the Folder parameter.

Line 216: The creation of the DatastoreCluster through the CreateStoragePod method.

Line 218-223: The function calls the Set-DatastoreCluster function.

Line 224-226: When the call passed Datastores, these are added to the DatastoreCluster through a 2nd call to the Set-DatastoreCluster function.

Line 229: Since we want to use the functions in pipeline constructs, the function places the DatastoreCluster in the pipeline as a StoragePod object.

Line 232-276: Normally you don’t need to use this function since there is already the Get-DatastoreCluster cmdlet in PowerCLI. This function returns a StoragePod object and is primarily for internal use. An exception could be when you want to report on properties in your DatastoreCluster that are not in the object returned by the Get-DatastoreCluster cmdlet.

Line 254-269: The function uses a local function called GetStoragePodInternal in order to recursively traverse the vSphere tree.

Line 274: When the function is called with a specific Name, this Where-clause will filter out the desired StoragePod objects.

Line 300-305: A kind of Object By Name logic. This will allow the function to access the Pod parameter as a Name in a string, or as an object returned by the Get-DatastoreCluster cmdlet or as a StoragePod object.

Sample use

The following samples will show you how you can use these functions to set up, configure and remove a DatastoreCluster.

In my testlab I have set up the following simple environment to demonstrate the functions. It consists of 3 VMFS5 datastores that I want to use to create a DatastoreCluster.

First we will create a DatastoreCluster, called DSC, with 2 datastores, DS2 and DS3. The code to do that looks as follows.

The result looks like this

Since we didn’t specify any parameters, besides the datastores, for the DatastoreCluster, the DatastoreCluster took all the defaults. As a guide, this is a table showing the defaults as used in the New-DatastoreCluster function.

Folder datastore
AutomationLevel automatic
 IOMetric True
 SpaceUtilization  80%
 SpaceUtilizationDifference  5%
IOLatency  15
IOLatencyDifference  5
Interval  480

Now we want to add the Datastore DS4 to this DatastoreCluster.

The result.

As a guide to understand which parameter that corresponds with which property, I made the following screenshots.

The General option.

The SDRS Automation option

The SDRS Runtime options

The other settings are currently not implemented in the functions.

The supported parameters can all be changed with the Set-DatastoreCluster function. Something like this for example.

This call changes the SDRS interval to 240 minutes or 4 hours (instead of the default 8 hours). And it changes the Utilized Space threshold to 70% (instead of the default 80%).
To remove a DatastoreCluster, you can do

Enjoy the functions !

7 Comments

    Matt

    Luc,

    Does it work in case, there are multiple datacenters in the VC-inventory ..?

      LucD

      @Matt, do you mean the Get-StoragePod function ? Yes, that should return multiple datastoreclusters.

    Jonathan Marrott

    Any way to do a Move-VM into a Datastore Cluster?

      LucD

      @Jonathan, the current PowerCLI build (5.0.1) only supports Datastore Clusters on the New-VM and the New-Harddisk cmdlets.
      But I suspect that is a vSphere limitation, the RelocateVM_Task method also doesn’t seem to support a Storage Cluster.

    Rick van Wijnen

    Luc,

    Thanks for the excellent presentation at VMUG 2011.
    Another topic I’m very much interested in is your “find the vCenter server” script. Is that powershell script public available?
    We had such event, next time I want to be prepared 🙂

    Thanks again,
    Rick.

      LucD

      @Rick, thanks.
      The “find the vCenter” script has been posted on Alan’s site as VM Start-up script

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

four − 4 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.