Hi there,
we try to change our deployment scripts from old cloneVm to new recommendDatastores. We need this to provision VMs to SDRS Clusters. As documented within API reference, old CloneVm was now replaced by VcStorageResourceManager.recommendDatastores:
Now we build the following scriptable task:
var myVcVirtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
var myVcResourceAllocationInfo = new VcResourceAllocationInfo();
var myVcStoragePlacementSpec = new VcStoragePlacementSpec();
var myVcStorageDrsPodSelectionSpec = new VcStorageDrsPodSelectionSpec();
var myVcStorageResourceManager = input_Datacenter.sdkConnection.storageResourceManager();
var myVcRessourcePool = input_RessourcePool;
var myVcVirtualMachineCustomSpec = input_VirtualMachineCustomSpec;
myVcStorageDrsPodSelectionSpec.storagePod = input_StoragePod;
myVcVirtualMachineRelocateSpec = System.getModule("com.vmware.library.vc.vm.spec").getRelocateSpec(null,null,null,myVcRessourcePool,null) ;
myVcVirtualMachineCloneSpec = System.getModule("com.vmware.library.vc.vm.spec").getCloneSpec(null,myVcVirtualMachineCustomSpec,myVcRessourcePool,false,false) ;
myVcStoragePlacementSpec.cloneName = input_VirtualMachineName;
myVcStoragePlacementSpec.cloneSpec = myVcVirtualMachineCloneSpec;
myVcStoragePlacementSpec.folder = input_Folder;
myVcStoragePlacementSpec.podSelectionSpec = myVcStorageDrsPodSelectionSpec;
myVcStoragePlacementSpec.resourcePool = myVcRessourcePool;
myVcStoragePlacementSpec.type = VcStoragePlacementSpecPlacementType.clone;
myVcStoragePlacementSpec.vm = input_Template;x = input_Datacenter.sdkConnection.storageResourceManager.recommendDatastores(myVcStoragePlacementSpec);
System.warn("Recommend Result: " + x);
System.warn("recommendations.key: " + x.recommendations.key);
System.warn("recommendations.reason: " + x.recommendations.reason);
System.warn("recommendations.reasontext: " + x.recommendations.reasonText);
System.warn("recommendations.action: " + x.recommendations.action);
System.warn("recommendations.target: " + x.recommendations.target);
System.warn("recommendations.type: " + x.recommendations.type);
System.warn("recommendations.dynamicProperty: " + x.dynamicProperty);
We get no error message and no task is starting. But on displaying all our warnings, they are all undefined without the x which is the correct object:
[2012-10-08 15:04:27.854] [W] Recommend Result: DynamicWrapper (Instance) : [VcStoragePlacementResult]-[class com.vmware.vim.vi4.StoragePlacementResult] -- VALUE : com.vmware.vim.vi4.StoragePlacementResult@6465a5b0
[2012-10-08 15:04:27.854] [W] recommendations.key: undefined
[2012-10-08 15:04:27.854] [W] recommendations.reason: undefined
[2012-10-08 15:04:27.870] [W] recommendations.reasontext: undefined
[2012-10-08 15:04:27.870] [W] recommendations.action: undefined
[2012-10-08 15:04:27.870] [W] recommendations.target: undefined
[2012-10-08 15:04:27.870] [W] recommendations.type: undefined
[2012-10-08 15:04:27.870] [W] recommendations.dynamicProperty: null
Someone ever tried this or has any idea about get this done?
Regards,
Chris
Hi!
the recommendations attribute of the resulting VcStoragePlacementResult is an array.
So you have to get the actual VcClusterRecommendation first (using recommendations.pop() or recommendations[0]......
Cheers,
Joerg
Hi and thank you Joerg,
yes you are right, often it is so simple but you can't see it :smileyblush:.
But it seems not to working fine So I have build a sdrs recommendation now, but within vCenter I can't see this recommendation. And on trying to apply this recommendation:
myVcStoragePlacementResult = input_Datacenter.sdkConnection.storageResourceManager.recommendDatastores(myVcStoragePlacementSpec);
myVcTask = input_Datacenter.sdkConnection.storageResourceManager.applyStorageDrsRecommendationToPod_Task(input_StoragePod, myVcStoragePlacementResult.recommendations[0].key)
I recieve an error message within vCenter which means: "A specified parameter was not correct. key". I can display my myVcStoragePlacementResult.recommendations[0].key which is set as a key string value.
Maybe you can help me one more time?
Best regards,
Chris
Hi Chris,
I don't have a lab to try, but usually these "a specified parameter was not correct" come up when either something is missing in the spec, or a parameter has the wrong type.
For debugging:
You can increase the loglevel in vCO and vCenter, sometimes you get longer stacktraces that pinpoint in the proper direction to find the error. (don't do in production, it might slow down vCO!)
And: make sure that you always instanciate dataobjects before adding them to an array (there is a bug in vCO, noted in the release notes)
Also (as usual:) Onyx might help to figure out whats necessary to do the applyStorageDrsReccomendationToPod_Task().
Cheers,
Joerg
Hi there,
sorry for my late reply. We have it running but I forgott to poste the script we use finaly In the end, it was a declaration error which we forgot.
So here is our deployment action:
VC:Task myDeploymentAction (VC:StoragePod StoragePod, VC:VirtualMachine Template, string VirtualMachineName, VC:VmFolder VmFolder, VC:ResourcePool ResourcePool, Any VirtualMachineCloneSpec, VC:HostSystem HostSystem[optional], Array/Any initialVmConfig[optional])
var storageSpec = new VcStoragePlacementSpec();
var podSelectionSpec = new VcStorageDrsPodSelectionSpec();
var location = new VcVirtualMachineRelocateSpec();
var myVcStoragePlacementResult = VcStoragePlacementResult();
var managedObject = Template.sdkConnection.storageResourceManager;
var myKey = new Array();if ( initialVmConfig[0].storagePod == null )
{
initialVmConfig[0] = new VcVmPodConfigForPlacement();
initialVmConfig[0].storagePod = StoragePod;
}podSelectionSpec.storagePod = StoragePod;
podSelectionSpec.initialVmConfig = initialVmConfig;location.pool = ResourcePool;
storageSpec.type = "clone";
storageSpec.vm = Template;
storageSpec.podSelectionSpec = podSelectionSpec;
storageSpec.cloneSpec = VirtualMachineCloneSpec;
storageSpec.cloneName = VirtualMachineName;
storageSpec.folder = VmFolder;
if ( HostSystem != null )
{
storageSpec.host = HostSystem;
}
myVcStoragePlacementResult = managedObject.recommendDatastores(storageSpec); // StorageResourceManagermyKey[0] = myVcStoragePlacementResult.recommendations[0].key
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
return myVcTask;
Here the HostSystem and the initialVmConfig is optional. We use the optional HostSystem to deploy direct to spezial licensed ESXi hosts. The initialVmConfig is used to modify the virtual machine during the deployment, watch out it is only experimental supported. From our experience everything is working except to extend disks which are part of the template. To add additional disks is no problem.
Thank again to your support Jörg.
Regards,
Chris
Thank you both. That is the information I was looking for as well.
Christian - You mentioned you had a script where you were adding disks using the new SDRS aware method. Could you post an example?
Thanks for sharing the workflow!!
Does this "destroying the template" also happen when you clone and adjust the disk size in the vSphere Client?
(There was a weird bug a lot of versions ago about this... http://communities.vmware.com/thread/170427 and I wonder if that's back)
Cheers,
Joerg
Hi,
Yes this will also happen on clone the vm within vSphere Client.
It is nearly the same error as explained in this thread. If you browse the target datastore, there will be a new vmdk with the correct size. But the vm itself shows the vmdk of the template (as explained in the thread).
Cheers
Thank you very much for sharing your workflow.
Christian, thanks for confirming.
Hey Christian,
Your code seems to be working for me except I can't get the VC:VirtualMachine object that results. With a normal datastore, I do a clone operation and return a task.
Next I have a vim3WaitTaskEnd that, as it's output, sets an attribute of type VC:VirtualMachine so I have my virtual machine object ready to use.
For a datastore cluster this doesn't work. The output of vim3WaitTaskEnd is:
DynamicWrapper (Instance) : [VcApplyStorageRecommendationResult]-[class com.vmware.vim.vi4.ApplyStorageRecommendationResult] -- VALUE : com.vmware.vim.vi4.ApplyStorageRecommendationResult@f295b591
Other than searching for the name of the vm and returning the object that matches the name, is there another way?
Thanks
Hey FreddyFredFred,
yes there is an other way. The result of the vim3WaitTaskEnd is as the log from your code says a object of type: VcApplyStorageRecommendationResult. If the task was successful, your new provisioned VM is: VcApplyStorageRecommendationResult.vm.
So simply built a new scriptable task, where you set the action result of vim3WaitTaskEnd as input (maybe 'myVcTaskResult') and as output the VM object (maybe 'myVcVirtualMachine') and your VM will be: myVcVirtualMachine = myVcTaskResult.vm;
Cheers, Chris
Hi
Any chance someone could provide a bit of an outline on how to implement this code. I am a newbie at this and most examples I have Google-ed are too simplistic. I am not sure how you would implement this with a VMClone task as far as sequencing goes as well at parsing the input and output from one action to the next.
Thanks
I've been banging my head against the wall for a few days now trying to deploy to an SDRS cluster. Finally got there with the help of this post and this one here: Re: Creating custom workflow for deployment - NEED HELP
With regards to Freddys and Christians last comments regarding capturing the newly created VM as an output parameter, I thought I'd detail what I did as I found it a little confusing when I read the post. As already stated, in order to return the new virtual machine object after deploying to an SDRS cluster, you should use the 'vim3WaitTaskEnd' action after running the code above in a scriptable task (or action) which provisions the VM to an SDRS cluster. I used the vcTask output from the deployment script above (return myVcTask) as input for the wait action. My confusion came over what type of variable was to be used as an output for the wait action. In the end I realized that I had to create another variable (myVMOutput for example) with a type of 'Any' and I set that as the output for the wait action. Next I did as Christian detailed, I created a scriptable task where the input is the myVMOutput and the output is a myNewVM variable of type 'VirtualMachine', with the code: myNewVM = myVMOutput.vm;
Apologies if the posts above seemed obvious. It took me a few hours to get it working so thought I'd share my pain! Thanks again Christian and Freddy.
I know this is an old thread, But im using this to extend disks using sdrs and realized it only does sdrs if adding a new disk and not when expanding a disk. The code for extend is actually different then adding and the issue is that the code to get recommendations is commented out:
//myKey[0] = myVcStoragePlacementResult.recommendations[0].key
//myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
so all it is doing is expanding through a reconfig:
VirtualMachine.reconfigVM_Task(myVcVirtualMachineConfigSpec);
I tried with the commented code but it doesnt return any recomendations (null) so I am guessing that is why it is commented out. Has anyone figured out a way to get it to work expanding with sdrs?
JC
Hi JC,
I use a method to extend virtual disks of VMs on datastore clusters without using the storage pod entity.
Essentially the code retrieves the virtual disk object of the virtual disk I want to extend (vcVirtualDisk), changes the specification of the disk (vcVirtualDeviceConfigSpec) and initiates a reconfigVM_Task of the VM.
var vcVirtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec();
var vcVirtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
var vcVirtualDeviceConfigSpecArray = new Array();
diskSize = diskSize * 1024 * 1024;
if ( vcVirtualDisk.capacityInKB != diskSize )
{
vcVirtualDisk.capacityInKB = diskSize;
vcVirtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
vcVirtualDeviceConfigSpec.device = vcVirtualDisk;
vcVirtualDeviceConfigSpecArray.push(vcVirtualDeviceConfigSpec);
}
vcVirtualMachineConfigSpec.deviceChange = vcVirtualDeviceConfigSpecArray;
vcTask = vm.reconfigVM_Task(vcVirtualMachineConfigSpec);
Inputs: vm, vcVirtualDisk, diskSize
Outputs: vcTask
Give that a go.
Flex
Thanks, but I need it to move based on SDRS. If the datastore the vm is on has no space, I need it to do SDRS if possible to find space and expand.
Ah yes didn't read your original query properly.
As far as I'm aware, I don't think you can code vCO to apply SDRS recommendations when extending disks. This is because vSphere does not produce SDRS recommendations itself when a virtual disk is extended manually.
Remember that as far as automating vSphere tasks goes, only tasks that can be done manually in vSphere can be automated with vCO. When extending disks manually in vSphere, SDRS recommendations are not produced. Only when adding new disks, as you already mentioned.