VirtualBox

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


Ignore:
Timestamp:
Jul 16, 2009 11:21:47 AM (16 years ago)
Author:
vboxsync
Message:

Python: WS Python bindings fully usable, extend shell to control remote VMs

File:
1 edited

Legend:

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

    r21584 r21640  
    258258            print session.QueryErrorObject(rc)
    259259
    260 def getMachines(ctx):
    261     return ctx['global'].getArray(ctx['vb'], 'machines')
     260def getMachines(ctx, invalidate = False):
     261    if ctx['vb'] is not None:
     262        if ctx['_machlist'] is None or invalidate:
     263            ctx['_machlist'] = ctx['global'].getArray(ctx['vb'], 'machines')
     264        return ctx['_machlist']
     265    else:
     266        return []
    262267
    263268def asState(var):
     
    389394
    390395def listCmd(ctx, args):
    391     for m in getMachines(ctx):
     396    for m in getMachines(ctx, True):
    392397        print "Machine '%s' [%s], state=%s" %(m.name,m.id,m.sessionState)
    393398    return 0
     
    420425    os = ctx['vb'].getGuestOSType(mach.OSTypeId)
    421426    print " One can use setvar <mach> <var> <value> to change variable, using name in []."
    422     print "  Name [name]: " + mach.name
    423     print "  ID [n/a]: " + mach.id
    424     print "  OS Type [n/a]: " + os.description
     427    print "  Name [name]: %s" %(mach.name)
     428    print "  ID [n/a]: %s" %(mach.id)
     429    print "  OS Type [n/a]: %s" %(os.description)
    425430    print
    426431    print "  CPUs [CPUCount]: %d" %(mach.CPUCount)
     
    435440    print "  ACPI [BIOSSettings.ACPIEnabled]: %s" %(asState(bios.ACPIEnabled))
    436441    print "  APIC [BIOSSettings.IOAPICEnabled]: %s" %(asState(bios.IOAPICEnabled))
    437     print "  PAE [PAEEnabled]: %s" %(asState(mach.PAEEnabled))
     442    print "  PAE [PAEEnabled]: %s" %(asState(int(mach.PAEEnabled)))
    438443    print "  Hardware virtualization [HWVirtExEnabled]: " + asState(mach.HWVirtExEnabled)
    439444    print "  VPID support [HWVirtExVPIDEnabled]: " + asState(mach.HWVirtExVPIDEnabled)
     
    457462        print "    Controller: %s port: %d device: %d:" % (disk.controller, disk.port, disk.device)
    458463        hd = disk.hardDisk
    459         print "    id: " + hd.id
    460         print "    location: " +  hd.location
    461         print "    name: " +  hd.name
    462         print "    format: " +  hd.format
     464        print "    id: %s" %(hd.id)
     465        print "    location: %s" %(hd.location)
     466        print "    name: %s"  %(hd.name)
     467        print "    format: %s"  %(hd.format)
    463468        print
    464469
    465470    dvd = mach.DVDDrive
    466     if dvd.getHostDrive() is not None:
     471    if dvd.getHostDrive():
    467472        hdvd = dvd.getHostDrive()
    468473        print "  DVD:"
    469         print "    Host disk:",hdvd.name
     474        print "    Host disk: %s" %(hdvd.name)
    470475        print
    471476
    472     if dvd.getImage() is not None:
     477    if dvd.getImage():
    473478        vdvd = dvd.getImage()
    474479        print "  DVD:"
    475         print "    Image at:",vdvd.location
    476         print "    Size:",vdvd.size
     480        print "    Image at: %s" %(vdvd.location)
     481        print "    Size: %s" %(vdvd.size)
    477482        print
    478483
    479484    floppy = mach.floppyDrive
    480     if floppy.getHostDrive() is not None:
     485    if floppy.getHostDrive():
    481486        hfloppy = floppy.getHostDrive()
    482487        print "  Floppy:"
    483         print "    Host disk:",hfloppy.name
     488        print "    Host disk: %s" %(hfloppy.name)
    484489        print
    485490
    486     if floppy.getImage() is not None:
     491    if floppy.getImage():
    487492        vfloppy = floppy.getImage()
    488493        print "  Floppy:"
    489         print "    Image at:",vfloppy.location
    490         print "    Size:",vfloppy.size
     494        print "    Image at: %s" %(vfloppy.location)
     495        print "    Size: %s" %(vfloppy.size)
    491496        print
    492497
     
    769774
    770775    time.sleep(float(args[1]))
     776    return 0
     777
     778
     779def connectCmd(ctx, args):
     780    if (len(args) > 4):
     781        print "usage: connect [url] [username] [passwd]"
     782        return 0
     783
     784    if ctx['vb'] is not None:
     785        print "Already connected, disconnect first..."
     786        return 0
     787
     788    if (len(args) > 1):
     789        url = args[1]
     790    else:
     791        url = None
     792
     793    if (len(args) > 2):
     794        user = args[1]
     795    else:
     796        user = ""
     797
     798    if (len(args) > 3):
     799        passwd = args[2]
     800    else:
     801        passwd = ""
     802
     803    vbox = ctx['global'].platform.connect(url, user, passwd)
     804    ctx['vb'] = vbox
     805    print "Running VirtualBox version %s" %(vbox.version)
     806    ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb'])
     807    return 0
     808
     809def disconnectCmd(ctx, args):
     810    if (len(args) != 1):
     811        print "usage: disconnect"
     812        return 0
     813
     814    if ctx['vb'] is None:
     815        print "Not connected yet."
     816        return 0
     817
     818    try:
     819        ctx['global'].platform.disconnect()
     820    except:
     821        ctx['vb'] = None
     822        raise
     823
     824    ctx['vb'] = None
     825    return 0
    771826
    772827aliases = {'s':'start',
     
    852907        traceback.print_exc()
    853908
    854 def interpret(ctx):
     909def interpret(ctx):   
     910    if ctx['remote']:
     911        commands['connect'] = ["Connect to remote VBox instance", connectCmd, 0]
     912        commands['disconnect'] = ["Disconnect from remote VBox instance", disconnectCmd, 0]
     913   
    855914    vbox = ctx['vb']
    856     print "Running VirtualBox version %s" %(vbox.version)
    857     ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb'])
    858 
    859     checkUserExtensions(ctx, commands, vbox.homeFolder)
     915
     916    if vbox is not None:
     917        print "Running VirtualBox version %s" %(vbox.version)
     918        ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb'])
     919        home = vbox.homeFolder
     920    else:
     921        ctx['perf'] = None
     922        home = os.path.join(os.path.expanduser("~"), ".VirtualBox")
     923
     924    print "h", home
     925    checkUserExtensions(ctx, commands, home)
    860926
    861927    autoCompletion(commands, ctx)
     
    923989           'remote':g_virtualBoxManager.remote,
    924990           'type':g_virtualBoxManager.type,
    925            'run':runCommandCb
     991           'run':runCommandCb,
     992           '_machlist':None
    926993           }
    927994    interpret(ctx)
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