Python的VirtualBox API

3
我已经为VirtualBox制作了一个命令行界面,以便可以从远程机器控制VirtualBox。现在我正在尝试使用Python VirtualBox API实现命令行界面。为此,我下载了pyvb包(Python API文档显示可以在pyvb包下使用的函数)。但是当我执行pyvb.vb.VB.startVM(VB类的实例, pyvb.vm.vbVM)时,
服务器端代码如下:
from pyvb.constants import *

from pyvb.vm import *

from pyvb.vb import *

import xpcom

import pyvb

import os

import socket

import threading

class ClientThread ( threading.Thread ):

   # Override Thread's __init__ method to accept the parameters needed:
   def __init__ ( self, channel, details ):

      self.channel = channel
      self.details = details
      threading.Thread.__init__ ( self )

   def run ( self ):

      print 'Received connection:', self.details [ 0 ]
      while 1:     
         s= self.channel.recv ( 1024 )
         if(s!='end'):
            if(s=='start'):
              v=VB() 
              pyvb.vb.VB.startVM(v,pyvb.vm.vbVM)

         else:
           self.channel.close()
           break
      print 'Closed connection:', self.details [ 0 ]


server = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
server.bind ( ( '127.0.0.1', 2897 ) )
server.listen ( 5 )

while True:
   channel, details = server.accept()
   ClientThread ( channel, details ).start()

出现错误提示

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
    self.run()
  File "news.py", line 27, in run
    pyvb.vb.VB.startVM(v,pyvb.vm.vbVM.getUUID(m))
  File "/usr/lib/python2.5/site-packages/pyvb-0.0.2-py2.5.egg/pyvb/vb.py", line 65, in startVM
    cmd='%s %s'%(VB_COMMAND_STARTVM, vm.getUUID())
AttributeError: 'str' object has no attribute 'getUUID'

如果您发布完整的回溯信息,可能会更有帮助。 - Devin Jeanpierre
1个回答

3

您可能想要查看Virtualbox的官方Python API。pyvb似乎是由第三方编写的包装器。

Virtualbox SDK包含Python示例和完整的API文档。


这应该可以帮助你入门:http://download.virtualbox.org/virtualbox/SDKRef.pdf - Jeroen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接