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
12 """A parser for parsing the command line output for VirtualBox VMs."""
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
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
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
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
173 """An abstraction representing a virtual machine in VirtualBox."""
278
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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