Possible bug in Python api or salt-cloud

Discussion about using the VirtualBox API, Tutorials, Samples.

Possible bug in Python api or salt-cloud

Postby mcqueenorama » 12. Jan 2018, 02:25

Salt-cloud's virtualbox provider is throwing like this:

Code: Select all   Expand viewCollapse view
[DEBUG   ] Failed to execute 'virtualbox.list_nodes()' while querying for running nodes: 'VirtualBoxManager' object has no attribute 'vbox'
Traceback (most recent call last):
  File "/usr/local/Cellar/saltstack/2017.7.2/libexec/lib/python2.7/site-packages/salt/cloud/__init__.py", line 2387, in run_parallel_map_providers_query
    cloud.clouds[data['fun']]()
  File "/usr/local/Cellar/saltstack/2017.7.2/libexec/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.py", line 299, in list_nodes
    list_nodes_full('function'), attributes, call,
  File "/usr/local/Cellar/saltstack/2017.7.2/libexec/lib/python2.7/site-packages/salt/cloud/clouds/virtualbox.py", line 248, in list_nodes_full
    for machine in vb_list_machines():
  File "/usr/local/Cellar/saltstack/2017.7.2/libexec/lib/python2.7/site-packages/salt/utils/virtualbox.py", line 347, in vb_list_machines
    machines = manager.getArray(vb_get_box(), 'machines')
  File "/usr/local/Cellar/saltstack/2017.7.2/libexec/lib/python2.7/site-packages/salt/utils/virtualbox.py", line 149, in vb_get_box
    vbox = _virtualboxManager.vbox
AttributeError: 'VirtualBoxManager' object has no attribute 'vbox'


Which is fixed with this simple patch to the python vboxapi:

Code: Select all   Expand viewCollapse view
# diff /Applications/VirtualBox.app/Contents/MacOS/sdk/installer/vboxapi/__init__.py /Library/Python/2.7/site-packages/vboxapi/__init__.py
1015c1015
<             vbox = self.platform.getVirtualBox()
---
>             self.vbox = self.platform.getVirtualBox()
#


But how can such a basic thing be broken?

Is the vboxapi wrong here or is the salt-cloud virtualbox provider?
mcqueenorama
 
Posts: 4
Joined: 4. Jan 2018, 21:21

Re: Possible bug in Python api or salt-cloud

Postby noteirak » 12. Jan 2018, 17:24

Please follow the Posting Guidelines
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Possible bug in Python api or salt-cloud

Postby mcqueenorama » 12. Jan 2018, 20:17

I thought I had provided these details, but that was in some other discussion.

Virtualbox is at 5.2.4 on both the Host and the Guest.

Host is OSX 10.12.6.
Guests are Centos 7.

The code is using the XPCOM api. I don't know the API version, but its whatever ships with 5.2.4.

Here's a simplified extraction of the salt cloud code where it expects a vbox attribute in the return from VirtualBoxManager. The stacktrace is shown in the post above.

Code: Select all   Expand viewCollapse view

import vboxapi
_virtualboxManager = vboxapi.VirtualBoxManager(None, None)
 vbox = _virtualboxManager.vbox



The rest of the vboxapi class does seem to be consistent in that there should be a self.vbox. See the init function of the class VirtualBoxManager(object). Its at line 1015 of vboxapi. Should that be self.vbox?

From the Virtualbox bundled vboxapi: /Applications/VirtualBox.app/Contents/MacOS/sdk/installer/vboxapi/__init__.py

Code: Select all   Expand viewCollapse view

class VirtualBoxManager(object):

...

    def __init__(self, sStyle=None, dPlatformParams=None):

...
        # Get the virtualbox singleton.
        try:
            vbox = self.platform.getVirtualBox()             #  <<<-- right here vbox or self.vbox?
        except NameError:
            print("Installation problem: check that appropriate libs in place")
            traceback.print_exc()
            raise
        except Exception:
            _, e, _ = sys.exc_info()
            print("init exception: ", e)
            traceback.print_exc()

mcqueenorama
 
Posts: 4
Joined: 4. Jan 2018, 21:21

Re: Possible bug in Python api or salt-cloud

Postby noteirak » 12. Jan 2018, 20:30

Can you try with 5.2.2 and 5.2.0?
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Possible bug in Python api or salt-cloud

Postby mcqueenorama » 15. Jan 2018, 04:06

Host at 5.2.0 and guestadditions at 5.2.0:

Code: Select all   Expand viewCollapse view
[ERROR   ] There was a query error: 'VirtualBoxManager' object has no attribute 'vbox'
Exception TypeError: "'NoneType' object is not callable" in <bound method VirtualBoxManager.__del__ of <vboxapi.VirtualBoxManager object at 0x1054a3390>> ignored
bmcqueen:~ root# VBoxManage --version
5.2.0r118431
bmcqueen:~ root#


When I apply the patch the provisioning goes forward. Could not fully provision with salt-cloud with VB 5.2.0. Have not determined why.

Host at 5.2.2 and guestadditions at 5.2.2:

Same error:

Code: Select all   Expand viewCollapse view
[ERROR   ] There was a query error: 'VirtualBoxManager' object has no attribute 'vbox'
Exception TypeError: "'NoneType' object is not callable" in <bound method VirtualBoxManager.__del__ of <vboxapi.VirtualBoxManager object at 0x10e0ee490>> ignored
bmcqueen:~ root#


Applying patch to 5.2.2 fixes it. salt-cloud successfully provisions the servers.
mcqueenorama
 
Posts: 4
Joined: 4. Jan 2018, 21:21

Re: Possible bug in Python api or salt-cloud

Postby noteirak » 15. Jan 2018, 10:28

can you try all this without salt cloud and do a standalone piece of code instead?
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Possible bug in Python api or salt-cloud

Postby mcqueenorama » 15. Jan 2018, 20:37

I should've thought of that sooner. The vboxshell does it this way:

Code: Select all   Expand viewCollapse view
    oVBoxMgr = VirtualBoxManager(style, params)
    ctx = {
        'global':       oVBoxMgr,
        'vb':           oVBoxMgr.getVirtualBox(),
...


My question is simply which is wrong, the vboxapi or salt-cloud. I think this is conclusive. Salt-cloud is wrong. I'll get something going over there.

I've already made the patch to salt-cloud locally and tested it. It works.

Thanks
mcqueenorama
 
Posts: 4
Joined: 4. Jan 2018, 21:21

Re: Possible bug in Python api or salt-cloud

Postby Sombrero » 21. May 2018, 09:14

I would like to add that there is definitely problem somewhere, either code or documentation.

Virtualbox SDK Programming Guide and Reference states in Section 2.3.2 the following:

After obtaining the VirtualBoxManager instance, one can perform operations on the IVirtualBox
class. For example, the following code will a start virtual machine by name or ID:
from vboxapi import VirtualBoxManager
mgr = VirtualBoxManager(None, None)
vbox = mgr.vbox
name = "Linux"
mach = vbox.findMachine(name)
session = mgr.getSessionObject(vbox)
progress = mach.launchVMProcess(session, "gui", "")
progress.waitForCompletion(-1)
mgr.closeMachineSession(session)

This example code does not work anymore.

It has worked previously in 5.1 versions. This is a braking API change that has not been documented at all in Section 13 Main API Change Log either.
Sombrero
 
Posts: 1
Joined: 21. May 2018, 09:01

Re: Possible bug in Python api or salt-cloud

Postby deniz » 19. Jun 2018, 23:19

You are right the documentation is not right.
To get the list of machines you can use this:
Code: Select all   Expand viewCollapse view
vbox_manager = vboxapi.VirtualBoxManager(None, None)
vbox = vbox_manager.getVirtualBox()
vm_list = vbox_manager.getArray(vbox, 'machines')
print vm_list


to get a single machine you can use this.
Code: Select all   Expand viewCollapse view
from vboxapi import VirtualBoxManager
mgr = VirtualBoxManager(None, None)
vbox = mgr.getVirtualBox()
vbox.findMachine('test')
deniz
 
Posts: 1
Joined: 19. Jun 2018, 23:16


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 1 guest