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 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.

20 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.


    • 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.


    • Hi William,

      Even i would like to add disk , with RecommendDatastores & reconfigure . Its failing with below error :

      2015-05-20T07:19:13.846Z [7F13211F3700 info ‘commonvpxLro’ opID=4c4f70e9] [VpxLRO] — BEGIN task-internal-171354 — — vim.StorageResourceManager.recommendDatastores — 3103693e-f972-e4e8-8bb5-4982e2edabf6(52500cdd-14b4-e652-57c3-46119bfeeb97)
      2015-05-20T07:19:13.858Z [7F13211F3700 info ‘drmLogger’ opID=4c4f70e9] [VpxVmdkStatTable::GetHistoricalStats] historical stats for scsi0:0 not found in the map
      2015-05-20T07:19:13.868Z [7F13211F3700 info ‘drmLogger’ opID=4c4f70e9] [VpxVmdkStatTable::GetHistoricalStats] historical stats for scsi0:1 not found in the map
      2015-05-20T07:19:13.880Z [7F13211F3700 info ‘drmLogger’ opID=4c4f70e9] [CreateDrmDisksForVmSet] Processed 22 vms
      2015-05-20T07:19:13.881Z [7F13211F3700 error ‘drmLogger’ opID=4c4f70e9] [FindDiskByKey] Device -100 is not a disk
      2015-05-20T07:19:13.889Z [7F13211F3700 info ‘commonvpxLro’ opID=4c4f70e9] [VpxLRO] — FINISH task-internal-171354 — — vim.StorageResourceManager.recommendDatastores —
      2015-05-20T07:19:13.889Z [7F13211F3700 info ‘Default’ opID=4c4f70e9] [VpxLRO] — ERROR task-internal-171354 — — vim.StorageResourceManager.recommendDatastores: vmodl.fault.InvalidArgument:
      –> Result:
      –> (vmodl.fault.InvalidArgument) {
      –> dynamicType = ,
      –> faultCause = (vmodl.MethodFault) null,
      –> invalidProperty = “StoragePlacementSpec.diskPodLocation.diskId”,
      –> msg = “”,
      –> }
      –> Args:

      I am adding the new disk , not sure why its looking for the valid diskid.

      If i try with diskId as 2000, 2001 series ..

      2015-05-20T08:38:45.363Z [7F1320D68700 info ‘commonvpxLro’ opID=4b4030fd] [VpxLRO] — BEGIN task-internal-171982 — — vim.StorageResourceManager.recommendDatastores — 3103693e-f972-e4e8-8bb5-4982e2edabf6(52500cdd-14b4-e652-57c3-46119bfeeb97)
      2015-05-20T08:38:45.363Z [7F1320D68700 error ‘vpxdvpxdMoStorageResourceManager’ opID=4b4030fd] [SanityCheckPodSelectionSpec] File backing not found for disk 2000 on pod vim.StoragePod:group-p544
      2015-05-20T08:38:45.363Z [7F1320D68700 error ‘vpxdvpxdMoStorageResourceManager’ opID=4b4030fd] [SanityCheckStoragePlacementSpec] PodSelectionSpec does not match ConfigSpec
      2015-05-20T08:38:45.371Z [7F1320D68700 info ‘commonvpxLro’ opID=4b4030fd] [VpxLRO] — FINISH task-internal-171982 — — vim.StorageResourceManager.recommendDatastores —
      2015-05-20T08:38:45.371Z [7F1320D68700 info ‘Default’ opID=4b4030fd] [VpxLRO] — ERROR task-internal-171982 — — vim.StorageResourceManager.recommendDatastores: vmodl.fault.InvalidArgument:
      –> Result:
      –> (vmodl.fault.InvalidArgument) {
      –> dynamicType = ,
      –> faultCause = (vmodl.MethodFault) null,
      –> invalidProperty = “StoragePlacementSpec.podSelectionSpec and configSpec”,

      Can you share your thoughts on this. I couldn’t find KB article related to this ..

      • I have tried to clone a vm from a template, I also sent the disk id as 2000 it did not work. Later I removed the disks from PodDiskLocator in initial vm config. It worked for me. In order to do a reconfigure I guess U need to give the key as -1 not 2000. Please try with -1.

  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 for your reply.
      It’s working with a regular VM but not with a template. Any pointers that I can explore further?


    • 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);



  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
    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,


    • 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”
    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.

  9. Hi Wiliam,

    Can we use RecommendDatastores() to get a list of recommended datastore names directly, using the call I get an object of StoragePlacementResult through which I can get a reference to StoragePod but however unable to fetch the exact datastore recommended. I would not like to use RecommendDatastores() in combination with ApplyStorageDrsRecommendation_Task(). I would just like to fetch the list of datastores recommended by SDRS.

    Please let me know if we can achieve this. Thanks.

  10. Hi William,

    We want to use the API to create a linked clone using datastore cluster.
    We are able to create a linked clone using datastore, but unable to do it using datastore cluster.
    Can u pls provide some pointers for the same?

  11. Hi All

    I was trying to add new disk to existing vm which exists on ‘Datastore cluster’, it is failing with below error

    can anyone help? A specified parameter was not correct.

Thanks for the comment!