| Home | Trees | Indices | Help |
|---|
|
|
1 """ 2 vb - pyvb module that holds the implementaton of the VB class 3 that is meant to be instantiated as a singleton. 4 """ 5 from pyvb.constants import * 6 from pyvb.command import * 7 from pyvb.vm import * 8 from pyvb.ostype import * 9 from pyvb.dvd import * 10 from pyvb.hdd import * 11 from pyvb.exception import * 1214 """This class is meant to be an abstraction of the VirtualBox appliacation. 15 So there should really only be one instance of this class although there 16 is nothing preventing it from being instantiated multiple times.""" 2022822 """Run the specified command on the command line. 23 @param command: The command to run. 24 @type command: L{pyvb.command.VBCommand} 25 @return: The command object that was run. 26 @rtype: L{pyvb.command.VBCommand}""" 27 command.run() 28 return command2931 """Return a list of VirtualBox virtual machines. First we check 32 if a specific machine is being requested. In this case, we fetch 33 a single VM by altering the command that is run. Even if a single 34 VM is requested, a list is still returned so the interface will 35 remain unchanged. If a specific machine is not requested, a list 36 of all VMs is returned. 37 @keyword uuid: The id of a machine to retrieve. 38 @type uuid: String 39 @return: A list of L{pyvb.vm.vbVM} instances. 40 @rtype: List""" 41 if uuid: 42 cmd='%s %s'%(VB_COMMAND_SHOWVMINFO, uuid) 43 command=VBCommand(command=cmd) 44 else: 45 command=VBCommand(command=VB_COMMAND_LIST_VMS) 46 parser=vbVmParser() 47 command.run() 48 return parser.parse(command.read)4951 """Return a list of VitualBox-supported operating system types. 52 @return: A list of L{pyvb.ostype.vbOsType} instances. 53 @rtype: List""" 54 command=VBCommand(command=VB_COMMAND_LIST_OSTYPES) 55 parser=vbOsTypeParser() 56 command.run() 57 return parser.parse(command.read)5860 """Return a list of host DVDs. 61 @return: A list of L{pyvb.dvd.vbHostDvd} instances. 62 @rtype: List""" 63 command=VBCommand(command=VB_COMMAND_LIST_HOSTDVDS) 64 parser=vbHostDvdParser() 65 command.run() 66 return parser.parse(command.read)6769 """Return a list of DVDs used by virtual machines. 70 @return: A list of L{pyvb.dvd.vbDvd} instances. 71 @rtype: List""" 72 command=VBCommand(command=VB_COMMAND_LIST_DVDS) 73 parser=vbDvdParser() 74 command.run() 75 return parser.parse(command.read)7678 """Return a list of HDDs in use by VirtualBox. First, we check 79 if a specific HDD was requested. In this case, we fetch a single 80 HDD by altering the command that is run. Even if a single HDD is 81 requested, a list is still returned so the interface will remain 82 unchanged. If a specific HDD is requested, a list of all HDDs is 83 returned. 84 @return: A list of L{pyvb.hdd.vbHdd} instances. 85 @rtype: List""" 86 parser=vbHddParser() 87 if uuid: 88 cmd='%s %s'%(VB_COMMAND_SHOWVDIINFO, uuid) 89 command=VBCommand(command=cmd) 90 command.run() 91 return parser.parseSingle(command.read) 92 else: 93 command=VBCommand(command=VB_COMMAND_LIST_HDDS) 94 command.run() 95 return parser.parse(command.read)9698 """Return a specific VirtualBox virtual machine using the specified id. 99 @param uuid: The id of the machine to retrieve. 100 @type uuid: String 101 @return: The specified VirtualBox virtual machine. 102 @rtype: L{pyvb.vm.vbVM}""" 103 try: 104 return self.listVMS(uuid)[0] 105 except IndexError: 106 raise vbVmNotFound('Virtual Machine %s could not be found.'%(uuid))107109 """Return a specific VirtualBox HDD using the specified id. 110 @param uuid: The id of the HDD to retrieve. 111 @type uuid: String 112 @return: The specified VirtualBox HDD. 113 @rtype: L{pyvb.hdd.vbHdd}""" 114 try: 115 return self.listHdds(uuid)[0] 116 except IndexError: 117 return118120 """Start the specified VirtualBox virtual machine. 121 @param vm: The VM to start. 122 @type vm: L{pyvb.vm.vbVM}""" 123 cmd='%s %s -type %s'%(VB_COMMAND_STARTVM, vm.getUUID(), type) 124 command=VBCommand(command=cmd) 125 command.run()126128 """Poweroff the specified VirtualBox virtual machine. 129 @param vm: The VM to poweroff. 130 @type vm: L{pyvb.vm.vbVM}""" 131 cmd='%s %s %s'%(VB_COMMAND_CONTROLVM, vm.getUUID(), 'poweroff') 132 command=VBCommand(command=cmd) 133 command.run()134136 """ACPI poweroff the specified VirtualBox virtual machine. 137 @param vm: The VM to poweroff. 138 @type vm: L{pyvb.vm.vbVM}""" 139 cmd='%s %s %s'%(VB_COMMAND_CONTROLVM, vm.getUUID(), 'acpipowerbutton') 140 command=VBCommand(command=cmd) 141 command.run()142144 """Pause the specified VirtualBox virtual machine. 145 @param vm: The VM to pause. 146 @type vm: L{pyvb.vm.vbVM}""" 147 cmd='%s %s %s'%(VB_COMMAND_CONTROLVM, vm.getUUID(), 'pause') 148 command=VBCommand(command=cmd) 149 command.run()150152 """Resume the specified VirtualBox virtual machine. 153 @param vm: The VM to resume. 154 @type vm: L{pyvb.vm.vbVM}""" 155 cmd='%s %s %s'%(VB_COMMAND_CONTROLVM, vm.getUUID(), 'resume') 156 command=VBCommand(command=cmd) 157 command.run()158160 """Create a new virtual machine. 161 @param name: The name of the new machine. 162 @type name: String 163 @return: A new L{pyvb.vm.vbVM} instance. 164 @rtype: L{pyvb.vm.vbVM}""" 165 cmd='%s -name "%s" -register'%(VB_COMMAND_CREATEVM, name) 166 command=VBCommand(command=cmd) 167 parser=vbVmParser() 168 parser.attributes={'uuid':VB_RE_UUID} 169 command.run() 170 return parser.parse(command.read)[0]171173 """Create a new disk-drive. 174 @param filename: The location of the disk file. 175 @type filename: String 176 @param size: The size of the disk file in megabytes. 177 @type size: Int 178 @return: A new L{pyvb.hdd.vbHdd} instance. 179 @rtype: L{pyvb.hdd.vbHdd}""" 180 cmd='%s -filename "%s" -size "%s" -register'%(VB_COMMAND_CREATEVDI, filename, size) 181 command=VBCommand(command=cmd) 182 parser=vbHddParser() 183 parser.attributes={'uuid':VB_RE_UUID3} 184 command.run() 185 return parser.parse(command.read)[0]186188 """Create a new DVD. 189 @param filename: The location of the ISO file. 190 @type filename: String 191 @return: A new L{pyvb.dvd.vbDvd} instance. 192 @rtype: L{pyvb.dvd.vbDvd}""" 193 cmd='%s dvd %s'%(VB_COMMAND_REGISTERIMAGE, filename) 194 command=VBCommand(command=cmd) 195 command.run() 196 for dvd in self.listDvds(): 197 if filename==dvd.getPath(): 198 return dvd199201 """Attach a disk-drive to a virtual machine. 202 @param vm: The virtual machine we are attaching the disk-drive to. 203 @type vm: L{pyvb.vm.vbVM} 204 @param hdd: The disk-drive we are attaching. 205 @type hdd: L{pyvb.hdd.vbHdd} 206 @return: None 207 @rtype: None""" 208 cmd='%s %s -hda %s'%(VB_COMMAND_MODIFYVM, vm.getUUID(), hdd.getUUID()) 209 command=VBCommand(command=cmd) 210 command.run()211213 """Attach a DVD to a virtual machine. 214 @param vm: The virtual machine we are attaching the DVD to. 215 @type vm: L{pyvb.vm.vbVM} 216 @param dvd: The DVD we are attaching. 217 @type dvd: L{pyvb.dvd.vbDvd} 218 @return: None 219 @rtype: None""" 220 cmd='%s %s -dvd %s'%(VB_COMMAND_MODIFYVM, vm.getUUID(), dvd.getUUID()) 221 command=VBCommand(command=cmd) 222 command.run()223
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Apr 23 09:30:25 2008 | http://epydoc.sourceforge.net |