2010-02-20 62 views
3

我爲virtualbox製作了一個命令行界面,以便可以從遠程計算機控制virtualbox。現在我正在嘗試使用python virtualbox API實現命令行界面。爲此,我下載了pyvb軟件包(python api文檔顯示了可用於在pyvb軟件包下實現此功能的函數)。但是當我給pyvb.vb.VB.startVM(instance of VB class,pyvb.vm.vbVM)VirtualBox的Python API

服務器端代碼

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' 
+0

如果您發佈了完整的回溯,這可能會有所幫助。 – 2010-02-20 08:08:43

回答

3

你可能要檢查從VirtualBox的官方Python API。 pyvb看起來像是由第三方編寫的封裝。

virtualbox sdk包含Python示例和完整的API文檔。

+0

如果你不介意,請添加一個鏈接到你的答案。 – 2011-01-17 15:07:07

+0

這應該讓你開始:http://download.virtualbox.org/virtualbox/SDKRef.pdf – Jeroen 2011-01-18 09:43:43