VirtualBox

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


Ignore:
Timestamp:
Apr 29, 2010 12:21:39 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60829
Message:

VBoxShell: snapshots

File:
1 edited

Legend:

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

    r28817 r28889  
    221221  delims = readline.get_completer_delims()
    222222  readline.set_completer_delims(re.sub("[\\.]", "", delims)) # remove some of the delimiters
    223   readline.parse_and_bind("set editing-mode emacs") 
     223  readline.parse_and_bind("set editing-mode emacs")
    224224  # OSX need it
    225225  if platform.system() == 'Darwin':
     
    265265def colVm(ctx,vm):
    266266    return colored(vm, 'blue')
     267
     268def colPath(ctx,vm):
     269    return colored(vm, 'green')
     270
    267271
    268272def createVm(ctx,name,kind,base):
     
    520524
    521525def cmdExistingVm(ctx,mach,cmd,args):
    522     mgr=ctx['mgr']
    523     vb=ctx['vb']
    524     session = mgr.getSessionObject(vb)
    525     uuid = mach.id
    526526    try:
    527         progress = vb.openExistingSession(session, uuid)
     527        session = ctx['global'].openMachineSession(mach.id)
    528528    except Exception,e:
    529529        printErr(ctx, "Session to '%s' not open: %s" %(mach.name,str(e)))
     
    531531            traceback.print_exc()
    532532        return
    533     if str(session.state) != str(ctx['ifaces'].SessionState_Open):
     533    if session.state != ctx['ifaces'].SessionState_Open:
    534534        print "Session to '%s' in wrong state: %s" %(mach.name, session.state)
     535        session.close()
    535536        return
    536537    # this could be an example how to handle local only (i.e. unavailable
     
    538539    if ctx['remote'] and cmd == 'some_local_only_command':
    539540        print 'Trying to use local only functionality, ignored'
     541        session.close()
    540542        return
    541543    console=session.console
     
    571573    mach = session.machine
    572574    try:
    573          cmd(ctx, mach, args)
     575        cmd(ctx, mach, args)
    574576    except Exception, e:
     577        save = False
    575578        printErr(ctx,e)
    576579        if g_verbose:
     
    578581    if save:
    579582         mach.saveSettings()
    580     session.close()
     583    ctx['global'].closeMachineSession(session)
     584
     585
     586def cmdAnyVm(ctx,mach,cmd, args=[],save=False):
     587    session = ctx['global'].openMachineSession(mach.id)
     588    mach = session.machine
     589    try:
     590         cmd(ctx, mach, session.console, args)
     591    except Exception, e:
     592        save = False;
     593        printErr(ctx,e)
     594        if g_verbose:
     595            traceback.print_exc()
     596    if save:
     597         mach.saveSettings()
     598    ctx['global'].closeMachineSession(session)
    581599
    582600def machById(ctx,id):
     
    11141132def hostCmd(ctx, args):
    11151133   vb = ctx['vb']
    1116    print "VirtualBox version %s" %(vb.version)
     1134   print "VirtualBox version %s" %(colored(vb.version, 'blue'))
     1135   props = vb.systemProperties
     1136   print "Machines: %s" %(colPath(ctx,props.defaultMachineFolder))
     1137   print "HDDs:     %s" %(colPath(ctx,props.defaultHardDiskFolder))
     1138
    11171139   #print "Global shared folders:"
    11181140   #for ud in ctx['global'].getArray(vb, 'sharedFolders'):
     
    20972119    if not found:
    20982120        cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: console.removeSharedFolder(name)])
     2121    return 0
     2122
     2123
     2124def snapshotCmd(ctx,args):
     2125    if (len(args) < 2 or args[1] == 'help'):
     2126        print "Take snapshot:    snapshot vm take name <description>"
     2127        print "Restore snapshot: snapshot vm restore name"
     2128        print "Merge snapshot:   snapshot vm merge name"
     2129        return 0
     2130
     2131    mach = argsToMach(ctx,args)
     2132    if mach is None:
     2133        return 0
     2134    cmd = args[2]
     2135    if cmd == 'take':
     2136        if (len(args) < 4):
     2137            print "usage: snapshot vm take name <description>"
     2138            return 0
     2139        name = args[3]
     2140        if (len(args) > 4):
     2141            desc = args[4]
     2142        else:
     2143            desc = ""
     2144        cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.takeSnapshot(name,desc)))
     2145
     2146    if cmd == 'restore':
     2147        if (len(args) < 4):
     2148            print "usage: snapshot vm restore name"
     2149            return 0
     2150        name = args[3]
     2151        snap = mach.findSnapshot(name)
     2152        cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.restoreSnapshot(snap)))
     2153        return 0
     2154
     2155    if cmd == 'restorecurrent':
     2156        if (len(args) < 4):
     2157            print "usage: snapshot vm restorecurrent"
     2158            return 0
     2159        snap = mach.currentSnapshot()
     2160        cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.restoreSnapshot(snap)))
     2161        return 0
     2162
     2163    if cmd == 'delete':
     2164        if (len(args) < 4):
     2165            print "usage: snapshot vm delete name"
     2166            return 0
     2167        name = args[3]
     2168        snap = mach.findSnapshot(name)
     2169        cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.deleteSnapshot(snap.id)))
     2170        return 0
     2171
     2172    print "Command '%s' is unknown" %(cmd)
     2173
    20992174    return 0
    21002175
     
    21722247            'gui': ['Start GUI frontend', guiCmd, 0],
    21732248            'colors':['Toggle colors', colorsCmd, 0],
     2249            'snapshot':['VM snapshot manipulation, snapshot help for more info', snapshotCmd, 0],
    21742250            }
    21752251
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