Changeset 531


Ignore:
Timestamp:
May 15, 2008, 8:31:05 PM (16 years ago)
Author:
quentin
Message:

Use more efficient python API to get VM information

Location:
trunk/packages/sipb-xen-remctl-auto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-remctl-auto/debian/changelog

    r524 r531  
     1sipb-xen-remctl-auto (1.0.14) unstable; urgency=low
     2
     3  * Use more efficient python API to get VM information, and return it
     4    in a Python dict structure.
     5
     6 -- Quentin Smith <quentin@mit.edu>  Thu, 15 May 2008 20:29:03 -0400
     7
    18sipb-xen-remctl-auto (1.0.13) unstable; urgency=low
    29
  • trunk/packages/sipb-xen-remctl-auto/files/usr/sbin/sipb-xen-listvms

    r146 r531  
    1 #!/bin/sh
     1#!/usr/bin/python
    22
    3 xm uptime | sed -n 's/^d_// p'
     3import sys
     4sys.path.insert(0, '/usr/lib/xen-3.1-1/lib/python')
     5from xen.lowlevel.xs import xs
     6
     7trans = xs()
     8
     9def live_vms():
     10    domids = set(trans.ls('', '/local/domain'))
     11    domids.remove('0')
     12
     13    vms = dict()
     14
     15    for domid in domids:
     16        name, data = get_dom(int(domid))
     17        if name.startswith('d_'):
     18            name = name[2:]
     19            vms[name] = data
     20    return vms
     21
     22def get_dom(domid):
     23    name = trans.read('', '/local/domain/%d/name' % domid)
     24    data = dict()
     25    data['domid'] = domid
     26    # presence of a graphical console
     27    data['console'] = trans.read('', '/local/domain/%d/device/vfb/0/state' % domid)
     28    # uptime
     29    data['vm'] = trans.read('', '/local/domain/%d/vm' % domid)
     30    data['start_time'] = float(trans.read('', '%s/start_time' % data['vm']))
     31   
     32    return name, data
     33
     34if __name__ == '__main__':
     35    vms = live_vms()
     36    if '--pickle' in sys.argv[1:]:
     37        import cPickle
     38        cPickle.dump(vms, sys.stdout)
     39    else:
     40        print vms
Note: See TracChangeset for help on using the changeset viewer.