direct-io.hg

changeset 5014:c50fd5930102

bitkeeper revision 1.1468 (428ce527Lb7wgq3pLjYHY6S5zNVk7g)

XendDomainInfo.py:
XendDomain.domain_exists() now returns a truth value, use domain_lookup
instead.
XendDomain.py:
Remove domain_by_name lookup array -- it's tedious to maintain for
hardly any benefits. Also make domain_exists return a truth value.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu May 19 19:12:39 2005 +0000 (2005-05-19)
parents 8e1eb9f69187
children d1e3efb12a27
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Thu May 19 17:02:35 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu May 19 19:12:39 2005 +0000
     1.3 @@ -37,7 +37,6 @@ class XendDomain:
     1.4  
     1.5      """Table of domain info indexed by domain id."""
     1.6      domain_by_id = {}
     1.7 -    domain_by_name = {}
     1.8      
     1.9      def __init__(self):
    1.10          # Hack alert. Python does not support mutual imports, but XendDomainInfo
    1.11 @@ -54,6 +53,16 @@ class XendDomain:
    1.12          eserver.subscribe('xend.virq', self.onVirq)
    1.13          self.initial_refresh()
    1.14  
    1.15 +    def domain_lookup_by_name(self, name):
    1.16 +        try:
    1.17 +            return filter(lambda d: d.name == name,
    1.18 +                          self.domain_by_id.values())[0]
    1.19 +        except IndexError, err:
    1.20 +            return None
    1.21 +
    1.22 +    def domain_lookup_by_id(self, id):
    1.23 +        return self.domain_by_id.get(id)
    1.24 +
    1.25      def onVirq(self, event, val):
    1.26          """Event handler for virq.
    1.27          """
    1.28 @@ -129,7 +138,6 @@ class XendDomain:
    1.29          """
    1.30          dominfo = XendDomainInfo.vm_recreate(savedinfo, info)
    1.31          self.domain_by_id[dominfo.id] = dominfo
    1.32 -        self.domain_by_name[dominfo.name] = dominfo
    1.33          return dominfo
    1.34  
    1.35      def _add_domain(self, info, notify=True):
    1.36 @@ -145,18 +153,12 @@ class XendDomain:
    1.37                  if i in self.domain_db:
    1.38                      del self.domain_db[i]
    1.39                  self.db.delete(i)
    1.40 -        # Remove entries under the wrong name.
    1.41 -        for n, d in self.domain_by_name.items():
    1.42 -            if n != d.name:
    1.43 -                del self.domain_by_name[n]
    1.44          # But also need to make sure are indexed under correct name.
    1.45          # What about entries under info.name ?
    1.46          if info.id in self.domain_by_id:
    1.47              notify = False
    1.48          self.domain_by_id[info.id] = info
    1.49          self.domain_db[info.id] = info.sxpr()
    1.50 -        if info.name:
    1.51 -            self.domain_by_name[info.name] = info
    1.52          self.sync_domain(info.id)
    1.53          if notify:
    1.54              eserver.inject('xend.domain.create', [info.name, info.id])
    1.55 @@ -167,9 +169,6 @@ class XendDomain:
    1.56          @param id:     domain id
    1.57          @param notify: send a domain died event if true
    1.58          """
    1.59 -        for (k, info) in self.domain_by_name.items():
    1.60 -            if info.id == id:
    1.61 -                del self.domain_by_name[k]
    1.62          info = self.domain_by_id.get(id)
    1.63          if info:
    1.64              del self.domain_by_id[id]
    1.65 @@ -274,7 +273,9 @@ class XendDomain:
    1.66          @return: domain names
    1.67          """
    1.68          self.refresh()
    1.69 -        return self.domain_by_name.keys()
    1.70 +        doms = self.domain_by_id.values()
    1.71 +        doms.sort(lambda x, y: cmp(x.name, y.name))
    1.72 +        return map(lambda x: x.name, doms)
    1.73  
    1.74      def domain_ls_ids(self):
    1.75          """Get list of domain ids.
    1.76 @@ -361,23 +362,22 @@ class XendDomain:
    1.77  
    1.78      def domain_lookup(self, name):
    1.79          name = str(name)
    1.80 -        dominfo = self.domain_by_name.get(name) or self.domain_by_id.get(name)
    1.81 +        dominfo = (self.domain_lookup_by_name(name) or
    1.82 +                   self.domain_lookup_by_id(name))
    1.83          if dominfo:
    1.84              return dominfo
    1.85          try:
    1.86 -            log.info("Creating entry for unknown domain: id=%s", name)
    1.87              d = self.xen_domain(name)
    1.88              if d:
    1.89 +                log.info("Creating entry for unknown domain: id=%s", name)
    1.90                  dominfo = XendDomainInfo.vm_recreate(None, d)
    1.91                  self._add_domain(dominfo)
    1.92                  return dominfo
    1.93          except Exception, ex:
    1.94              log.exception("Error creating domain info: id=%s", name)
    1.95 -        raise XendError('invalid domain: ' + name)
    1.96  
    1.97      def domain_exists(self, name):
    1.98 -        name = str(name)
    1.99 -        return self.domain_by_name.get(name) or self.domain_by_id.get(name)
   1.100 +        return self.domain_lookup(name) != None
   1.101  
   1.102      def domain_unpause(self, id):
   1.103          """Unpause domain execution.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu May 19 17:02:35 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu May 19 19:12:39 2005 +0000
     2.3 @@ -79,7 +79,7 @@ STATE_VM_TERMINATED = "terminated"
     2.4  def domain_exists(name):
     2.5      # See comment in XendDomain constructor.
     2.6      xd = get_component('xen.xend.XendDomain')
     2.7 -    return xd.domain_exists(name)
     2.8 +    return xd.domain_lookup(name)
     2.9  
    2.10  def shutdown_reason(code):
    2.11      """Get a shutdown reason from a code.