Last year I wrote an article called Automating Storage DRS & Datastore Cluster Management in vSphere 5 and I provided a pretty comprehensive vSphere SDK for Perl script to help administrators automate Storage DRS configurations. These past few months I have noticed an increase in interest on the VMTN developer forums relating to Storage DRS. Majority of the questions has been related to which vSphere API methods to use and how to use these methods for cloning VMs to datastore clusters.

If you have cloned a VM before, the underlying vSphere API method being used is the CloneVM_Task(), but when cloning a VM to a datastore cluster, a different API must be used.

In vSphere 5, VMware introduced several new API methods in the StorageResourceManager and the two specific ones relating to provisioning VMs are RecommendDatastores() and ApplyStorageDrsRecommendation_Task(). The process to clone a VM to a datastore cluster is a two step process:

  1. Call RecommendDatastores() which accepts very similar input as the CloneVM_Task(). In addition, you need to specify the datastore cluster also known as a Storage Pod in the vSphere API as well as the "type" (create, clone, relocate, reconfigure), in this example we will be performing a clone operation. This method will then generate a recommendation on where to place the VM which is based on the SDRS placement engine. No provisioning will occur at this point, just a placement recommendation.
  2. To perform the actual provision of the VM, you will need to call ApplyStorageDrsRecommendation_Task() which accepts a recommendation ID that was generated from the first step. Once the recommendation is applied, the provisioning of the VM will start just like it did when you called the CloneVM_Task().

Note: The RecommendDatastores() will return multiple recommendations, the best one will be first entry in the array. This is the same algorithm used when performing this same operation in the vSphere Client, it also selects the first recommendation.

Now that we understand how the APIs work, let's take a look at how we can leverage this in a script for some automation! Here is a simple vSphere SDK for Perl script called datastoreClusterVMProvisioning.pl which allows you to clone an existing VM onto a datastore cluster. You will need a system that has vCLI 5.0 installed or you can use VMware vMA 5 to run the script. You will also need to connect to a vCenter Server 5 for all SDRS operations.

The script requires 4 input parameters:

  • vmname - Name of the VM you wish to clone from
  • clonename - Name of the cloned VM
  • vmfolder - Name of a vCenter folder 
  • datastorecluster - Name of a datastore cluster

Here is a screenshot of cloning an existing VM onto a datastore cluster:

The script is pretty straight forward and it can easily be adapted to include other configurations as required in your own environment.

Hopefully this gives you a better idea on how to leverage the new provisioning APIs for Storage DRS and start automating your VM deployments onto datastore clusters and get the benefits Storage DRS in your vSphere environment.

15 thoughts on “VM Provisioning on Datastore Clusters in vSphere 5

  1. Hm, why can’t you just call the RecommendDatastores() and then stuff that result into the usual clone task as the datastore?

    • @MC Not sure I understand what you mean by usual clone task? As the article mentions, provisioning onto a Datastore Cluster requires a different set of methods, not your usual CloneVM_Task(). It must be done as described above.

  2. Sorry, that was more a comment on the API itself. It’s unfortunate it requires completely different calls just because of the storage target“ Thx for the working example of how to deal with it!

  3. William, did you have any luck with RecommendDatastores & reconfigure (add disk to be specific)? It keeps crapping out with InvalidRequest.

    -SP

    • I’m also very interested to know how to add a disk to a vm upon deployment. I am able to get it to reconfigure the CPU and the ram, even add an additional scsi controller. I try to add the disk and it just seems to ignore my request to add the drive.

      -CH

  4. Hi
    When I am giving vmname as a template name, I get Error

    Storage DRS placement: vm current host not connected to pod

    Any help is appreciated.

    Thanks,
    Ajay

    • Thanks for your reply.
      It’s working with a regular VM but not with a template. Any pointers that I can explore further?

      Thanks,
      Ajay

    • If you perform the operation deploying from a VM Template to Datastore Cluster and watch the Onyx output, you’ll see that you just need to specify the VM Template as the source “ nothing you need to change. Would recommend taking a look at Onyx to help you with the code

    • Greetings, and thanks for this script, it helped me a lot.

      To use it to deploy a VM from a template, you need to specify a resource pool to the VirtualMachineRelocateSpec, as it is a required parameter in that case.

      I’m using the ESX cluster’s root pool for that (grabbing $clusterName as a parameter) :

      my $clusterView = Vim::find_entity_view(view_type => ‘ClusterComputeResource’, filter => {name => $clusterName});
      my $location = VirtualMachineRelocateSpec->new(pool => $clusterView->resourcePool);

      Regards,

      Daniel

  5. I realize you’re focused on the perl SDK here.

    Is there any chance you are familiar with a Power CLI cmdlet to retrieve a reference to StorageResourceManager?

  6. Hi,

    I am trying to create new baremetal VM on datastore cluster using JAVA SDK.

    That needs filepath & datastore information to be specified in different backing infos
    e.g.
    VirtualMachineFileInfo,
    VirtualCdromIsoBackingInfo,
    VirtualDiskFlatVer2BackingInfo etc.

    Since I just know the name of datastorecluster i want to deploy VM on, and have no idea which datastore in that cluster will be finally selected to deploy that VM, i am not sure what values to specify there.

    API does not accept datastore cluster’s (StoragePod’s) details at that place. If i leave those parameters unset, vmware API throws exceptions as its mandatory.

    Does anyone has any idea about this?

    Any sort of help will be appreciated,

    Thanks,

    • I am having the same problem with the perl SDK and cannot figure out how to make the create task work without having those same properties. Did you figure it out in the Java SDK?

  7. Hello William!
    We are trying to utilize your script, to clone to the datastorecluster.
    However we have an error we cant figure out what causes it:
    Cloning “sdktemp1″ to “del1000″ onto “cl_ds1″
    Error:
    SOAP Fault:
    -----------
    Fault string: The operation is not supported on the object.
    Fault detail: NotSupported

    This is on vSphere 5.5 and SDK 5.5 as well.

    One theory the System guy who deals with the VMware infrastructure has, is that it is related to not having the FullyAutomated setting, anywhere in the configuration specifications for the clone.
    I have been looking hard into the objects related to the calls in your script, and their API reference, and I cant find any way this setting could be set in the relevant object (it doesnt exist in those objects).

    Could you please advice on this?

  8. Hi William,

    I understand cloning virtual machine on datastore cluster is possible using recommendDatastores & storagePlacementSpec. But my doubt is whether this is applicable for bare metal virtual machine also ? Basically cloneVMTask() can be replaced by recommendDatastores & applyStorageDrsRecommendationTask. Is it possible to do the same with createVMTask() also?

    Since is looking for basic mandatory parameter of vm* , i am not sure with createVMTask where we don’t have template or vm name in place.

    Requesting your help on this.

Thanks for the comment!