[vbox-dev] trying to clone a vm

Klaus Espenlaub klaus.espenlaub at oracle.com
Mon Jul 15 08:55:12 GMT 2013


Hi Carlo,

On 15.07.2013 10:01, Carlo Bongiovanni wrote:
> Hi All,
>
> I am running VirtualBox 4.2.10 on Ubuntu 12.04.
>
> I am trying to clone a vm with the Java API. Doing this operation from
> the console, I would issue the following command:
> VBoxManage clonevm vmuid_src --name vmname_dest --register
>
> With Java I am doing the following:
>
>          IMachine m_clone = vbox.findMachine(vmuid_src);
>          String m_clone_os = m_clone.getOSTypeId();
>          IMachine machine = vbox.createMachine(null, vmname_dest, null,
> m_clone_os, null);
>          machine.saveSettings();
>          vbox.registerMachine(machine);
>
>          CloneMode cm = CloneMode.MachineState;
>          List<CloneOptions> cloneOptionsList = new
> ArrayList<CloneOptions>();
>          cloneOptionsList.add(CloneOptions.KeepAllMACs);
>
>          machine.cloneTo(m_clone, cm, cloneOptionsList);
>
> After the execution of this code, I found a new vm in the list, but
> without any storage attached. What am I missing? Can you direct me to
> the right way to do it? I couldn't understand it from the sdkref.

Your code has to wait until the cloning has completed. The IProgress 
object isn't returned for fun, it serves an important purpose. Without 
it there's no good way to tell when the cloning has finished. It can 
take a very long time, as your code creates a full clone which 
potentially means copying many GBytes of virtual disk contents. Only at 
the end of the VM cloning the settings are all in place...

The best "sample" is always the source of VBoxManage - it's C++, but the 
API works in principle the same in all languages, with minor differences 
in the error handling and thus details of the parameter list.

Klaus
>
> Thanks, best
> Carlo




More information about the vbox-dev mailing list