Does anyone have any sample code for cloning a VM using the VISDK webservices? I programming in C++ but a Java/C# implementation will help also.
Thanks,
Jan
It can include both existing and newly added disks and other components.
That is correct, you need to make sure the unitNumber is unique, I believe if you pass in "-1" it'll automatically increment the counters for you
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
... I'm having trouble with a FULL CLONE.
Take a look at the vSphere SDK for Perl Utility script vmclone.pl which is part vCLI installation that includes a complete working clone script for a VM. You can go through the script and it'll show you which calls to the API is required to perform the clone operation and that should get you started in writing your own in C++, remember the clone operation requires vCenter.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Thanks -- that was very helpful.
Follow up question,
How do I add additional disks to the already existing disks? I can clone using the existing disk, no problem. But how do I add disk?
I'm guessing: VirtualMachineConfigSpec and then setDeviceChange()?
Thanks,
Jan
As part of the CloneVM_Task, you're allowed to modify the VM configuration, this includes changing the name of the VM, adding/removing network adapters,disks,cdrom,etc.
Take a look at the API reference for the CloneVM_Task: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html#c...
and yes, you'll need to create a new VirtualMachineCloneSpec which will specify a new VirtualMachineConfigSpec that contains the changes you would like to make, in your case, you're adding an additional disk so you'll create the necessary backing and add the appropriate number of disks
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
VirtualMachineCloneSpec.setChangeDevice() will include the existing and new disks in vector or just the additional disks?
Also If I'm creating a new disks I have to make sure the unit number don't overlap with the existing disks, right?
It can include both existing and newly added disks and other components.
That is correct, you need to make sure the unitNumber is unique, I believe if you pass in "-1" it'll automatically increment the counters for you
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Where can I find -1 documented? Because that would make my life real simple
Thanks,
Jan
I don't' recall if it's formally documented, even in the API docs, but this was through some testing and I also noticed some of the canned vSphere SDK for Perl scripts used -1 to denote a new entry.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".