cloneTo() loses groups?

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

cloneTo() loses groups?

Post by Jermey »

Hi All,

I am new to programming the VBox API, so apologies if this is a newbie question. I am writing in Python and using VBox 5.0. I am attempting to create a new machine cloned from another. The new machine needs to be created in a new machine group. When I execute the createMachine() API, I can save the settings and see that the group is there. However, after I cloneTo() the group setting is gone. I'm not sure if I'm calling things wrong, but here is the code:

Code: Select all

    def create(self, groups=None, progress=None):
        if self.exists:
            return False

        filename = self._VBOX.composeMachineFilename(
            self.name, groups[0], None, None)

        # create the new vm vbox vm
        self.vbox_vmi = self._VBOX.createMachine(
            filename, self.name,
            groups, 'Other', '')

        # clone the 'cvx-base' VM
        cvx_base = self._CATALOG['clone-this-vm']     # _CATALOG is just a dictionary of existing VMs
        cloning = cvx_base.cloneTo(
            self.vbox_vmi,
            self._ENUMS.CloneMode_MachineState, None)

        if not progress:
            cloning.waitForCompletion(-1)
        else:
            # TODO: should put in a failsafe for exceeding timeout
            while not cloning.completed:
                progress(self.name, cloning.percent, cloning.completed)
                cloning.waitForCompletion(1000)
            # one more for done
            progress(self.name, cloning.percent, cloning.completed)

        self.__class__._catalog_register(self)
        return True
I also trying using the "vboxmanage clonevm" command with the --groups --register option and I actually see the same results; i.e. the groups are lost.

Really appreciate anyone's guidance.

Thank you!
-- Jeremy
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

There is no mention of groups management in IMachine::cloneTo() so not possible to answer directly.
I've asked the questions on the dev mailing list, we'll see what comes up.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

Re: cloneTo() loses groups?

Post by Jermey »

Hi noteirak,

Really appreciate the prompt response on this. I look forward to seeing what the devs report.

Thank you!
-- Jeremy
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

Re: cloneTo() loses groups?

Post by Jermey »

Hi noteirak,

Are there any other approaches to solving this issue, i.e. a way to write the "groups" back after the cloneTo() operation? I tried to access the IMachine.groups attribute, but I am seeing that this attribute is not found on the IMachine instance.

Thanks again,
-- Jeremy
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

That's odd, that's exactly what I would do: read the list of groups from the original VM and add them to the cloned VM.
Maybe check for possible getGroups() and setGroups() methods?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

Re: cloneTo() loses groups?

Post by Jermey »

Awesome, this worked!

Code: Select all

self.vbox_vmi.setGroups(['/pod_1.demo'])
So this "setGroups" method is not defined in the SDK documentation. How does one learn about these undocumented methods? :-)

Thanks again!!
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

That depends on the language actually. For (almost) all properties, you'll find a matching getXXX and setXXX method in Python and Java per example. Possibly in PHP too.
Actual properties are used in C/C++ because it's possible to make them readonly per exemple, which is not the case (at least not like intended in C/C++) in Java or Python.
That's just a trick to know :)
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

Re: cloneTo() loses groups?

Post by Jermey »

Hi noteirak,

Good trick to know, thank you!

I did run into one "problem" assigning the Group after the cloneTo(). Let's say I createMachine() with groups = ["/my_group"]. What happens *before* the register() is that the VM, let's call it "my_host" is actually located in my "Virtual Box/my_group/my_host" directory. But *after* the call to register(), and after I make the explicit called to setGroup(), it's relocated to "Virtual Box/my_group/my_group/my_host". <<-- note the "doubling" of the group path.

The issue here is that in the my_host.vbox settings file, it points the harddrive to "Virtual Box/my_group/my_host/my_host.vdi". So when the register() process happens, VBoxManager (GUI) shows that the hard-drive is not accessible; and the VM fails to launch. I had to "hot fix" this by creating a symlink in the "Virtual Box/my_group" directory ... but that's really a hack.

Any ideas what this is happening?

Thank you!
-- Jeremy
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

No idea but that sounds like a bug indeed. Will double check if I can reproduce. Workaround would be to give a group only after the VM is registered.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Jermey
Posts: 12
Joined: 14. Aug 2015, 00:17

Re: cloneTo() loses groups?

Post by Jermey »

I finally figured this out. Turns out there is a very specific order that I needed to do in making the calls. First, do *NOT* include the groups in the createMachine() call. Only after the call to cloneTo() has finished do I then call setGroups() and then registerMachine(). Then everything works as expected.

Fun learning experience, indeed :-)

Thank you again for your help. It's the setGroups, and the better understanding on getXXX and setXXX that you shared that really helped out. Really appreciate it.

Cheers,
-- Jeremy
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

Glad you made it work. My hunch was good in the end then. I still need to reproduce locally but almost 100% sure it's a bug and I'll fill up a bug report later on so the devs can have a look at it.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: cloneTo() loses groups?

Post by noteirak »

Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply