ia64/xen-unstable

changeset 14975:0063e11206d5

[XEND] make *.get_all_records return dict of ref->record

Also clean up some handling of uuids and refs in xm

signed-of-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Fri Apr 27 15:09:39 2007 +0100 (2007-04-27)
parents 405573aedd24
children 1634486b2a5c
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendBase.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Fri Apr 27 15:06:55 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Fri Apr 27 15:09:39 2007 +0100
     1.3 @@ -553,8 +553,8 @@ class XendAPI(object):
     1.4  
     1.5              def _get_all_records(_api_cls):
     1.6                  return lambda s, session: \
     1.7 -                    xen_api_success([unpack(getattr(cls, '%s_get_record' % _api_cls)(s, session, ref))\
     1.8 -                                     for ref in unpack(getattr(cls, '%s_get_all' % _api_cls)(s, session))])
     1.9 +                    xen_api_success(dict([(ref, unpack(getattr(cls, '%s_get_record' % _api_cls)(s, session, ref)))\
    1.10 +                                          for ref in unpack(getattr(cls, '%s_get_all' % _api_cls)(s, session))]))
    1.11  
    1.12              setattr(cls, get_by_uuid, _get_by_uuid)
    1.13              setattr(cls, get_uuid,    _get_uuid)
     2.1 --- a/tools/python/xen/xend/XendBase.py	Fri Apr 27 15:06:55 2007 +0100
     2.2 +++ b/tools/python/xen/xend/XendBase.py	Fri Apr 27 15:09:39 2007 +0100
     2.3 @@ -118,8 +118,8 @@ class XendBase:
     2.4              raise "Big Error.. TODO!"
     2.5  
     2.6      def get_all_records(cls):
     2.7 -        return [inst.get_record()
     2.8 -                for inst in XendAPIStore.get_all(cls.getClass())]
     2.9 +        return dict([(inst.get_uuid(), inst.get_record())
    2.10 +                     for inst in XendAPIStore.get_all(cls.getClass())])
    2.11  
    2.12      get_all = classmethod(get_all)
    2.13      get_by_uuid = classmethod(get_by_uuid)
     3.1 --- a/tools/python/xen/xm/main.py	Fri Apr 27 15:06:55 2007 +0100
     3.2 +++ b/tools/python/xen/xm/main.py	Fri Apr 27 15:09:39 2007 +0100
     3.3 @@ -569,14 +569,14 @@ def get_single_vm(dom):
     3.4  
     3.5          try:
     3.6              domid = int(dom)
     3.7 -            uuids = [server.xenapi.VM.get_domid(vm_ref)
     3.8 -                     for vm_ref in server.xenapi.VM.get_all()
     3.9 -                     if int(server.xenapi.VM.get_domid(vm_ref)) == domid]
    3.10 +            refs = [vm_ref
    3.11 +                    for vm_ref in server.xenapi.VM.get_all()
    3.12 +                    if int(server.xenapi.VM.get_domid(vm_ref)) == domid]
    3.13          except:
    3.14              pass
    3.15              
    3.16 -        if len(uuids) > 0:
    3.17 -            return uuids[0]
    3.18 +        if len(refs) > 0:
    3.19 +            return refs[0]
    3.20  
    3.21          raise OptionError("Domain '%s' not found." % dom)
    3.22      else:
    3.23 @@ -747,15 +747,15 @@ def getDomains(domain_names, state, full
    3.24          doms_dict = []
    3.25  
    3.26          dom_recs = server.xenapi.VM.get_all_records()
    3.27 -        dom_metrics_recs = dict(map(lambda x: (x['uuid'], x), server.xenapi.VM_metrics.get_all_records()))
    3.28 +        dom_metrics_recs = server.xenapi.VM_metrics.get_all_records()
    3.29  
    3.30 -        for dom_rec in dom_recs:
    3.31 -            dom_metrics  = dom_metrics_recs[dom_rec['metrics']]
    3.32 +        for dom_ref, dom_rec in dom_recs.items():
    3.33 +            dom_metrics_rec = dom_metrics_recs[dom_rec['metrics']]
    3.34  
    3.35              states = ('running', 'blocked', 'paused', 'shutdown',
    3.36                        'crashed', 'dying')
    3.37              def state_on_off(state):
    3.38 -                if state in dom_metrics['state']:
    3.39 +                if state in dom_metrics_rec['state']:
    3.40                      return state[0]
    3.41                  else:
    3.42                      return "-"
    3.43 @@ -763,12 +763,12 @@ def getDomains(domain_names, state, full
    3.44                                   for state in states])
    3.45              
    3.46              dom_rec.update({'name':     dom_rec['name_label'],
    3.47 -                            'memory_actual': int(dom_metrics['memory_actual'])/1024,
    3.48 -                            'vcpus':    dom_metrics['VCPUs_number'],
    3.49 +                            'memory_actual': int(dom_metrics_rec['memory_actual'])/1024,
    3.50 +                            'vcpus':    dom_metrics_rec['VCPUs_number'],
    3.51                              'state':    state_str,
    3.52 -                            'cpu_time': dom_metrics['VCPUs_utilisation'],
    3.53 +                            'cpu_time': dom_metrics_rec['VCPUs_utilisation'],
    3.54                              'start_time': datetime_to_secs(
    3.55 -                                              dom_metrics['start_time'])})
    3.56 +                                              dom_metrics_rec['start_time'])})
    3.57  
    3.58              doms_sxp.append(['domain'] + map2sxp(dom_rec))
    3.59              doms_dict.append(dom_rec)
    3.60 @@ -2075,9 +2075,9 @@ def xm_network_attach(args):
    3.61  
    3.62          def get_net_from_bridge(bridge):
    3.63              # In OSS, we just assert network.name_label == bridge name
    3.64 -            networks = dict([(record['name_label'], record['uuid'])
    3.65 -                             for record in server.xenapi.network
    3.66 -                             .get_all_records()])
    3.67 +            networks = dict([(record['name_label'], ref)
    3.68 +                             for ref, record in server.xenapi.network
    3.69 +                             .get_all_records().items()])
    3.70              if bridge not in networks.keys():
    3.71                  raise "Unknown bridge name!"
    3.72              return networks[bridge]
    3.73 @@ -2251,35 +2251,29 @@ def xm_network_del(args):
    3.74      arg_check(args, "network-del", 1)
    3.75      network = args[0]
    3.76  
    3.77 -    networks = dict([(record['name_label'], record['uuid'])
    3.78 -                     for record in
    3.79 -                     server.xenapi.network.get_all_records()])
    3.80 +    networks = dict([(record['name_label'], ref)
    3.81 +                     for ref, record in
    3.82 +                     server.xenapi.network.get_all_records().items()])
    3.83  
    3.84      if network not in networks.keys():
    3.85          raise ValueError("'%s' is not a valid network name" % network)
    3.86      
    3.87      server.xenapi.network.destroy(networks[network])
    3.88  
    3.89 -def uuid_dict_trans(records):
    3.90 -    return dict([(record['uuid'], record)
    3.91 -                 for record in records])
    3.92 -
    3.93  def xm_network_show(args):
    3.94      xenapi_only()
    3.95      arg_check(args, "network-show", 0)
    3.96  
    3.97      networks = server.xenapi.network.get_all_records()
    3.98 -    pifs     = uuid_dict_trans(
    3.99 -        server.xenapi.PIF.get_all_records())
   3.100 -    vifs     = uuid_dict_trans(
   3.101 -        server.xenapi.VIF.get_all_records())
   3.102 +    pifs     = server.xenapi.PIF.get_all_records()
   3.103 +    vifs     = server.xenapi.VIF.get_all_records()
   3.104  
   3.105      print '%-20s %-40s %-10s' % \
   3.106            ('Name', 'VIFs', 'PIFs')
   3.107      
   3.108      format2 = "%(name_label)-20s %(vif)-40s %(pif)-10s"
   3.109  
   3.110 -    for network in networks:
   3.111 +    for network_ref, network in networks.items():
   3.112          for i in range(max(len(network['PIFs']),
   3.113                             len(network['VIFs']), 1)):
   3.114              if i < len(network['PIFs']):
   3.115 @@ -2292,7 +2286,7 @@ def xm_network_show(args):
   3.116              else:
   3.117                  vif_uuid = None
   3.118                  
   3.119 -            pif = pifs.get(pif_uuid, {'device':''}) 
   3.120 +            pif = pifs.get(pif_uuid, None) 
   3.121              vif = vifs.get(vif_uuid, None)
   3.122  
   3.123              if vif: