Please find attached a short example of a VirtualBox webservice client
written in Python. It was written to pretty closely mirror the existing
Java example. It's released under the MIT license
(http://www.opensource.org/licenses/mit-license.php), and if anyone has
a use for it, have at it.

~JW
#!/usr/bin/env python
#
# This is a short python program to demontrate how to connect to the VirtualBox
# webservice. It's intended to provide the same functionality as the java
# example that already ships with VirtualBox.
#
# To run this example, follow these steps:
#
# 1) Be sure you have Python and ZSI installed
#    (http://pywebsvcs.sourceforge.net/)
#
# 2) Run wsdl2py on the file 'vboxwebService.wsdl'. This will generate two .py
#       files. These two files need to either be in the same working directory
#       as this script, or moved to your site-packages directory (usually
#       /usr/lib/python2.X/site-packages/)
#
# 3) Start vboxwebsrv
#
# 4) Run this script

from VirtualBox_services import *

loc = vboxServiceLocator()
port = loc.getvboxPortType()

# ZSI's method for dealing with a WSDL interface is to create a request, then
# submit that request to the webservice and deal with the response.

# Logon to the webservice
req = IWebsessionManager_logonRequestMsg()
req._username = ''
req._password = ''
resp = port.IWebsessionManager_logon(req)
oVbox = resp.Returnval

# Get the VBox version number
req = IVirtualBox_getVersionRequestMsg()
req._this = oVbox
resp = port.IVirtualBox_getVersion(req)
print "Version Number: %s\n"  % resp.Returnval

# Get a list of the VMs
req = IVirtualBox_getMachinesRequestMsg()
req._this = oVbox
resp = port.IVirtualBox_getMachines(req)
aMachines = resp.Returnval.Array

# Print the names of the VMs
print 'Current Virtual Machines:'
for oMachine in aMachines:
    req = IMachine_getNameRequestMsg()
    req._this = oMachine
    resp = port.IMachine_getName(req)
    machineName = resp.Returnval
    print "\t%s" % machineName
    # We're done this machine object, so we can release it
    req = IManagedObjectRef_releaseRequestMsg()
    req._this = oMachine
    port.IManagedObjectRef_release(req)

# Logoff
req = IWebsessionManager_logoffRequestMsg()
req._refIVirtualBox = oVbox
resp = port.IWebsessionManager_logoff(req)

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to