I am trying to cloneVM in SDRS Cluster. It lists 3 recommendations. But while assigning, it throws the following error.
Tried both of them and both throws the same error.
Task cloneTask = rd.applyStorageDrsRecommendation_Task(strs);
Task cloneTask = rd.applyStorageDrsRecommendationToPod_Task(sp, strs[0]);
it throws "A specified parameter was not correct. Key"
Output of the 3 recommendations :
1)
103852
1
storagePlacement
Satisfy storage initial placement requests
V1
2)
103854
1
storagePlacement
Satisfy storage initial placement requests
V1
3)
103856
1
storagePlacement
Satisfy storage initial placement requests
V1
StoragePod sp = (StoragePod) new InventoryNavigator(rootFolder).searchManagedEntity("StoragePod", ds.getDatastoreClusterName() );
ManagedObjectReference rd1 = service.getServiceContent().getStorageResourceManager();
StorageResourceManager rd = new StorageResourceManager(service.getServerConnection(), rd1 );
StorageDrsVmConfigInfo vmconfigInfo = new StorageDrsVmConfigInfo();
vmconfigInfo.setBehavior("automated");
VmPodConfigForPlacement vpcfp = new VmPodConfigForPlacement();
vpcfp.setStoragePod(sp.getMOR());
vpcfp.setVmConfig(vmconfigInfo);
StorageDrsPodSelectionSpec sdpss = new StorageDrsPodSelectionSpec();
sdpss.setStoragePod(sp.getMOR());
sdpss.setInitialVmConfig(new VmPodConfigForPlacement[]{vpcfp});
VirtualMachineCloneSpec spec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec locationSpec = new VirtualMachineRelocateSpec();
locationSpec.setPool(pool.getMOR());
spec.setLocation(locationSpec);
StoragePlacementSpec sps = new StoragePlacementSpec();
sps.setCloneName(siInf.getVmName());
sps.setType("clone");
sps.setPodSelectionSpec(sdpss);
sps.setVm(template.getMOR());
sps.setFolder(rootFolder.getMOR());
sps.setCloneSpec(spec);
ServerConnection sc = service.getServerConnection();
VimPortType vpt = sc.getVimService();
StoragePlacementResult spr = vpt.recommendDatastores(service.getServiceContent().getStorageResourceManager(), sps);
ClusterRecommendation[] crs = spr.getRecommendations();
String[] strs = new String[1];
for (int i = 0 ; i < crs.length ; i++)
{
ClusterRecommendation cr = crs[i];
System.out.println(cr.getKey());
System.out.println(cr.getRating());
System.out.println(cr.getReason());
System.out.println(cr.getReasonText());
System.out.println(cr.getType());
strs[0] = cr.getKey();
}
//Task cloneTask = rd.applyStorageDrsRecommendation_Task(strs);
Task cloneTask = rd.applyStorageDrsRecommendationToPod_Task(sp, strs[0]);
String result = cloneTask.waitForTask();
if(result.equalsIgnoreCase("error"))
{
String errorMsg = cloneTask.getTaskInfo().error.getLocalizedMessage();
}