<div dir="ltr"><div><div>Hi Klaus, <br><br></div>I elaborated your last answer and tried a lot to find what was wrong in my code. I also discovered that probably I also needed to lock the session before cloning the machine and I tried doing it.. I finally got this code, surrounded with try/catch that I avoid to paste here for semplicity:<br>

<br>            // find the machine to clone<br>            IMachine m_clone = vbox.findMachine(vmuid_clone);<br>            String m_clone_os = m_clone.getOSTypeId();<br>            // create a new machine with the provided name<br>

            IMachine machine = vbox.createMachine(null, vmname, null, m_clone_os, null);<br><br>            machine.saveSettings();<br>            vbox.registerMachine(machine);<br><br>            // lock the src machine<br>

            session = mgr.getSessionObject();<br>            m_clone.lockMachine(session, LockType.Write);<br>            IMachine mutable = session.getMachine();<br><br>            // clone options<br>            CloneMode cm = CloneMode.MachineState;<br>

            List<CloneOptions> cloneOptionsList = new ArrayList<CloneOptions>();<br>            cloneOptionsList.add(CloneOptions.KeepAllMACs);<br><br>            // clone the machine<br>            IProgress p = machine.cloneTo(mutable, cm, cloneOptionsList);<br>

<br>            // get percent of cloning option<br>            log(p.getPercent());<br><br>            // wait<br>            p.waitForCompletion(-1);<br><br>            // get percent of cloning option<br>            log(p.getPercent());<br>

<br>            // unlock the src machine<br>            session.unlockMachine();<br><br></div><div>After the execution of this code, the p.getPercent() returns "50", and the new machine is registered, but no disks are linked to it. Am I missing something important?<br>

<br></div><div>Thanks for any feedback. <br></div><div>Best<br>Carlo<br></div><div><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/15 Klaus Espenlaub <span dir="ltr"><<a href="mailto:klaus.espenlaub@oracle.com" target="_blank">klaus.espenlaub@oracle.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Carlo,<br>
<div><div class="h5"><br>
On 15.07.2013 10:01, Carlo Bongiovanni wrote:<br>
> Hi All,<br>
><br>
> I am running VirtualBox 4.2.10 on Ubuntu 12.04.<br>
><br>
> I am trying to clone a vm with the Java API. Doing this operation from<br>
> the console, I would issue the following command:<br>
> VBoxManage clonevm vmuid_src --name vmname_dest --register<br>
><br>
> With Java I am doing the following:<br>
><br>
>          IMachine m_clone = vbox.findMachine(vmuid_src);<br>
>          String m_clone_os = m_clone.getOSTypeId();<br>
>          IMachine machine = vbox.createMachine(null, vmname_dest, null,<br>
> m_clone_os, null);<br>
>          machine.saveSettings();<br>
>          vbox.registerMachine(machine);<br>
><br>
>          CloneMode cm = CloneMode.MachineState;<br>
>          List<CloneOptions> cloneOptionsList = new<br>
> ArrayList<CloneOptions>();<br>
>          cloneOptionsList.add(CloneOptions.KeepAllMACs);<br>
><br>
>          machine.cloneTo(m_clone, cm, cloneOptionsList);<br>
><br>
> After the execution of this code, I found a new vm in the list, but<br>
> without any storage attached. What am I missing? Can you direct me to<br>
> the right way to do it? I couldn't understand it from the sdkref.<br>
<br>
</div></div>Your code has to wait until the cloning has completed. The IProgress<br>
object isn't returned for fun, it serves an important purpose. Without<br>
it there's no good way to tell when the cloning has finished. It can<br>
take a very long time, as your code creates a full clone which<br>
potentially means copying many GBytes of virtual disk contents. Only at<br>
the end of the VM cloning the settings are all in place...<br>
<br>
The best "sample" is always the source of VBoxManage - it's C++, but the<br>
API works in principle the same in all languages, with minor differences<br>
in the error handling and thus details of the parameter list.<br>
<br>
Klaus<br>
><br>
> Thanks, best<br>
> Carlo<br>
<br>
_______________________________________________<br>
vbox-dev mailing list<br>
<a href="mailto:vbox-dev@virtualbox.org">vbox-dev@virtualbox.org</a><br>
<a href="https://www.virtualbox.org/mailman/listinfo/vbox-dev" target="_blank">https://www.virtualbox.org/mailman/listinfo/vbox-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><span style="font-family:arial;font-size:small">Carlo Bongiovanni</span><br style="font-family:arial;font-size:small"><br style="font-family:arial;font-size:small">

<span style="font-family:arial;font-size:small">Tel. +49</span><span style="font-family:arial;font-size:small"> </span><span style="font-size:small">173 9714421</span><br style="font-family:arial;font-size:small"><span style="font-family:arial;font-size:small">callto://pacman81</span><br style="font-family:arial;font-size:small">

<span style="font-family:arial;font-size:small">gtalk: carlo.bongiovanni</span><br></div>
</div>