VirtualBox

Ignore:
Timestamp:
Feb 7, 2013 2:28:14 PM (12 years ago)
Author:
vboxsync
Message:

clienttest.py: adapt to currently documented way of getting arrays, plus better error handling and documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/samples/python/clienttest.py

    • Property svn:eol-style changed from native to LF
    • Property svn:executable set to *
    r40400 r44588  
    3838
    3939    from vboxapi import VirtualBoxManager
     40    # This is a VirtualBox COM/XPCOM API client, no data needed.
    4041    wrapper = VirtualBoxManager(None, None)
    4142
     
    5152
    5253    # Enumerate all defined machines
    53     for mach in vbox.machines:
     54    for mach in wrapper.getArray(vbox, 'machines'):
    5455
    5556        try:
     57            # Be prepared for failures - the VM can be inaccessible
     58            vmname = '<inaccessible>'
     59            try:
     60                vmname = mach.name
     61            except Exception, e:
     62                None
     63            vmid = '';
     64            try:
     65                vmid = mach.id
     66            except Exception, e:
     67                None
    5668
    57             # Print some basic information
    58             print "Machine name: %s [%s]" %(mach.name,mach.id)
     69            # Print some basic VM information even if there were errors
     70            print "Machine name: %s [%s]" %(vmname,vmid)
     71            if vmname == '<inaccessible>' or vmid == '':
     72                continue
     73
     74            # Print some basic VM information
    5975            print "    State:           %s" %(enumToString(vboxConstants, "MachineState", mach.state))
    6076            print "    Session state:   %s" %(enumToString(vboxConstants, "SessionState", mach.sessionState))
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