Package pyvb :: Module vm
[hide private]
[frames] | no frames]

Source Code for Module pyvb.vm

  1  """ 
  2  vm - pyvb module that holds the implementation of all VM related abstractions. 
  3  """ 
  4  from pyvb.constants import * 
  5  from pyvb.parser import * 
  6  from pyvb.command import * 
  7  from pyvb.sharedfolder import * 
  8  from pyvb.state import * 
  9  from pyvb.hdd import * 
 10   
11 -class vbVmParser(vbParser):
12 """A parser for parsing the command line output for VirtualBox VMs."""
13 - def __init__(self):
14 """Constructor. Initialize the found atributes dictionary which 15 holds the attributes that are found and initialize the dictionary 16 which contains the attribute we are looking for. 17 @return: A new instance. 18 @rtype: L{pyvb.vbVmParser}""" 19 self.found_attributes={} 20 self.attributes={'name':VB_RE_NAME,\ 21 'guestos':VB_RE_GUESTOS,\ 22 'uuid':VB_RE_UUID,\ 23 'configfile':VB_RE_CONFIGFILE,\ 24 'memorysize':VB_RE_MEMORYSIZE,\ 25 'vramsize':VB_RE_VRAMSIZE, 26 'bootmenumode':VB_RE_BOOTMENUMODE,\ 27 'acpi':VB_RE_ACPI,\ 28 'ioacpi':VB_RE_IOACPI,\ 29 'timeoffset':VB_RE_TIMEOFFSET,\ 30 'virtext':VB_RE_VIRTEXT,\ 31 'state':VB_RE_STATE,\ 32 'monitorcount':VB_RE_MONITORCOUNT,\ 33 'floppy':VB_RE_FLOPPY,\ 34 'primarymaster':VB_RE_PRIMARYMASTER,\ 35 'dvd':VB_RE_DVD,\ 36 'nic1':VB_RE_NIC1,\ 37 'nic2':VB_RE_NIC2,\ 38 'nic3':VB_RE_NIC3,\ 39 'nic4':VB_RE_NIC4,\ 40 'uart1':VB_RE_UART1,\ 41 'uart2':VB_RE_UART2,\ 42 'audio':VB_RE_AUDIO,\ 43 'clipboardmode':VB_RE_CLIPBOARDMODE,\ 44 'sharedfolders':VB_RE_SHAREDFOLDERS}
45
46 - def parse(self, file):
47 """Parse the given file. For each VM that is found, 48 we append the result to the list of returned VMs. 49 @param file: The file object to parse. 50 @type file: File 51 @return: The list of L{pyvb.vm.vbVM} instances. 52 @rtype: List""" 53 vms=[] 54 for result in self._parse(file): 55 found_vm=vbVM() 56 try: 57 found_vm.setName(result['name']) 58 except KeyError: 59 pass 60 try: 61 found_vm.setGuestos(result['guestos']) 62 except KeyError: 63 pass 64 try: 65 found_vm.setUUID(result['uuid']) 66 except KeyError: 67 pass 68 try: 69 found_vm.setConfigfile(result['configfile']) 70 except KeyError: 71 pass 72 try: 73 found_vm.setMemorysize(result['memorysize']) 74 except KeyError: 75 pass 76 try: 77 found_vm.setVramsize(result['vramsize']) 78 except KeyError: 79 pass 80 try: 81 found_vm.setBootmenumode(result['bootmenumode']) 82 except KeyError: 83 pass 84 try: 85 found_vm.setACPI(result['acpi']) 86 except KeyError: 87 pass 88 try: 89 found_vm.setIOACPI(result['ioacpi']) 90 except KeyError: 91 pass 92 try: 93 found_vm.setTimeoffset(result['timeoffset']) 94 except KeyError: 95 pass 96 try: 97 found_vm.setVirtext(result['virtext']) 98 except KeyError: 99 pass 100 try: 101 found_vm.setState(result['state']) 102 except KeyError: 103 pass 104 try: 105 found_vm.setMonitorcount(result['monitorcount']) 106 except KeyError: 107 pass 108 try: 109 found_vm.setFloppy(result['floppy']) 110 except KeyError: 111 pass 112 try: 113 found_vm.setPrimarymaster(result['primarymaster']) 114 except KeyError: 115 pass 116 try: 117 found_vm.setDVD(result['dvd']) 118 except KeyError: 119 pass 120 try: 121 found_vm.setNIC1(result['nic1']) 122 except KeyError: 123 pass 124 try: 125 found_vm.setNIC2(result['nic2']) 126 except KeyError: 127 pass 128 try: 129 found_vm.setNIC3(result['nic3']) 130 except KeyError: 131 pass 132 try: 133 found_vm.setNIC4(result['nic4']) 134 except KeyError: 135 pass 136 try: 137 found_vm.setUART1(result['uart1']) 138 except KeyError: 139 pass 140 try: 141 found_vm.setUART2(result['uart2']) 142 except KeyError: 143 pass 144 try: 145 found_vm.setClipboardmode(result['clipboardmode']) 146 except KeyError: 147 pass 148 try: 149 found_vm.setSharedfolders(result['sharedfolders']) 150 except KeyError: 151 pass 152 vms.append(found_vm) 153 return vms
154
155 - def parseHddUUID(self, hdd):
156 """Parse the specified HDD and return the uuid. 157 @param hdd: The hdd string to parse. 158 @type hdd: String 159 @return: The uuid of the specified HDD. 160 @rtype: String""" 161 return VB_RE_UUID2.match(hdd).groups()[1]
162
163 - def parseState(self, state):
164 """Parse the specified machine state and return a tuple 165 containing the state name, and the state date. 166 @param state: The state string to parse. 167 @type state: String 168 @return: A tuple containing the state components. 169 @rtype: Tuple""" 170 return VB_RE_STATE2.match(state).groups()
171
172 -class vbVM:
173 """An abstraction representing a virtual machine in VirtualBox."""
174 - def __init__(self, **kw):
175 """Constructor. Initialize attributes. 176 @return: A new instance. 177 @rtype: L{pyvb.vm.vbVM}""" 178 try: 179 self.setName(kw['name']) 180 except KeyError: 181 self.setName('') 182 try: 183 self.setGuestos(kw['guestos']) 184 except KeyError: 185 self.setGuestos('') 186 try: 187 self.setUUID(kw['uuid']) 188 except KeyError: 189 self.setUUID('') 190 try: 191 self.setConfigfile(kw['configfile']) 192 except KeyError: 193 self.setConfigfile('') 194 try: 195 self.setMemorysize(kw['memorysize']) 196 except KeyError: 197 self.setMemorysize('') 198 try: 199 self.setVramsize(kw['vramsize']) 200 except Exception, e: 201 self.setVramsize('') 202 try: 203 self.setBootmenumode(kw['bootmenumode']) 204 except KeyError: 205 self.setBootmenumode('') 206 try: 207 self.setACPI(kw['acpi']) 208 except KeyError: 209 self.setACPI('') 210 try: 211 self.setIOACPI(kw['ioacpi']) 212 except KeyError: 213 self.setIOACPI('') 214 try: 215 self.setTimeoffset(kw['timeoffset']) 216 except KeyError: 217 self.setTimeoffset('') 218 try: 219 self.setVirtext(kw['virtext']) 220 except KeyError: 221 self.setVirtext('') 222 try: 223 self.setState(kw['state']) 224 except KeyError: 225 self.setState('') 226 try: 227 self.setMonitorcount(kw['monitorcount']) 228 except KeyError: 229 self.setMonitorcount('') 230 try: 231 self.setFloppy(kw['floppy']) 232 except KeyError: 233 self.setFloppy('') 234 try: 235 self.setPrimarymaster(kw['primarymaster']) 236 except KeyError: 237 self.setPrimarymaster('') 238 try: 239 self.setDVD(kw['dvd']) 240 except KeyError: 241 self.setDVD('') 242 try: 243 self.setNIC1(kw['nic1']) 244 except KeyError: 245 self.setNIC1('') 246 try: 247 self.setNIC2(kw['nic2']) 248 except KeyError: 249 self.setNIC2('') 250 try: 251 self.setNIC3(kw['nic3']) 252 except KeyError: 253 self.setNIC3('') 254 try: 255 self.setNIC4(kw['nic4']) 256 except KeyError: 257 self.setNIC4('') 258 try: 259 self.setUART1(kw['uart1']) 260 except KeyError: 261 self.setUART1('') 262 try: 263 self.setUART2(kw['uart2']) 264 except KeyError: 265 self.setUART2('') 266 try: 267 self.setAudio(kw['audio']) 268 except KeyError: 269 self.setAudio('') 270 try: 271 self.setClipboardmode(kw['clipboardmode']) 272 except KeyError: 273 self.setClipboardmode('') 274 try: 275 self.setSharedfolders(kw['sharedfolders']) 276 except KeyError: 277 self.setSharedfolders('')
278
279 - def setName(self, name):
280 """Set the name attribute of this L{pyvb.vm.vbVM} instance. 281 @param name: The name attribute. 282 @type name: String 283 @return: None 284 @rtype: None""" 285 self.name=name
286
287 - def setGuestos(self, guestos):
288 """Set the guestos attribute of this L{pyvb.vm.vbVM} instance. 289 @param guestos: The guestos attribute. 290 @type guestos: String 291 @return: None 292 @rtype: None""" 293 self.guestos=guestos
294
295 - def setUUID(self, uuid):
296 """Set the uuid attribute of this L{pyvb.vm.vbVM} instance. 297 @param uuid: The uuid attribute. 298 @type uuid: String 299 @return: None 300 @rtype: None""" 301 self.uuid=uuid
302
303 - def setConfigfile(self, configfile):
304 """Set the configfile attribute of this L{pyvb.vm.vbVM} instance. 305 @param configfile: The configfile attribute. 306 @type configfile: String 307 @return: None 308 @rtype: None""" 309 self.configfile=configfile
310
311 - def setMemorysize(self, memorysize):
312 """Set the memorysize attribute of this L{pyvb.vm.vbVM} instance. 313 @param memorysize: The memorysize attribute. 314 @type memorysize: String 315 @return: None 316 @rtype: None""" 317 self.memorysize=memorysize
318
319 - def setVramsize(self, vramsize):
320 """Set the vramsize attribute of this L{pyvb.vm.vbVM} instance. 321 @param vramsize: The vramsize attribute. 322 @type vramsize: String 323 @return: None 324 @rtype: None""" 325 self.vramsize=vramsize
326
327 - def setBootmenumode(self, bootmenumode):
328 """Set the bootmenumode attribute of this L{pyvb.vm.vbVM} instance. 329 @param bootmenumode: The bootmenumode attribute. 330 @type bootmenumode: String 331 @return: None 332 @rtype: None""" 333 self.bootmenumode=bootmenumode
334
335 - def setACPI(self, acpi):
336 """Set the acpi attribute of this L{pyvb.vm.vbVM} instance. 337 @param acpi: The acpi attribute. 338 @type acpi: String 339 @return: None 340 @rtype: None""" 341 self.acpi=acpi
342
343 - def setIOACPI(self, ioacpi):
344 """Set the ioacpi attribute of this L{pyvb.vm.vbVM} instance. 345 @param ioacpi: The ioacpi attribute. 346 @type ioacpi: String 347 @return: None 348 @rtype: None""" 349 self.ioacpi=ioacpi
350
351 - def setTimeoffset(self, timeoffset):
352 """Set the timeoffset attribute of this L{pyvb.vm.vbVM} instance. 353 @param timeoffset: The timeoffset attribute. 354 @type timeoffset: String 355 @return: None 356 @rtype: None""" 357 self.timeoffset=timeoffset
358
359 - def setVirtext(self, virtext):
360 """Set the virtext attribute of this L{pyvb.vm.vbVM} instance. 361 @param virtext: The virtext attribute of this L{pyvb.vm.vbVM} instance. 362 @type virtext: String 363 @return: None 364 @rtype: None""" 365 self.virtext=virtext
366
367 - def setState(self, state):
368 """Set the state attribute of this L{pyvb.vm.vbVM} instance. 369 @param state: The state attribute. 370 @type state: String 371 @return: None 372 @rtype: None""" 373 self.state=state
374
375 - def setMonitorcount(self, monitorcount):
376 """Set the monitorcount attribute of this L{pyvb.vm.vbVM} instance. 377 @param monitorcount: The monitorcount attribute. 378 @type monitorcount: String 379 @return: None 380 @rtype: None""" 381 self.monitorcount=monitorcount
382
383 - def setFloppy(self, floppy):
384 """Set the floppy attribute of this L{pyvb.vm.vbVM} instance. 385 @param floppy: The floppy attribute. 386 @type floppy: String 387 @return: None 388 @rtype: None""" 389 self.floppy=floppy
390
391 - def setPrimarymaster(self, primarymaster):
392 """Set the primarymaster attribute of this L{pyvb.vm.vbVM} instance. 393 @param primarymaster: The primarymaster attribute. 394 @type primarymaster: String 395 @return: None 396 @rtype: None""" 397 self.primarymaster=primarymaster
398
399 - def setDVD(self, dvd):
400 """Set the dvd attribute of this L{pyvb.vm.vbVM} instance. 401 @param dvd: The dvd attribute. 402 @type dvd: String 403 @return: None 404 @rtype: None""" 405 self.dvd=dvd
406
407 - def setNIC1(self, nic1):
408 """Set the nic1 attribute of this L{pyvb.vm.vbVM} instance. 409 @param nic1: The nic1 attribute. 410 @type nic1: String 411 @return: None 412 @rtype: None""" 413 self.nic1=nic1
414
415 - def setNIC2(self, nic2):
416 """Set the nic2 attribute of this L{pyvb.vm.vbVM} instance. 417 @param nic2: The nic2 attribute. 418 @type nic2: String 419 @return: None 420 @rtype: None""" 421 self.nic2=nic2
422
423 - def setNIC3(self, nic3):
424 """Set the nic3 attribute of this L{pyvb.vm.vbVM} instance. 425 @param nic3: The nic3 attribute. 426 @type nic3: String 427 @return: None 428 @rtype: None""" 429 self.nic3=nic3
430
431 - def setNIC4(self, nic4):
432 """Set the nic4 attribute of this L{pyvb.vm.vbVM} instance. 433 @param nic4: The nic4 attribute. 434 @type nic4: String 435 @return: None 436 @rtype: None""" 437 self.nic4=nic4
438
439 - def setUART1(self, uart1):
440 """Set the uart attribute of this L{pyvb.vm.vbVM} instance. 441 @param uart1: The uart1 attribute. 442 @type uart1: String 443 @return: None 444 @rtype: None""" 445 self.uart1=uart1
446
447 - def setUART2(self, uart2):
448 """Set the uart2 attribute of this L{pyvb.vm.vbVM} instance. 449 @param uart2: The uart2 attribute. 450 @type uart2: String 451 @return: None 452 @rtype: None""" 453 self.uart2=uart2
454
455 - def setAudio(self, audio):
456 """Set the audio attribute of this L{pyvb.vm.vbVM} instance. 457 @param audio: The audio attribute. 458 @type audio: String 459 @return: None 460 @rtype: None""" 461 self.audio=audio
462
463 - def setClipboardmode(self, clipboardmode):
464 """Set the clipboardmode attribute of this L{pyvb.vm.vbVM} instance. 465 @param clipboardmode: The clipboardmode attribute. 466 @type clipboardmode: String 467 @return: None 468 @rtype: None""" 469 self.clipboardmode=clipboardmode
470
471 - def setSharedfolders(self, sharedfolders):
472 """Set the sharedfolders attribute of this L{pyvb.vm.vbVM} instance. 473 @param sharedfolders: The sharedfolders attribute. 474 @type sharedfolders: String 475 @return: None 476 @rtype: None""" 477 self.sharedfolders=sharedfolders
478
479 - def getName(self):
480 """Return the name attribute of this L{pyvb.vm.vbVM} instance. 481 @return: The name attribute. 482 @rtype: String""" 483 return self.name
484
485 - def getGuestos(self):