vboxapi.py revision 5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5
#
# Copyright (C) 2009 Sun Microsystems, Inc.
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
# Clara, CA 95054 USA or visit http://www.sun.com if you need
# additional information or have any questions.
#
import traceback
if VboxBinDir is None:
# Will be set by the installer
VboxBinDir = "%VBOX_INSTALL_PATH%"
if VboxSdkDir is None:
from VirtualBox_constants import VirtualBoxReflectionInfo
class PerfCollector:
""" This class provides a wrapper over IPerformanceCollector in order to
get more 'pythonic' interface.
To begin collection of metrics use setup() method.
To get collected data use query() method.
It is possible to disable metric collection without changing collection
parameters with disable() method. The enable() method resumes metric
collection.
"""
""" Initializes the instance.
"""
""" Discards all previously collected values for the specified
metrics, sets the period of collection and the number of retained
samples, enables collection.
"""
""" Resumes metric collection for the specified metrics.
"""
""" Suspends metric collection for the specified metrics.
"""
""" Retrieves collected metric values as well as some auxiliary
information. Returns an array of dictionaries, one dictionary per
metric. Each dictionary contains the following entries:
'name': metric name
'object': managed object this metric associated with
'unit': unit of measurement
'scale': divide 'values' by this number to get float numbers
'values': collected data
'values_as_string': pre-processed values ready for 'print' statement
"""
# Get around the problem with input arrays returned in output
# parameters (see #3953) for MSCOM.
else:
out = []
if scale != 1:
fmt = '%.2f%s'
else:
fmt = '%d %s'
'scale':scale,
'values_as_string':'['+', '.join([fmt % (int(values[j])/scale, units[i]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))])+']'
})
return out
def ComifyName(name):
_COMForward = { 'getattr' : None,
'setattr' : None}
# fastpath
# try case-insensitivity workaround for class attributes (COM methods)
try:
except AttributeError:
try:
except AttributeError:
class PlatformMSCOM:
# Class to fake access to constants in style of foo.bar.boo
class ConstantFake:
try:
except:
raise AttributeError
import win32com
raise AttributeError
if fake != None:
return fake
try:
while parent != None:
if name is not None:
else:
except AttributeError,e:
return fake
class InterfacesWrapper:
def __getattr__(self, a):
import win32com
if a.startswith("__"):
raise AttributeError
try:
except AttributeError,e:
VBOX_TLB_GUID = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'
VBOX_TLB_LCID = 0
VBOX_TLB_MAJOR = 1
VBOX_TLB_MINOR = 0
import win32com
import pythoncom
import win32api
from win32con import DUPLICATE_SAME_ACCESS
pid = GetCurrentProcess()
import win32com
def getVirtualBox(self):
import win32com
return 'MSCOM'
return False
def initPerThread(self):
import pythoncom
def deinitPerThread(self):
import pythoncom
d = {}
d['BaseClass'] = impl
d['arg'] = arg
str = ""
str += "import win32com.server.util\n"
str += "import pythoncom\n"
str += " _typelib_guid_ = tlb_guid\n"
str += " _typelib_version_ = 1, 0\n"
# generate capitalized version of callback methods -
# that's how Python COM looks them up
if m.startswith("on"):
str += " def __init__(self): BaseClass.__init__(self, arg)\n"
str += "result = win32com.client.Dispatch('VirtualBox.CallbackWrapper')\n"
exec (str,d,d)
return d['result']
from win32api import GetCurrentThreadId
from win32event import MsgWaitForMultipleObjects, \
from pythoncom import PumpWaitingMessages
raise Exception("wait for events from the same thread you inited!")
# is it possible?
pass
# Waiting messages
else:
# Timeout
pass
import pythoncom
from win32file import CloseHandle
if h is not None:
CloseHandle(h)
pass
class PlatformXPCOM:
import xpcom
import xpcom.components
import xpcom.components
def getVirtualBox(self):
import xpcom.components
return 'XPCOM'
return False
def initPerThread(self):
import xpcom
def deinitPerThread(self):
import xpcom
d = {}
d['BaseClass'] = impl
d['arg'] = arg
str = ""
str += "import xpcom.components\n"
str += " def __init__(self): BaseClass.__init__(self, arg)\n"
str += "result = xpcom.components.classes['@virtualbox.org/VirtualBoxCallback;1'].createInstance()\n"
exec (str,d,d)
return d['result']
import xpcom
import xpcom
class PlatformWEBSERVICE:
# not really needed, but just fail early if misconfigured
import VirtualBox_services
import VirtualBox_wrappers
from VirtualBox_wrappers import IWebsessionManager2
if params is not None:
else:
def getVirtualBox(self):
from VirtualBox_wrappers import IWebsessionManager2
if url is None:
url = ""
if user is None:
user = ""
if passwd is None:
passwd = ""
def disconnect(self):
return 'WEBSERVICE'
return True
def initPerThread(self):
pass
def deinitPerThread(self):
pass
raise Exception("no callbacks for webservices")
# Webservices cannot do that yet
pass
try:
except:
pass
class SessionManager:
class VirtualBoxManager:
if style is None:
style = "MSCOM"
else:
style = "XPCOM"
# for webservices, enums are symbolic
try:
print "Installation problem: check that appropriate libs in place"
raise ne
except Exception,e:
print "init exception: ",e
else:
raise e
def getVirtualBox(self):
def initPerThread(self):
return session
def deinitPerThread(self):