VirtualBox

Ignore:
Timestamp:
Feb 16, 2010 12:42:11 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57753
Message:

Python shell: commands to set/get extra data

File:
1 edited

Legend:

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

    r26548 r26571  
    767767    mach.saveSettings()
    768768    session.close()
     769    return 0
     770
     771
     772def setExtraDataCmd(ctx, args):
     773    if (len(args) < 3):
     774        print "usage: setextra [vmname|uuid|global] key <value>"
     775        return 0
     776    key = args[2]
     777    if len(args) == 4:
     778        value = args[3]
     779    else:
     780        value = None
     781    if args[1] == 'global':
     782        ctx['vb'].setExtraData(key, value)
     783        return 0
     784
     785    mach = argsToMach(ctx,args)
     786    if mach == None:
     787        return 0
     788    session = ctx['global'].openMachineSession(mach.id)
     789    mach = session.machine
     790    mach.setExtraData(key, value)
     791    mach.saveSettings()
     792    session.close()
     793    return 0
     794
     795def printExtraKey(obj, key, value):
     796    print "%s: '%s' = '%s'" %(obj, key, value)
     797
     798def getExtraDataCmd(ctx, args):
     799    if (len(args) < 2):
     800        print "usage: getextra [vmname|uuid|global] <key>"
     801        return 0
     802    if len(args) == 3:
     803        key = args[2]
     804    else:
     805        key = None
     806
     807    if args[1] == 'global':
     808        obj = ctx['vb']
     809    else:
     810        obj = argsToMach(ctx,args)
     811        if obj == None:
     812            return 0
     813
     814    if key == None:
     815        keys = obj.getExtraDataKeys()
     816    else:
     817        keys = [ key ]
     818    for k in keys:
     819        printExtraKey(args[1], k, ctx['vb'].getExtraData(k))
     820
    769821    return 0
    770822
     
    11071159            'teleport':['Teleport VM to another box (see openportal): teleport Win anotherhost:8000 <passwd>', teleportCmd, 0],
    11081160            'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal Win 8000 <passwd>', openportalCmd, 0],
    1109             'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0]
     1161            'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0],
     1162            'getextra':['Get extra data, empty key lists all: getextra <vm|global> <key>', getExtraDataCmd, 0],
     1163            'setextra':['Set extra data, empty value removes key: setextra <vm|global> <key> <value>', setExtraDataCmd, 0]           
    11101164            }
    11111165
     
    12591313           'run': lambda cmd,args: runCommandCb(ctx, cmd, args),
    12601314           'machById': lambda id: machById(ctx,id),
     1315           'argsToMach': lambda args: argsToMach(ctx,args),
    12611316           'progressBar': lambda p: progressBar(ctx,p),
    12621317           '_machlist':None
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