
class VBoxStarter():
  def __init__(self, mgr, vmname):
    print "VBoxStarter::__init__(%s)" % str(vmname)
    self.vmname = vmname
    #from vboxapi import VirtualBoxManager
    #self.mgr = VirtualBoxManager(None, None)
    self.mgr = mgr
    self.vbox = self.mgr.vbox

  def startvm(self):    
    try:
      self.mach = self.vbox.findMachine(self.vmname)
    except Exception, e:
      #This will happen if you try to start non-existent or unregistered VM
      print e
      return False
    self.session = self.mgr.mgr.getSessionObject(self.vbox)
    try:
      self.progress = self.mach.launchVMProcess(self.session, "gui", "")        
      self.progress.waitForCompletion(-1)
    except Exception, e:
      #This will happen if you try to start the same VM twice
      print e
      return False
    print "self.progress.percent = ", self.progress.percent
    if self.progress.percent != 100:
      #This will happen if you attemp to start VirtualBox with unloaded "vboxdrv" module.
      return False