2010-02-20 7 views
3

J'ai créé une interface de ligne de commande pour virtualbox afin que la virtualbox puisse être contrôlée depuis une machine distante. maintenant j'essaye d'implémenter l'interface de commmand-line en utilisant python virtualbox api. Pour cela j'ai téléchargé le paquet pyvb (la documentation de python api montre les fonctions qui peuvent être utilisées pour implémenter ceci sous le paquetage pyvb). mais quand je donne pyvb.vb.VB.startVM(instance of VB class,pyvb.vm.vbVM)API Python pour VirtualBox

SERVEUR CODE LATÉRALE

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() 

il montre une erreur

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

Il serait probablement utile si vous avez posté le retraçage complet. –

Répondre

3

Vous pouvez vérifier l'API Python officiel de VirtualBox. pyvb ressemble à un emballage écrit par un tiers.

La boîte virtuelle sdk contient des exemples Python et une documentation API complète.

+0

S'il vous plaît ajouter un lien à votre réponse si cela ne vous dérange pas. –

+0

Cela devrait vous aider à démarrer: http://download.virtualbox.org/virtualbox/SDKRef.pdf – Jeroen