direct-io.hg

changeset 5017:25cc682e9734

bitkeeper revision 1.1471 (428cf949ZdshF_D_GTMuih23dXPidw)

XendDomain.py:
Add XendDomainDict for easy by name lookup.
Don't call self.refresh() from XendDomain.list().
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu May 19 20:38:33 2005 +0000 (2005-05-19)
parents 7c5f7c1ed1a3
children c03769252a5e eaba619f2e83
files tools/python/xen/xend/XendDomain.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Thu May 19 19:47:28 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu May 19 20:38:33 2005 +0000
     1.3 @@ -35,8 +35,15 @@ class XendDomain:
     1.4      """Path to domain database."""
     1.5      dbpath = "domain"
     1.6  
     1.7 -    """Table of domain info indexed by domain id."""
     1.8 -    domains = {}
     1.9 +    class XendDomainDict(dict):
    1.10 +        def get_by_name(self, name):
    1.11 +            try:
    1.12 +                return filter(lambda d: d.name == name, self.values())[0]
    1.13 +            except IndexError, err:
    1.14 +                return None
    1.15 +
    1.16 +    """Dict of domain info indexed by domain id."""
    1.17 +    domains = XendDomainDict()
    1.18      
    1.19      def __init__(self):
    1.20          # Hack alert. Python does not support mutual imports, but XendDomainInfo
    1.21 @@ -53,16 +60,13 @@ class XendDomain:
    1.22          eserver.subscribe('xend.virq', self.onVirq)
    1.23          self.initial_refresh()
    1.24  
    1.25 -    def domain_lookup_by_name(self, name):
    1.26 -        try:
    1.27 -            return filter(lambda d: d.name == name,
    1.28 -                          self.domains.values())[0]
    1.29 -        except IndexError, err:
    1.30 -            return None
    1.31 +    def list(self):
    1.32 +        """Get list of domain objects.
    1.33  
    1.34 -    def domain_lookup_by_id(self, id):
    1.35 -        return self.domains.get(id)
    1.36 -
    1.37 +        @return: domain objects
    1.38 +        """
    1.39 +        return self.domains.values()
    1.40 +    
    1.41      def onVirq(self, event, val):
    1.42          """Event handler for virq.
    1.43          """
    1.44 @@ -153,8 +157,6 @@ class XendDomain:
    1.45                  if i in self.domain_db:
    1.46                      del self.domain_db[i]
    1.47                  self.db.delete(i)
    1.48 -        # But also need to make sure are indexed under correct name.
    1.49 -        # What about entries under info.name ?
    1.50          if info.id in self.domains:
    1.51              notify = False
    1.52          self.domains[info.id] = info
    1.53 @@ -285,14 +287,6 @@ class XendDomain:
    1.54          self.refresh()
    1.55          return self.domains.keys()
    1.56  
    1.57 -    def list(self):
    1.58 -        """Get list of domain objects.
    1.59 -
    1.60 -        @return: domain objects
    1.61 -        """
    1.62 -        self.refresh()
    1.63 -        return self.domains.values()
    1.64 -    
    1.65      def domain_create(self, config):
    1.66          """Create a domain from a configuration.
    1.67  
    1.68 @@ -362,8 +356,7 @@ class XendDomain:
    1.69  
    1.70      def domain_lookup(self, name):
    1.71          name = str(name)
    1.72 -        dominfo = (self.domain_lookup_by_name(name) or
    1.73 -                   self.domain_lookup_by_id(name))
    1.74 +        dominfo = self.domains.get_by_name(name) or self.domains.get(name)
    1.75          if dominfo:
    1.76              return dominfo
    1.77          try: