VirtualBox

Ignore:
Timestamp:
Feb 18, 2009 2:17:15 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43024
Message:

Python: imporved error reporting in XPCOM, shell updates, docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/sample/shellcommon.py

    r16366 r16903  
    145145   return s.split()
    146146
    147 def startVm(mgr,vb,mach,type,perf):
     147def createVm(ctx,name,kind,base):
     148    mgr = ctx['mgr']
     149    vb = ctx['vb']
     150    session = mgr.getSessionObject(vb)
     151    mach = vb.createMachine(name, kind, base,
     152                            "00000000-0000-0000-0000-000000000000")
     153    mach.saveSettings()
     154    print "created machine with UUID",mach.id
     155    vb.registerMachine(mach)
     156
     157def removeVm(ctx,mach):
     158    mgr = ctx['mgr']
     159    vb = ctx['vb']
     160    print "removing machine ",mach.name,"with UUID",mach.id
     161    mach = vb.unregisterMachine(mach.id)
     162    if mach:
     163         mach.deleteSettings()
     164
     165def startVm(ctx,mach,type):
     166    mgr = ctx['mgr']
     167    vb = ctx['vb']
     168    perf = ctx['perf']
    148169    session = mgr.getSessionObject(vb)
    149170    uuid = mach.id
     
    152173    completed = progress.completed
    153174    rc = progress.resultCode
    154     print "Completed:", completed, "rc:",rc
     175    print "Completed:", completed, "rc:",hex(rc&0xffffffff)
    155176    if int(rc) == 0:
    156177        # we ignore exceptions to allow starting VM even if
     
    163184                traceback.print_exc()
    164185            pass
    165     session.close()
     186         # if session not opened, close doesn't make sense
     187        session.close()
     188    else:
     189        # Not yet implemented error string query API for remote API
     190        if not ctx['remote']:
     191            print session.QueryErrorObject(rc)
    166192
    167193def getMachines(ctx):
     
    282308    else:
    283309        type = "gui"
    284     startVm(ctx['mgr'], ctx['vb'], mach, type, ctx['perf'])
     310    startVm(ctx, mach, type)
     311    return 0
     312
     313def createCmd(ctx, args):
     314    if (len(args) < 3 or len(args) > 4):
     315        print "usage: create name ostype <basefolder>"
     316        return 0
     317    name = args[1]
     318    oskind = args[2]
     319    if len(args) == 4:
     320        base = args[3]
     321    else:
     322        base = ''
     323    try:
     324         ctx['vb'].getGuestOSType(oskind)
     325    except Exception, e:
     326        print 'Unknown OS type:',oskind
     327        return 0
     328    createVm(ctx, name, oskind, base)
     329    return 0
     330
     331def removeCmd(ctx, args):
     332    mach = argsToMach(ctx,args)
     333    if mach == None:
     334        return 0
     335    removeVm(ctx, mach)
    285336    return 0
    286337
     
    382433commands = {'help':['Prints help information', helpCmd],
    383434            'start':['Start virtual machine by name or uuid', startCmd],
     435            'create':['Create virtual machine', createCmd],
     436            'remove':['Remove virtual machine', removeCmd],
    384437            'pause':['Pause virtual machine', pauseCmd],
    385438            'resume':['Resume virtual machine', resumeCmd],
Note: See TracChangeset for help on using the changeset viewer.

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