ia64/xen-unstable

changeset 14871:338820b7ea45

Add *.get_all_records to XenAPI, make use of this for xm list

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Mon Apr 16 22:58:12 2007 +0100 (2007-04-16)
parents 4538426ae5fd
children 046fd974b4dc
files tools/python/xen/xend/XendAPI.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Mon Apr 16 17:02:52 2007 -0400
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Mon Apr 16 22:58:12 2007 +0100
     1.3 @@ -575,15 +575,25 @@ class XendAPI(object):
     1.4              
     1.5              get_by_uuid = '%s_get_by_uuid' % api_cls
     1.6              get_uuid = '%s_get_uuid' % api_cls
     1.7 +            get_all_records = '%s_get_all_records' % api_cls    
     1.8 +
     1.9              def _get_by_uuid(_1, _2, ref):
    1.10                  return xen_api_success(ref)
    1.11  
    1.12              def _get_uuid(_1, _2, ref):
    1.13                  return xen_api_success(ref)
    1.14  
    1.15 +            def unpack(v):
    1.16 +                return v['Value']
    1.17 +
    1.18 +            def _get_all_records(_api_cls):
    1.19 +                return lambda s, session: \
    1.20 +                    xen_api_success([unpack(getattr(cls, '%s_get_record' % _api_cls)(s, session, ref))\
    1.21 +                                     for ref in unpack(getattr(cls, '%s_get_all' % _api_cls)(s, session))])
    1.22 +
    1.23              setattr(cls, get_by_uuid, _get_by_uuid)
    1.24              setattr(cls, get_uuid,    _get_uuid)
    1.25 -
    1.26 +            setattr(cls, get_all_records, _get_all_records(api_cls))
    1.27  
    1.28          # Autoplugging classes
    1.29          # --------------------
    1.30 @@ -721,7 +731,7 @@ class XendAPI(object):
    1.31      Base_attr_ro = ['uuid']
    1.32      Base_attr_rw = []
    1.33      Base_methods = [('get_record', 'Struct')]
    1.34 -    Base_funcs   = [('get_all', 'Set'), ('get_by_uuid', None)]
    1.35 +    Base_funcs   = [('get_all', 'Set'), ('get_by_uuid', None), ('get_all_records', 'Set')]
    1.36  
    1.37      # Xen API: Class Session
    1.38      # ----------------------------------------------------------------
     2.1 --- a/tools/python/xen/xm/main.py	Mon Apr 16 17:02:52 2007 -0400
     2.2 +++ b/tools/python/xen/xm/main.py	Mon Apr 16 22:58:12 2007 +0100
     2.3 @@ -741,11 +741,12 @@ def getDomains(domain_names, state, full
     2.4      if serverType == SERVER_XEN_API:
     2.5          doms_sxp = []
     2.6          doms_dict = []
     2.7 -        dom_refs = server.xenapi.VM.get_all()
     2.8 -        for dom_ref in dom_refs:
     2.9 -            dom_rec = server.xenapi.VM.get_record(dom_ref)
    2.10 -            dom_metrics_ref = server.xenapi.VM.get_metrics(dom_ref)
    2.11 -            dom_metrics = server.xenapi.VM_metrics.get_record(dom_metrics_ref)
    2.12 +
    2.13 +        dom_recs = server.xenapi.VM.get_all_records()
    2.14 +        dom_metrics_recs = dict(map(lambda x: (x['uuid'], x), server.xenapi.VM_metrics.get_all_records()))
    2.15 +
    2.16 +        for dom_rec in dom_recs:
    2.17 +            dom_metrics  = dom_metrics_recs[dom_rec['metrics']]
    2.18  
    2.19              states = ('running', 'blocked', 'paused', 'shutdown',
    2.20                        'crashed', 'dying')