def delete(self): """Delete the VM. VM must be locked or unregistered""" with VirtualBoxException.ExceptionHandler(): iMachine = self.getIMachine() iprogress = iMachine.delete(None) progress = Progress(iprogress) progress.waitForCompletion()
def createBaseStorage(self, size, variant=None, wait=True): """Create storage for the drive of the given size (in MB). Returns Progress instance. If wait is True, does not return until process completes.""" if variant is None: variant = Constants.MediumVariant_Standard with VirtualBoxException.ExceptionHandler(): progress = self.getIMedium().createBaseStorage(size, variant) progress = Progress(progress) if wait: progress.waitForCompletion() return progress
def deleteSnapshot(self, snapshot, wait=True): """Deletes the specified snapshot. Returns Progress instance. If wait is True, does not return until process completes.""" assert(snapshot is not None) with self.lock() as session: with VirtualBoxException.ExceptionHandler(): iprogress = session.console.deleteSnapshot(snapshot.id) progress = Progress(iprogress) # XXX Not sure if we need a lock for this or not if wait: progress.waitForCompletion() return progress
def takeSnapshot(self, name, description=None, wait=True): """Saves the current execution state and all settings of the machine and creates differencing images for all normal (non-independent) media. Returns Progress instance. If wait is True, does not return until process completes.""" assert(name is not None) with self.lock() as session: with VirtualBoxException.ExceptionHandler(): iprogress = session.console.takeSnapshot(name, description) progress = Progress(iprogress) # XXX Not sure if we need a lock for this or not if wait: progress.waitForCompletion() return progress
def cloneTo(self, target, variant=None, parent=None, wait=True): """Clone to the target hard drive. Returns Progress instance. If wait is True, does not return until process completes.""" if variant is None: variant = Constants.MediumVariant_Standard with VirtualBoxException.ExceptionHandler(): progress = self.getIMedium().cloneTo(target.getIMedium(), variant, parent) progress = Progress(progress) if wait: progress.waitForCompletion() return progress
def powerOn(self, type="gui", env=""): """Spawns a new process that executes a virtual machine. This is spawning a "remote session" in VirtualBox terms.""" # TODO: Add a wait argument if not self.isRegistered(): raise VirtualBoxException.VirtualBoxInvalidVMStateException( "VM is not registered") with VirtualBoxException.ExceptionHandler(): iMachine = self.getIMachine() session = Session.create() iprogress = iMachine.launchVMProcess(session.getISession(), type, env) progress = Progress(iprogress) progress.waitForCompletion() session.unlockMachine()