Our system: vSphere 4.0, ESXi 4.0, using PowerCLI 4.0 - but not the PowerShell command line. We're using a C# program that uses the .NET objects that PowerShell uses - not sure how much of a different that makes.
I'm attempt to deploy a VM with thin provisioned disks from a template that has fat provisioned disks, just like in the vSphere client. The particular bit of code that is supposed to control this is as follows (shortened for brevity):
VirtualMachineCloneSpec clonespec = new VirtualMachineCloneSpec();
clonespec.Location = new VirtualMachineRelocateSpec();
clonespec.Location.Datastore = datastore.MoRef;
clonespec.Location.Pool = pool.MoRef;
clonespec.Location.Transform = VirtualMachineRelocateTransformation.sparse;
....
template.CloneVM(targetFolder.MoRef, requestItem.SessionName, clonespec);
Using this code, the resulting VM is always deployed with fat disks, just like the template. I've confirmed - via the vSphere client - that the data storage device being used does support thin provisioned disks.
Does anyone know why this doesn't work?
This definitely works from the vSphere client.
Perhaps use Onyx and check if there is anything missing from your code.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Found my own solution. Reordering the logic seemed to fix the problem. Here was the changed lines that made it work:
irtualMachineCloneSpec clonespec = new VirtualMachineCloneSpec();
clonespec.Location = new VirtualMachineRelocateSpec();
clonespec.Location.Transform = VirtualMachineRelocateTransformation.sparse; // This location seemed to be the key.
clonespec.Location.Datastore = datastore.MoRef;
clonespec.Location.Pool = pool.MoRef;
....
template.CloneVM(targetFolder.MoRef, requestItem.SessionName, clonespec);
And now it works.