50
50
def onAdditionsStateChange(self):
51
51
print "%s: onAdditionsStateChange" %(self.mach.name)
53
def onDVDDriveChange(self):
54
print "%s: onDVDDriveChange" %(self.mach.name)
56
def onFloppyDriveChange(self):
57
print "%s: onFloppyDriveChange" %(self.mach.name)
59
53
def onNetworkAdapterChange(self, adapter):
60
54
print "%s: onNetworkAdapterChange" %(self.mach.name)
68
62
def onStorageControllerChange(self):
69
63
print "%s: onStorageControllerChange" %(self.mach.name)
65
def onMediumChange(self, attachment):
66
print "%s: onMediumChange" %(self.mach.name)
71
68
def onVRDPServerChange(self):
72
69
print "%s: onVRDPServerChange" %(self.mach.name)
216
213
print "%d %%\r" %(p.percent),
217
214
sys.stdout.flush()
218
215
p.waitForCompletion(wait)
216
ctx['global'].waitForEvents(0)
219
217
except KeyboardInterrupt:
220
218
print "Interrupted."
221
def reportError(ctx,session,rc):
222
if not ctx['remote']:
223
print session.QueryErrorObject(rc)
222
226
def createVm(ctx,name,kind,base):
237
241
session = ctx['global'].openMachineSession(id)
239
243
mach = session.machine
240
for d in ctx['global'].getArray(mach, 'hardDiskAttachments'):
241
mach.detachHardDisk(d.controller, d.port, d.device)
244
for d in ctx['global'].getArray(mach, 'mediumAttachments'):
245
mach.detachDevice(d.controller, d.port, d.device)
243
247
traceback.print_exc()
244
248
mach.saveSettings()
274
278
# if session not opened, close doesn't make sense
277
# Not yet implemented error string query API for remote API
278
if not ctx['remote']:
279
print session.QueryErrorObject(rc)
281
reportError(ctx,session,rc)
281
283
def getMachines(ctx, invalidate = False):
282
284
if ctx['vb'] is not None:
335
337
vbox.unregisterCallback(cb)
340
def takeScreenshot(ctx,console,args):
341
from PIL import Image
342
display = console.display
346
f = "/tmp/screenshot.png"
350
w = console.display.width
354
h = console.display.height
355
print "Saving screenshot (%d x %d) in %s..." %(w,h,f)
356
data = display.takeScreenShotSlow(w,h)
359
im = Image.frombuffer(mode, size, data, "raw", mode, 0, 1)
363
def teleport(ctx,session,console,args):
364
if args[0].find(":") == -1:
365
print "Use host:port format for teleport target"
367
(host,port) = args[0].split(":")
374
print "Teleporting to %s:%d..." %(host,port)
375
progress = console.teleport(host, port, passwd)
376
progressBar(ctx, progress, 100)
377
completed = progress.completed
378
rc = int(progress.resultCode)
382
reportError(ctx,session,rc)
337
384
def cmdExistingVm(ctx,mach,cmd,args):
347
394
traceback.print_exc()
349
if session.state != ctx['ifaces'].SessionState_Open:
396
if str(session.state) != str(ctx['ifaces'].SessionState_Open):
350
397
print "Session to '%s' in wrong state: %s" %(mach.name, session.state)
352
399
# unfortunately IGuest is suppressed, thus WebServices knows not about it
362
409
'stats': lambda: guestStats(ctx, mach),
363
410
'guest': lambda: guestExec(ctx, mach, console, args),
364
411
'monitorGuest': lambda: monitorGuest(ctx, mach, console, args),
365
'save': lambda: progressBar(ctx,console.saveState())
412
'save': lambda: progressBar(ctx,console.saveState()),
413
'screenshot': lambda: takeScreenshot(ctx,console,args),
414
'teleport': lambda: teleport(ctx,session,console,args)
423
472
def listCmd(ctx, args):
424
473
for m in getMachines(ctx, True):
425
print "Machine '%s' [%s], state=%s" %(m.name,m.id,m.sessionState)
474
if m.teleporterEnabled:
478
print "%sMachine '%s' [%s], state=%s" %(tele,m.name,m.id,m.sessionState)
428
481
def getControllerType(type):
455
523
print " Name [name]: %s" %(mach.name)
456
524
print " ID [n/a]: %s" %(mach.id)
457
525
print " OS Type [n/a]: %s" %(os.description)
526
print " Firmware [firmwareType]: %s (%s)" %(getFirmwareType(mach.firmwareType),mach.firmwareType)
459
528
print " CPUs [CPUCount]: %d" %(mach.CPUCount)
460
529
print " RAM [memorySize]: %dM" %(mach.memorySize)
464
533
print " Clipboard mode [clipboardMode]: %d" %(mach.clipboardMode)
465
534
print " Machine status [n/a]: %d" % (mach.sessionState)
536
if mach.teleporterEnabled:
537
print " Teleport target on port %d (%s)" %(mach.teleporterPort, mach.teleporterPassword)
467
539
bios = mach.BIOSSettings
468
540
print " ACPI [BIOSSettings.ACPIEnabled]: %s" %(asState(bios.ACPIEnabled))
469
541
print " APIC [BIOSSettings.IOAPICEnabled]: %s" %(asState(bios.IOAPICEnabled))
470
print " PAE [PAEEnabled]: %s" %(asState(int(mach.PAEEnabled)))
471
print " Hardware virtualization [HWVirtExEnabled]: " + asState(mach.HWVirtExEnabled)
472
print " VPID support [HWVirtExVPIDEnabled]: " + asState(mach.HWVirtExVPIDEnabled)
542
hwVirtEnabled = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled)
543
print " Hardware virtualization [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled,value)]: " + asState(hwVirtEnabled)
544
hwVirtVPID = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_VPID)
545
print " VPID support [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_VPID,value)]: " + asState(hwVirtVPID)
546
hwVirtNestedPaging = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_NestedPaging)
547
print " Nested paging [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_NestedPaging,value)]: " + asState(hwVirtNestedPaging)
473
549
print " Hardware 3d acceleration[accelerate3DEnabled]: " + asState(mach.accelerate3DEnabled)
474
print " Nested paging [HWVirtExNestedPagingEnabled]: " + asState(mach.HWVirtExNestedPagingEnabled)
550
print " Hardware 2d video acceleration[accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled)
475
552
print " Last changed [n/a]: " + time.asctime(time.localtime(long(mach.lastStateChange)/1000))
476
553
print " VRDP server [VRDPServer.enabled]: %s" %(asState(mach.VRDPServer.enabled))
482
559
for controller in controllers:
483
560
print " %s %s bus: %d" % (controller.name, getControllerType(controller.controllerType), controller.bus)
485
disks = ctx['global'].getArray(mach, 'hardDiskAttachments')
488
print " Hard disk(s):"
490
print " Controller: %s port: %d device: %d:" % (disk.controller, disk.port, disk.device)
492
print " id: %s" %(hd.id)
493
print " location: %s" %(hd.location)
494
print " name: %s" %(hd.name)
495
print " format: %s" %(hd.format)
499
if dvd.getHostDrive():
500
hdvd = dvd.getHostDrive()
502
print " Host disk: %s" %(hdvd.name)
506
vdvd = dvd.getImage()
508
print " Image at: %s" %(vdvd.location)
509
print " Size: %s" %(vdvd.size)
510
print " Id: %s" %(vdvd.id)
513
floppy = mach.floppyDrive
514
if floppy.getHostDrive():
515
hfloppy = floppy.getHostDrive()
517
print " Host disk: %s" %(hfloppy.name)
520
if floppy.getImage():
521
vfloppy = floppy.getImage()
523
print " Image at: %s" %(vfloppy.location)
524
print " Size: %s" %(vfloppy.size)
562
attaches = ctx['global'].getArray(mach, 'mediumAttachments')
567
print " Controller: %s port: %d device: %d type: %s:" % (a.controller, a.port, a.device, a.type)
569
if a.type == ctx['global'].constants.DeviceType_HardDisk:
571
print " Id: %s" %(m.id)
572
print " Location: %s" %(m.location)
573
print " Name: %s" %(m.name)
574
print " Format: %s" %(m.format)
576
if a.type == ctx['global'].constants.DeviceType_DVD:
579
print " Id: %s" %(m.id)
580
print " Name: %s" %(m.name)
582
print " Host DVD %s" %(m.location)
584
print " [passthrough mode]"
586
print " Virtual image at %s" %(m.location)
587
print " Size: %s" %(m.size)
589
if a.type == ctx['global'].constants.DeviceType_Floppy:
592
print " Id: %s" %(m.id)
593
print " Name: %s" %(m.name)
595
print " Host floppy %s" %(m.location)
597
print " Virtual image at %s" %(m.location)
598
print " Size: %s" %(m.size)
614
687
cmdExistingVm(ctx, mach, 'guest', ' '.join(args[2:]))
690
def screenshotCmd(ctx, args):
692
print "usage: screenshot name file <width> <height>"
694
mach = argsToMach(ctx,args)
697
cmdExistingVm(ctx, mach, 'screenshot', args[2:])
700
def teleportCmd(ctx, args):
702
print "usage: teleport name host:port <password>"
704
mach = argsToMach(ctx,args)
707
cmdExistingVm(ctx, mach, 'teleport', args[2:])
710
def openportalCmd(ctx, args):
712
print "usage: openportal name port <password>"
714
mach = argsToMach(ctx,args)
722
if not mach.teleporterEnabled or mach.teleporterPort != port or passwd:
723
session = ctx['global'].openMachineSession(mach.id)
724
mach1 = session.machine
725
mach1.teleporterEnabled = True
726
mach1.teleporterPort = port
727
mach1.teleporterPassword = passwd
730
startVm(ctx, mach, "gui")
733
def closeportalCmd(ctx, args):
735
print "usage: closeportal name"
737
mach = argsToMach(ctx,args)
740
if mach.teleporterEnabled:
741
session = ctx['global'].openMachineSession(mach.id)
742
mach1 = session.machine
743
mach1.teleporterEnabled = False
617
749
def setvarCmd(ctx, args):
618
750
if (len(args) < 4):
619
751
print "usage: setvar [vmname|uuid] expr value"
673
805
cnt = host.processorCount
674
806
print "Processor count:",cnt
675
807
for i in range(0,cnt):
676
print "Processor #%d speed: %dMHz" %(i,host.getProcessorSpeed(i))
808
print "Processor #%d speed: %dMHz %s" %(i,host.getProcessorSpeed(i), host.getProcessorDescription(i))
678
810
print "RAM: %dM (free %dM)" %(host.memorySize, host.memoryAvailable)
679
811
print "OS: %s (%s)" %(host.operatingSystem, host.OSVersion)
967
1101
'runScript':['Run VBox script: runScript script.vbox', runScriptCmd, 0],
968
1102
'sleep':['Sleep for specified number of seconds: sleep 3.14159', sleepCmd, 0],
969
1103
'shell':['Execute external shell command: shell "ls /etc/rc*"', shellCmd, 0],
970
'exportVm':['Export VM in OVF format: export Win /tmp/win.ovf', exportVMCmd, 0]
1104
'exportVm':['Export VM in OVF format: export Win /tmp/win.ovf', exportVMCmd, 0],
1105
'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0],
1106
'teleport':['Teleport VM to another box (see openportal): teleport Win anotherhost:8000 <passwd>', teleportCmd, 0],
1107
'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal Win 8000 <passwd>', openportalCmd, 0],
1108
'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0]
973
1111
def runCommandArgs(ctx, args):
1120
1258
'run': lambda cmd,args: runCommandCb(ctx, cmd, args),
1121
1259
'machById': lambda id: machById(ctx,id),
1122
1260
'progressBar': lambda p: progressBar(ctx,p),
1123
'progressBar': lambda p: progressBar(ctx,p),
1124
1261
'_machlist':None