예제 #1
0
파일: pyVBoxTest.py 프로젝트: von/pyVBox
 def _cleanup(self):
     """Unregister test HD and VM if they are registered."""
     # Do machine first to detach any HDs
     try:
         machine = VirtualMachine.find(self.testVMname)
     except:
         pass
     else:
         machine.eject()
     try:
         harddisk = HardDisk.find(self.testHDpath)
     except:
         pass
     else:
         harddisk.close()
     try:
         machine = VirtualMachine.find(self.cloneVMname)
     except Exception as e:
         pass
     else:
         machine.eject()
         machine.delete()
     try:
         clonedisk = HardDisk.find(self.cloneHDpath)
     except:
         pass
     else:
         clonedisk.close()
     try:
         os.remove(self.cloneHDpath)
     except:
         pass
예제 #2
0
 def _cleanup(self):
     """Unregister test HD and VM if they are registered."""
     # Do machine first to detach any HDs
     try:
         machine = VirtualMachine.find(self.testVMname)
     except:
         pass
     else:
         machine.eject()
     try:
         harddisk = HardDisk.find(self.testHDpath)
     except:
         pass
     else:
         harddisk.close()
     try:
         machine = VirtualMachine.find(self.cloneVMname)
     except Exception as e:
         pass
     else:
         machine.eject()
         machine.delete()
     try:
         clonedisk = HardDisk.find(self.cloneHDpath)
     except:
         pass
     else:
         clonedisk.close()
     try:
         os.remove(self.cloneHDpath)
     except:
         pass
예제 #3
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument")
     vm = VirtualMachine.find(args.pop(0))
     vm.resume()
     return 0
예제 #4
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing virtual machine argument")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing target directory argument")
     targetDir = args.pop(0)
     verboseMsg("Backing up %s to %s" % (vm, targetDir))
     if vm.isRunning():
         verboseMsg("Pausing VM...")
         # Must wait until paused or will have race condition for lock
         # on disks.
         vm.pause(wait=True)
         atexit.register(vm.resume)
     # Todo: Backup settings file in some way.
     # Todo: Want to back up devices than hard drives?
     disks = vm.getHardDrives()
     for disk in disks:
         targetFilename = os.path.join(targetDir, disk.basename())
         # Todo: Need to resolve file already existing here.
         verboseMsg("Backing up disk %s to %s (%d bytes)" %
                    (disk, targetFilename, disk.size))
         progress = disk.clone(targetFilename, wait=False)
         show_progress(progress)
         # Remove newly created clone from registry
         clone = HardDisk.find(targetFilename)
         clone.close()
예제 #5
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing source VM name argument")
     srcVM = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing target VM name argument")
     targetName = args.pop(0)
     message("Cloning %s to %s" % (srcVM, targetName))
     cloneVM = srcVM.clone(targetName)
     # Now clone and attach disks
     disks = srcVM.getHardDrives()
     for disk in disks:
         # Generate new HD filename by prefixing new VM name.
         # Not the greatest, but not sure what the best way is.
         targetFilename = os.path.join(disk.dirname(),
                                       "%s-%s" % (targetName, disk.name))
         # Todo: Need to resolve file already existing here.
         message("Cloning disk %s to %s (%d bytes)" %
                 (disk, os.path.basename(targetFilename), disk.size))
         progress = disk.clone(targetFilename, wait=False)
         show_progress(progress)
         cloneHD = HardDisk.find(targetFilename)
         message("Attaching %s to %s" % (cloneHD, cloneVM))
         cloneVM.attachMedium(cloneHD)
     return 0
예제 #6
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     mode = "gui"
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument")
     vm = VirtualMachine.find(args.pop(0))
     vm.powerOn(type=mode)
예제 #7
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing source VM name argument")
     srcVM = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing target VM name argument")
     targetName = args.pop(0)
     message("Cloning %s to %s" % (srcVM, targetName))
     cloneVM = srcVM.clone(targetName)
     # Now clone and attach disks
     disks = srcVM.getHardDrives()
     for disk in disks:
         # Generate new HD filename by prefixing new VM name.
         # Not the greatest, but not sure what the best way is.
         targetFilename = os.path.join(disk.dirname(),
                                       "%s-%s" % (targetName, disk.name))
         # Todo: Need to resolve file already existing here.
         message("Cloning disk %s to %s (%d bytes)"
                 % (disk,
                    os.path.basename(targetFilename),
                    disk.size))
         progress = disk.clone(targetFilename, wait=False)
         show_progress(progress)
         cloneHD = HardDisk.find(targetFilename)
         message("Attaching %s to %s" % (cloneHD, cloneVM))
         cloneVM.attachMedium(cloneHD)
     return 0
예제 #8
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     mode = "gui"
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument");
     vm = VirtualMachine.find(args.pop(0))
     vm.powerOn(type=mode)
예제 #9
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing virtual machine argument")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing target directory argument")
     targetDir = args.pop(0)
     verboseMsg("Backing up %s to %s" % (vm, targetDir))
     if vm.isRunning():
         verboseMsg("Pausing VM...")
         # Must wait until paused or will have race condition for lock
         # on disks.
         vm.pause(wait=True)
         atexit.register(vm.resume)
     # Todo: Backup settings file in some way.
     # Todo: Want to back up devices than hard drives?
     disks = vm.getHardDrives()
     for disk in disks:
         targetFilename = os.path.join(targetDir, disk.basename())
         # Todo: Need to resolve file already existing here.
         verboseMsg("Backing up disk %s to %s (%d bytes)" % (disk,
                                                             targetFilename,
                                                             disk.size))
         progress = disk.clone(targetFilename, wait=False)
         show_progress(progress)
         # Remove newly created clone from registry
         clone = HardDisk.find(targetFilename)
         clone.close()
예제 #10
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing VM name")
     vm = VirtualMachine.find(args.pop(0))
     snapshot = vm.getCurrentSnapshot()
     progress = vm.deleteSnapshot(snapshot, wait=False)
     show_progress(progress)
예제 #11
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing VM name")
     vm = VirtualMachine.find(args.pop(0))
     snapshot = vm.getCurrentSnapshot()
     progress = vm.deleteSnapshot(snapshot, wait=False)
     show_progress(progress)
예제 #12
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument")
     for name in args:
         vm = VirtualMachine.find(name)
         verboseMsg("Ejecting %s" % vm)
         vm.eject()
     return 0
예제 #13
0
 def testRegister(self):
     """Test VirtualMachine.register() and related functions"""
     machine = VirtualMachine.open(self.testVMpath)
     machine.register()
     self.assertEqual(True, machine.isRegistered())
     m2 = VirtualMachine.find(machine.name)
     self.assertEqual(machine.id, m2.id)
     machine.unregister()
     self.assertEqual(False, machine.isRegistered())
예제 #14
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument");
     for name in args:
         vm = VirtualMachine.find(name)
         verboseMsg("Ejecting %s" % vm)
         vm.eject()
     return 0
예제 #15
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing virtual machine argument")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing hard disk filenames")
     for hd in args:
         hd = cls.harddisk(hd)
         verboseMsg("Attaching %s" % hd)
         vm.attachMedium(hd)
     return 0
예제 #16
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument");
     for filename in args:
         vm = VirtualMachine.find(args.pop(0))
         if vm.isRegistered():
             verboseMsg("Unregistering VM %s" % vm)
             vm.unregister()
         else:
             errorMsg("VM \"%s\" is not registered." % vm)
     return 0
예제 #17
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing VM name")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) == 0:
         raise Exception("Missing snapshot name")
     name = args.pop(0)
     description = None
     if len(args) > 0:
         description = args.pop(0)
     vm.takeSnapshot(name, description)
예제 #18
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing VM name")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) == 0:
         raise Exception("Missing snapshot name")
     name = args.pop(0)
     description = None
     if len(args) > 0:
         description = args.pop(0)
     vm.takeSnapshot(name, description)
예제 #19
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) < 1:
         raise Exception("Missing virtual machine argument")
     vm = VirtualMachine.find(args.pop(0))
     if len(args) < 1:
         raise Exception("Missing hard disk filenames")
     for hd in args:
         hd = cls.harddisk(hd)
         verboseMsg("Attaching %s" % hd)
         vm.attachMedium(hd)
     return 0
예제 #20
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     """Invoke the command. Return exit code for program."""
     if len(args) == 0:
         raise Exception("Missing virtual machine name argument")
     for filename in args:
         vm = VirtualMachine.find(args.pop(0))
         if vm.isRegistered():
             verboseMsg("Unregistering VM %s" % vm)
             vm.unregister()
         else:
             errorMsg("VM \"%s\" is not registered." % vm)
     return 0
예제 #21
0
파일: pyvbox.py 프로젝트: aburan28/pyVBox
 def invoke(cls, args):
     if len(args) == 0:
         vms = VirtualMachine.getAll()
         verboseMsg("Registered VMs:")
         for vm in vms:
             try:
                 print "\t%s" % vm
             except Exception as e:
                 errorMsg("Could not display VM: %s" % str(e))
     else:
         for vmName in args:
             try:
                 vm = VirtualMachine.find(vmName)
                 print_vm(vm)
             except Exception as e:
                 errorMsg("Could not display information about VM \"%s\": %s" % (vmName, str(e)))
예제 #22
0
파일: pyvbox.py 프로젝트: szydre/pyVBox
 def invoke(cls, args):
     if len(args) == 0:
         vms = VirtualMachine.getAll()
         verboseMsg("Registered VMs:")
         for vm in vms:
             try:
                 print "\t%s" % vm
             except Exception as e:
                 errorMsg("Could not display VM: %s" % str(e))
     else:
         for vmName in args:
             try:
                 vm = VirtualMachine.find(vmName)
                 print_vm(vm)
             except Exception as e:
                 errorMsg(
                     "Could not display information about VM \"%s\": %s" %
                     (vmName, str(e)))