VirtualBox

Changeset 24581 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 11, 2009 2:35:18 PM (15 years ago)
Author:
vboxsync
Message:

Python shell: teleportation support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r24450 r24581  
    219219
    220220
     221def reportError(ctx,session,rc):
     222    if not ctx['remote']:
     223            print session.QueryErrorObject(rc)
     224
     225
    221226def createVm(ctx,name,kind,base):
    222227    mgr = ctx['mgr']
     
    274279        session.close()
    275280    else:
    276         # Not yet implemented error string query API for remote API
    277         if not ctx['remote']:
    278             print session.QueryErrorObject(rc)
     281       reportError(ctx,session,rc)
    279282
    280283def getMachines(ctx, invalidate = False):
     
    353356    data = display.takeScreenShotSlow(w,h)
    354357    size = (w,h)
    355     mode = "RGBA"   
     358    mode = "RGBA"
    356359    im = Image.frombuffer(mode, size, data, "raw", mode, 0, 1)
    357360    im.save(f, "PNG")
    358361
     362
     363def 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)
    359383
    360384def cmdExistingVm(ctx,mach,cmd,args):
     
    387411         'monitorGuest':    lambda: monitorGuest(ctx, mach, console, args),
    388412         'save':            lambda: progressBar(ctx,console.saveState()),
    389          'screenshot':      lambda: takeScreenshot(ctx,console,args)
     413         'screenshot':      lambda: takeScreenshot(ctx,console,args),
     414         'teleport':        lambda: teleport(ctx,session,console,args)
    390415         }
    391416    try:
     
    650675    cmdExistingVm(ctx, mach, 'screenshot', args[2:])
    651676    return 0
     677
     678def teleportCmd(ctx, args):
     679    if (len(args) < 3):
     680        print "usage: teleport name host:port <password>"
     681        return 0
     682    mach = argsToMach(ctx,args)
     683    if mach == None:
     684        return 0
     685    cmdExistingVm(ctx, mach, 'teleport', args[2:])
     686    return 0
     687
     688def makeportalCmd(ctx, args):
     689    if (len(args) < 3):
     690        print "usage: makeportal name port <password>"
     691        return 0
     692    mach = argsToMach(ctx,args)
     693    if mach == None:
     694        return 0
     695    port = int(args[2])
     696    if (len(args) > 3):
     697        passwd = args[3]
     698    else:
     699        passwd = ""
     700    if not mach.teleporterEnabled or mach.teleporterPort != port:
     701        session = ctx['global'].openMachineSession(mach.id)
     702        mach1 = session.machine
     703        mach1.teleporterEnabled = True
     704        mach1.teleporterPort = port
     705        mach1.saveSettings()
     706        session.close()
     707    startVm(ctx, mach, "gui")
     708    return 0
     709
     710def closeportalCmd(ctx, args):
     711    if (len(args) < 2):
     712        print "usage: closeportal name"
     713        return 0
     714    mach = argsToMach(ctx,args)
     715    if mach == None:
     716        return 0
     717    if mach.teleporterEnabled:
     718        session = ctx['global'].openMachineSession(mach.id)
     719        mach1 = session.machine
     720        mach1.teleporterEnabled = False
     721        mach1.saveSettings()
     722        session.close()
     723    return 0
     724
    652725
    653726def setvarCmd(ctx, args):
     
    10071080            'shell':['Execute external shell command: shell "ls /etc/rc*"', shellCmd, 0],
    10081081            'exportVm':['Export VM in OVF format: export Win /tmp/win.ovf', exportVMCmd, 0],
    1009             'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0]
     1082            'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0],
     1083            'teleport':['Teleport VM to another box (see makeportal): teleport Win anotherhost:8000 <passwd>', teleportCmd, 0],
     1084            'makeportal':['Make portal for teleportation of VM from another box (see teleport): makeportal Win 8000 <passwd>', makeportalCmd, 0],
     1085            'closeportal':['Close portal for teleportation of VM from another box (see teleport): closeportal Win', closeportalCmd, 0]
    10101086            }
    10111087
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette