~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VBoxShell/vboxshell.py

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    def onAdditionsStateChange(self):
51
51
        print  "%s: onAdditionsStateChange" %(self.mach.name)
52
52
 
53
 
    def onDVDDriveChange(self):
54
 
        print  "%s: onDVDDriveChange" %(self.mach.name)
55
 
 
56
 
    def onFloppyDriveChange(self):
57
 
        print  "%s: onFloppyDriveChange" %(self.mach.name)
58
 
 
59
53
    def onNetworkAdapterChange(self, adapter):
60
54
        print  "%s: onNetworkAdapterChange" %(self.mach.name)
61
55
 
68
62
    def onStorageControllerChange(self):
69
63
        print  "%s: onStorageControllerChange" %(self.mach.name)
70
64
 
 
65
    def onMediumChange(self, attachment):
 
66
        print  "%s: onMediumChange" %(self.mach.name)
 
67
 
71
68
    def onVRDPServerChange(self):
72
69
        print  "%s: onVRDPServerChange" %(self.mach.name)
73
70
 
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
219
 
 
220
 
 
221
def reportError(ctx,session,rc):
 
222
    if not ctx['remote']:
 
223
            print session.QueryErrorObject(rc)
 
224
 
 
225
 
222
226
def createVm(ctx,name,kind,base):
223
227
    mgr = ctx['mgr']
224
228
    vb = ctx['vb']
237
241
    session = ctx['global'].openMachineSession(id)
238
242
    try:
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)
242
246
    except:
243
247
       traceback.print_exc()
244
248
    mach.saveSettings()
274
278
         # if session not opened, close doesn't make sense
275
279
        session.close()
276
280
    else:
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)
280
282
 
281
283
def getMachines(ctx, invalidate = False):
282
284
    if ctx['vb'] is not None:
334
336
        pass
335
337
    vbox.unregisterCallback(cb)
336
338
 
 
339
 
 
340
def takeScreenshot(ctx,console,args):
 
341
    from PIL import Image
 
342
    display = console.display
 
343
    if len(args) > 0:
 
344
        f = args[0]
 
345
    else:
 
346
        f = "/tmp/screenshot.png"
 
347
    if len(args) > 1:
 
348
        w = args[1]
 
349
    else:
 
350
        w = console.display.width
 
351
    if len(args) > 2:
 
352
        h = args[2]
 
353
    else:
 
354
        h = console.display.height
 
355
    print "Saving screenshot (%d x %d) in %s..." %(w,h,f)
 
356
    data = display.takeScreenShotSlow(w,h)
 
357
    size = (w,h)
 
358
    mode = "RGBA"
 
359
    im = Image.frombuffer(mode, size, data, "raw", mode, 0, 1)
 
360
    im.save(f, "PNG")
 
361
 
 
362
 
 
363
def teleport(ctx,session,console,args):
 
364
    if args[0].find(":") == -1:
 
365
        print "Use host:port format for teleport target"
 
366
        return
 
367
    (host,port) = args[0].split(":")
 
368
    if len(args) > 1:
 
369
        passwd = args[1]
 
370
    else:
 
371
        passwd = ""
 
372
 
 
373
    port = int(port)
 
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)
 
379
    if rc == 0:
 
380
        print "Success!"
 
381
    else:
 
382
        reportError(ctx,session,rc)
 
383
 
337
384
def cmdExistingVm(ctx,mach,cmd,args):
338
385
    mgr=ctx['mgr']
339
386
    vb=ctx['vb']
346
393
        if g_verbose:
347
394
            traceback.print_exc()
348
395
        return
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)
351
398
        return
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)
366
415
         }
367
416
    try:
368
417
        ops[cmd]()
422
471
 
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:
 
475
            tele = "[T] "
 
476
        else:
 
477
            tele = "    "
 
478
        print "%sMachine '%s' [%s], state=%s" %(tele,m.name,m.id,m.sessionState)
426
479
    return 0
427
480
 
428
481
def getControllerType(type):
443
496
    else:
444
497
        return "Unknown"
445
498
 
 
499
def getFirmwareType(type):
 
500
    if type == 0:
 
501
        return "invalid"
 
502
    elif type == 1:
 
503
        return "bios"
 
504
    elif type == 2:
 
505
        return "efi"
 
506
    elif type == 3:
 
507
        return "efi64"
 
508
    elif type == 4:
 
509
        return "efidual"
 
510
    else:
 
511
        return "Unknown"
 
512
 
 
513
 
446
514
def infoCmd(ctx,args):
447
515
    if (len(args) < 2):
448
516
        print "usage: info [vmname|uuid]"
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)
458
527
    print
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)
466
535
    print
 
536
    if mach.teleporterEnabled:
 
537
        print "  Teleport target on port %d (%s)" %(mach.teleporterPort, mach.teleporterPassword)
 
538
    print
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)
 
548
 
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)
 
551
 
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))
477
554
 
482
559
    for controller in controllers:
483
560
        print "    %s %s bus: %d" % (controller.name, getControllerType(controller.controllerType), controller.bus)
484
561
 
485
 
    disks = ctx['global'].getArray(mach, 'hardDiskAttachments')
486
 
    if disks:
487
 
        print
488
 
        print "  Hard disk(s):"
489
 
    for disk in disks:
490
 
        print "    Controller: %s port: %d device: %d:" % (disk.controller, disk.port, disk.device)
491
 
        hd = disk.hardDisk
492
 
        print "    id: %s" %(hd.id)
493
 
        print "    location: %s" %(hd.location)
494
 
        print "    name: %s"  %(hd.name)
495
 
        print "    format: %s"  %(hd.format)
496
 
        print
497
 
 
498
 
    dvd = mach.DVDDrive
499
 
    if dvd.getHostDrive():
500
 
        hdvd = dvd.getHostDrive()
501
 
        print "  DVD:"
502
 
        print "    Host disk: %s" %(hdvd.name)
503
 
        print
504
 
 
505
 
    if dvd.getImage():
506
 
        vdvd = dvd.getImage()
507
 
        print "  DVD:"
508
 
        print "    Image at: %s" %(vdvd.location)
509
 
        print "    Size: %s" %(vdvd.size)
510
 
        print "    Id: %s" %(vdvd.id)
511
 
        print
512
 
 
513
 
    floppy = mach.floppyDrive
514
 
    if floppy.getHostDrive():
515
 
        hfloppy = floppy.getHostDrive()
516
 
        print "  Floppy:"
517
 
        print "    Host disk: %s" %(hfloppy.name)
518
 
        print
519
 
 
520
 
    if floppy.getImage():
521
 
        vfloppy = floppy.getImage()
522
 
        print "  Floppy:"
523
 
        print "    Image at: %s" %(vfloppy.location)
524
 
        print "    Size: %s" %(vfloppy.size)
525
 
        print
 
562
    attaches = ctx['global'].getArray(mach, 'mediumAttachments')
 
563
    if attaches:
 
564
        print
 
565
        print "  Mediums:"
 
566
    for a in attaches:
 
567
        print "   Controller: %s port: %d device: %d type: %s:" % (a.controller, a.port, a.device, a.type)
 
568
        m = a.medium
 
569
        if a.type == ctx['global'].constants.DeviceType_HardDisk:
 
570
            print "   HDD:"
 
571
            print "    Id: %s" %(m.id)
 
572
            print "    Location: %s" %(m.location)
 
573
            print "    Name: %s"  %(m.name)
 
574
            print "    Format: %s"  %(m.format)
 
575
 
 
576
        if a.type == ctx['global'].constants.DeviceType_DVD:
 
577
            print "   DVD:"
 
578
            if m:
 
579
                print "    Id: %s" %(m.id)
 
580
                print "    Name: %s" %(m.name)
 
581
                if m.hostDrive:
 
582
                    print "    Host DVD %s" %(m.location)
 
583
                    if a.passthrough:
 
584
                         print "    [passthrough mode]"
 
585
                else:
 
586
                    print "    Virtual image at %s" %(m.location)
 
587
                    print "    Size: %s" %(m.size)
 
588
 
 
589
        if a.type == ctx['global'].constants.DeviceType_Floppy:
 
590
            print "   Floppy:"
 
591
            if m:
 
592
                print "    Id: %s" %(m.id)
 
593
                print "    Name: %s" %(m.name)
 
594
                if m.hostDrive:
 
595
                    print "    Host floppy %s" %(m.location)
 
596
                else:
 
597
                    print "    Virtual image at %s" %(m.location)
 
598
                    print "    Size: %s" %(m.size)
526
599
 
527
600
    return 0
528
601
 
614
687
    cmdExistingVm(ctx, mach, 'guest', ' '.join(args[2:]))
615
688
    return 0
616
689
 
 
690
def screenshotCmd(ctx, args):
 
691
    if (len(args) < 3):
 
692
        print "usage: screenshot name file <width> <height>"
 
693
        return 0
 
694
    mach = argsToMach(ctx,args)
 
695
    if mach == None:
 
696
        return 0
 
697
    cmdExistingVm(ctx, mach, 'screenshot', args[2:])
 
698
    return 0
 
699
 
 
700
def teleportCmd(ctx, args):
 
701
    if (len(args) < 3):
 
702
        print "usage: teleport name host:port <password>"
 
703
        return 0
 
704
    mach = argsToMach(ctx,args)
 
705
    if mach == None:
 
706
        return 0
 
707
    cmdExistingVm(ctx, mach, 'teleport', args[2:])
 
708
    return 0
 
709
 
 
710
def openportalCmd(ctx, args):
 
711
    if (len(args) < 3):
 
712
        print "usage: openportal name port <password>"
 
713
        return 0
 
714
    mach = argsToMach(ctx,args)
 
715
    if mach == None:
 
716
        return 0
 
717
    port = int(args[2])
 
718
    if (len(args) > 3):
 
719
        passwd = args[3]
 
720
    else:
 
721
        passwd = ""
 
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
 
728
        mach1.saveSettings()
 
729
        session.close()
 
730
    startVm(ctx, mach, "gui")
 
731
    return 0
 
732
 
 
733
def closeportalCmd(ctx, args):
 
734
    if (len(args) < 2):
 
735
        print "usage: closeportal name"
 
736
        return 0
 
737
    mach = argsToMach(ctx,args)
 
738
    if mach == None:
 
739
        return 0
 
740
    if mach.teleporterEnabled:
 
741
        session = ctx['global'].openMachineSession(mach.id)
 
742
        mach1 = session.machine
 
743
        mach1.teleporterEnabled = False
 
744
        mach1.saveSettings()
 
745
        session.close()
 
746
    return 0
 
747
 
 
748
 
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))
677
809
 
678
810
   print "RAM: %dM (free %dM)" %(host.memorySize, host.memoryAvailable)
679
811
   print "OS: %s (%s)" %(host.operatingSystem, host.OSVersion)
731
863
          type == ctx['global'].constants.NetworkAdapterType_I82545EM or
732
864
          type == ctx['global'].constants.NetworkAdapterType_I82543GC):
733
865
        return "e1000"
 
866
    elif (type == ctx['global'].constants.NetworkAdapterType_Virtio):
 
867
        return "virtio"
734
868
    elif (type == ctx['global'].constants.NetworkAdapterType_Null):
735
869
        return None
736
870
    else:
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]
971
1109
            }
972
1110
 
973
1111
def runCommandArgs(ctx, args):
1077
1215
            print e
1078
1216
            if g_verbose:
1079
1217
                traceback.print_exc()
1080
 
 
 
1218
        ctx['global'].waitForEvents(0)
1081
1219
    try:
1082
1220
        # There is no need to disable metric collection. This is just an example.
1083
1221
        if ct['perf']:
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
1125
1262
           }
1126
1263
    interpret(ctx)