vboxapi.py revision 0ad756e595c9bb21b406d2b8f608ca778f2c1df3
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# -*- coding: utf-8 -*-
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncVirtualBox Python API Glue.
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsyncCopyright (C) 2009-2013 Oracle Corporation
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncavailable from http://www.virtualbox.org. This file is free software;
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncyou can redistribute it and/or modify it under the terms of the GNU
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncGeneral Public License (GPL) as published by the Free Software
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Note! To set Python bitness on OSX use 'export VERSIONER_PYTHON_PREFER_32_BIT=yes'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Standard Python imports.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Globals, environment and sys.path changes.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncVBoxBinDir = os.environ.get("VBOX_PROGRAM_PATH", None)
2561352ae77d8f2f825526a6cbafa34b45f16972vboxsync # Will be set by the installer
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync # Will be set by the installer
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Import the generated VirtualBox constants.
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsyncfrom VirtualBox_constants import VirtualBoxReflectionInfo
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ This class provides a wrapper over IPerformanceCollector in order to
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync get more 'pythonic' interface.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync To begin collection of metrics use setup() method.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync To get collected data use query() method.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync It is possible to disable metric collection without changing collection
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync parameters with disable() method. The enable() method resumes metric
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync collection.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Initializes the instance.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Discards all previously collected values for the specified
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync metrics, sets the period of collection and the number of retained
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync samples, enables collection.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.collector.setupMetrics(names, objects, period, nsamples)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Resumes metric collection for the specified metrics.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Suspends metric collection for the specified metrics.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Retrieves collected metric values as well as some auxiliary
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync information. Returns an array of dictionaries, one dictionary per
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync metric. Each dictionary contains the following entries:
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'name': metric name
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'object': managed object this metric associated with
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'unit': unit of measurement
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'scale': divide 'values' by this number to get float numbers
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values': collected data
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values_as_string': pre-processed values ready for 'print' statement
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync # Get around the problem with input arrays returned in output
aaa80e9df329609078dea844a11f2611443b677avboxsync # parameters (see #3953) for MSCOM.
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync (values, names, objects, names_out, objects_out, units, scales, sequence_numbers,
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync indices, lengths) = self.collector.queryMetricsData(names, objects)
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync (values, names_out, objects_out, units, scales, sequence_numbers,
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync indices, lengths) = self.collector.queryMetricsData(names, objects)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values':[int(values[j]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))],
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values_as_string':'['+', '.join([fmt % (int(values[j])/scale, units[i]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))])+']'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Attribute hacks.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync## This is for saving the original DispatchBaseClass __getattr__ and __setattr__
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# method references.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync 'getattr': None,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync 'setattr': None,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ Our getattr replacement for DispatchBaseClass. """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Fastpath.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if oRet != None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Try case-insensitivity workaround for class attributes (COM methods).
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.__class__.__dict__[sAttr] = self.__class__.__dict__[sKey]
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Slow path.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['getattr'](self, ComifyName(sAttr))
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ Our setattr replacement for DispatchBaseClass. """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['setattr'](self, ComifyName(sAttr), oValue)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['setattr'](self, sAttr, oValue)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Base class for the platform specific code.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Gets a the IVirtualBox singleton.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Get a session object that can be used for opening machine sessions.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The oIVBox parameter is an getVirtualBox() return value, i.e. an
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IVirtualBox reference.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync See also openMachineSession.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Returns the platform type (class name sans 'Platform'). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns True if remote (web services) and False if local (COM/XPCOM).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Retrives the value of the array attribute 'sAttrib' from
e35e9d6317da2985728e7510bea9337b9893b66evboxsync interface 'oInterface'.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This is for hiding platform specific differences in attributes
e35e9d6317da2985728e7510bea9337b9893b66evboxsync returning arrays.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Does backend specific initialization for the calling thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Does backend specific uninitialization for the calling thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Instantiates and wraps an active event listener class so it can be
e35e9d6317da2985728e7510bea9337b9893b66evboxsync passed to an event source for registration.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oImplClass is a class (type, not instance) which implements
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IEventListener.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync dArgs is a dictionary with string indexed variables. This may be
e35e9d6317da2985728e7510bea9337b9893b66evboxsync modified by the method to pass platform specific parameters. Can
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This currently only works on XPCOM. COM support is not possible due to
e35e9d6317da2985728e7510bea9337b9893b66evboxsync shortcuts taken in the COM bridge code, which is not under our control.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Use passive listeners for COM and web services.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync raise Exception("No active listeners for this platform");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Wait for events to arrive and process them.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The timeout (cMsTimeout) is in milliseconds for how long to wait for
e35e9d6317da2985728e7510bea9337b9893b66evboxsync events to arrive. A negative value means waiting for ever, while 0
e35e9d6317da2985728e7510bea9337b9893b66evboxsync does not wait at all.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 0 if events was processed.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 1 if timed out or interrupted in some way.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 2 on error (like not supported for web services).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Raises an exception if the calling thread is not the main thread (the one
e35e9d6317da2985728e7510bea9337b9893b66evboxsync that initialized VirtualBoxManager) or if the time isn't an integer.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Interrupt a waitForEvents call.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This is normally called from a worker thread to wake up the main thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns True on success, False on failure.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Unitializes the platform specific backend.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IUnknown::QueryInterface wrapper.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oIUnknown is who to ask.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sClassName is the name of the interface we're asking for.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Error (exception) access methods.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the COM status code from the VBox API given exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns True if the exception indicates that the interface is dead, False if not.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Checks if the exception oXcpt is equal to the COM/XPCOM status code
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync The oXcpt parameter can be any kind of object, we'll just return True
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if it doesn't behave like a our exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Will not raise any exception as long as hrStatus and self are not bad.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the best error message found in the COM-like exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns None to fall back on errToString.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Raises exception if oXcpt isn't our kind of exception object.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the base exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Copy/whatever all error constants onto oDst.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Copy everything that looks like error constants from oDst to oSrc.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sAttr[0].isupper() and (sAttr[1].isupper() or sAttr[1] == '_'):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Platform specific code for MS COM.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @name VirtualBox COM Typelib definitions (should be generate)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # @remarks Must be updated when the corresponding VirtualBox.xidl bits
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # are changed. Fortunately this isn't very often.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VBOX_TLB_GUID = '{D7569351-1750-46F0-936E-BD127D5BC264}'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Class to fake access to constants in style of foo.bar.boo """
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_depth']=parent.__dict__['_depth']+1
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if fake != None:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync while parent != None:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if name is not None:
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync self.__dict__['_rootFake'] = PlatformMSCOM.ConstantFake(None, None)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Since the code runs on all platforms, we have to do a lot of
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # importing here instead of at the top of the file where it's normally located.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32com.client import gencache, DispatchBaseClass
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32api import GetCurrentThread, GetCurrentThreadId, DuplicateHandle, GetCurrentProcess
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Hack the COM dispatcher base class so we can modify method and
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # attribute names to match those in xpcom.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _g_dCOMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__']
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync DispatchBaseClass.__dict__['__getattr__'] = _CustomGetAttr
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _g_dCOMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__']
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync DispatchBaseClass.__dict__['__setattr__'] = _CustomSetAttr
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Hack the exception base class so the users doesn't need to check for
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # XPCOM or COM and do different things.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
1d96c25e994a2160c1697208bb398d79ca117c4avboxsync return win32com.client.Dispatch("VirtualBox.Session")
2ea0ec406117609d51bd5ac51cbb3d4f0de9a16dvboxsync return win32com.client.Dispatch("VirtualBox.VirtualBox")
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'MSCOM'
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync raise Exception('no active listeners on Windows as PyGatewayBase::QueryInterface() '
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync 'returns new gateway objects all the time, thus breaking EventQueue '
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync 'assumptions about the listener interface pointer being constants between calls ');
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync # Did this code ever really work?
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync str += " _typelib_version_ = tlb_major, tlb_minor\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync # Maybe we'd better implement Dynamic invoke policy, to be more flexible here
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
dafcc1aee6fa9a280e6c6d7630132e5a778f3a6fvboxsync # capitalized version of listener method
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += " def __init__(self): BaseClass.__init__(self, dArgs)\n"
4bb0fd45b2679a58b304ba2d7bff3e19b74a447fvboxsync str += "result = win32com.server.util.wrap(ListenerImpl())\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync exec(str, d, d)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync return d['result']
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32event import MsgWaitForMultipleObjects, \
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync raise TypeError("The timeout argument is not an integer")
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync raise Exception("wait for events from the same thread you inited!")
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync rc = MsgWaitForMultipleObjects(self.handles, 0, cMsTimeout, QS_ALLINPUT)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # is it possible?
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # Waiting messages
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync # check for interruption
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Basically a python implementation of NativeEventQueue::postEvent().
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync The magic value must be in sync with the C++ implementation or this
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync won't work.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync Note that because of this method we cannot easily make use of a
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync non-visible Window to handle the message like we would like to do.
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync PostThreadMessage(self.tid, WM_USER, None, 0xf241b819)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if h is not None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # The DISP_E_EXCEPTION + excptinfo fun needs checking up, only
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # empirical info on it so far.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except: pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706ba, -2147023174, # RPC_S_SERVER_UNAVAILABLE.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # XPCOM compatability constants.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Platform specific code for XPCOM.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync sys.path.append(VBoxSdkDir+'/bindings/xpcom/python/')
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'XPCOM'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oInterface.__getattr__('get'+ComifyName(sAttrib))()
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _com_interfaces_ = xpcom.components.interfaces.IEventListener\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += " def __init__(self): BaseClass.__init__(self, dArgs)\n"
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync exec (str, d, d)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync return d['result']
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oIUnknown.queryInterface(getattr(xpcom.components.interfaces, sClassName))
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706be, -2147023170, # NS_ERROR_CALL_FAILED (RPC_S_CALL_FAILED)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
0ad756e595c9bb21b406d2b8f608ca778f2c1df3vboxsync oDst = self.errCopyErrorConstants(oDst, xpcom.nsError);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # COM compatability constants.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_ACCESSDENIED = -2147024891; # see VBox/com/defs.h
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.DISP_E_EXCEPTION = -2147352567; # For COM compatability only.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VirtualBox Web Services API specific code.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Import web services stuff. Fix the sys.path the first time.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sWebServLib = os.path.join(VBoxSdkDir, 'bindings', 'webservice', 'python', 'lib');
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync from VirtualBox_wrappers import IWebsessionManager2
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Initialize instance variables from parameters.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if dParams is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Base class overrides.
355edde34018a687b4a4d17054c378b780e3d8abvboxsync return self.connect(self.url, self.user, self.password)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'WEBSERVICE'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Returns True if remote VBox host, False if local. """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync # Webservices cannot do that yet
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync # Webservices cannot do that yet
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += "from VirtualBox_wrappers import "+sClassName+"\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += "result = "+sClassName+"(oIUnknown.mgr, oIUnknown.handle)\n"
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync # wrong, need to test if class indeed implements this interface
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync exec (str, d, d)
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync return d['result']
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Web service specific methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync from VirtualBox_wrappers import IWebsessionManager2
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if url is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if user is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.vbox = self.wsmgr.logon(self.user, self.password)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync raise Exception("cannot connect to '"+self.url+"' as '"+self.user+"'")
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if self.vbox is not None and self.wsmgr is not None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync## The current (last) exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# This is reinitalized whenever VirtualBoxManager is called, so it will hold
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# the reference to the error exception class for the last platform/style that
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# was used. Most clients does talk to multiple VBox instance on different
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# platforms at the same time, so this should be sufficent for most uses and
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# be way simpler to use than VirtualBoxManager::oXcptClass.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VirtualBox API manager class.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The API users will have to instantiate this. If no parameters are given,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync it will default to interface with the VirtualBox running on the local
e35e9d6317da2985728e7510bea9337b9893b66evboxsync machine. sStyle can be None (default), MSCOM, XPCOM or WEBSERVICES. Most
e35e9d6317da2985728e7510bea9337b9893b66evboxsync users will either be specifying None or WEBSERVICES.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The dPlatformParams is an optional dictionary for passing parameters to the
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WEBSERVICE backend.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, sStyle = None, dPlatformParams = None):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.platform = PlatformWEBSERVICE(dPlatformParams);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## VirtualBox API constants (for webservices, enums are symbolic).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.constants = VirtualBoxReflectionInfo(sStyle == "WEBSERVICE")
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## Status constants.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.statuses = self.platform.errSetupConstants(VirtualBoxManager.Statuses());
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## @todo Add VBOX_E_XXX to statuses? They're already in constants...
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## Dictionary for errToString, built on demand.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## The exception class for the selected platform.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Get the virtualbox singleton.
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync print "Installation problem: check that appropriate libs in place"
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync print "init exception: ", e
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @deprecated
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # This used to refer to a session manager class with only one method
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # called getSessionObject. The method has moved into this call.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns a Python API revision number.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This will be incremented when features are added to this file.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Wrappers for self.platform methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getVirtualBox(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getSessionObject(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getArray(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def createListener(self, oImplClass, dArgs = None):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::createListener(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.createListener(oImplClass, dArgs)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::waitForEvents(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::interruptWaitEvents(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::queryInterface(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.queryInterface(oIUnknown, sClassName)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Init and uninit.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::deinitPerThread(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::deinitPerThread(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync For unitializing the manager.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Do not access it after calling this method.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Utility methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def openMachineSession(self, oIMachine, fPermitSharing = True):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Attemts to open the a session to the machine.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns a session object on success.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Raises exception on failure.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Closes a session opened by openMachineSession.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Ignores None parameters.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if oSession is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns a helper class (PerfCollector) for accessing performance
e35e9d6317da2985728e7510bea9337b9893b66evboxsync collector goodies. See PerfCollector for details.
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync Returns the VirtualBox binary directory.
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync Returns the VirtualBox SDK directory.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Error code utilities.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## @todo port to webservices!
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Gets the status code from an exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns True if the exception indicates that the interface is dead, False if not.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Checks if the exception is one that could come from the VBox API.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if self.oXcptClass is None: ## @todo find the exception class for web services!
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ See PlatformBase::errIsEqual(). """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Negated errIsEqual.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Converts the specified COM status code, or the status code of the
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync specified exception, to a C constant string.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Deal with exceptions.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Build the dictionary on demand.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Do the lookup, falling back on formatting the status number.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the best error message found in the COM-like exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sRet is None: