ia64/xen-unstable

changeset 6844:eb6fbb3d0a7b

Add gather function and robustify class methods' failure handling.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 14 18:24:25 2005 +0000 (2005-09-14)
parents 9c9a3bb878c2
children d5497a215660
files tools/python/xen/xend/xenstore/xstransact.py
line diff
     1.1 --- a/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 14 17:06:37 2005 +0000
     1.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 14 18:24:25 2005 +0000
     1.3 @@ -106,6 +106,23 @@ class xstransact:
     1.4              ret.extend(self._list(key))
     1.5          return ret
     1.6  
     1.7 +    def gather(self, *args):
     1.8 +        ret = []
     1.9 +        for tup in args:
    1.10 +            if len(tup) == 2:
    1.11 +                (key, fn) = tup
    1.12 +                defval = None
    1.13 +            else:
    1.14 +                (key, fn, defval) = tup
    1.15 +            try:
    1.16 +                val = fn(self.read(key))
    1.17 +            except TypeError:
    1.18 +                val = defval
    1.19 +            ret.append(val)
    1.20 +        if len(ret) == 1:
    1.21 +            return ret[0]
    1.22 +        return ret
    1.23 +
    1.24  
    1.25      def Read(cls, path, *args):
    1.26          while True:
    1.27 @@ -115,10 +132,14 @@ class xstransact:
    1.28                  t.commit()
    1.29                  return v
    1.30              except RuntimeError, ex:
    1.31 +                t.abort()
    1.32                  if ex.args[0] == errno.ETIMEDOUT:
    1.33                      pass
    1.34                  else:
    1.35                      raise
    1.36 +            except:
    1.37 +                t.abort()
    1.38 +                raise
    1.39  
    1.40      Read = classmethod(Read)
    1.41  
    1.42 @@ -130,10 +151,14 @@ class xstransact:
    1.43                  t.commit()
    1.44                  return
    1.45              except RuntimeError, ex:
    1.46 +                t.abort()
    1.47                  if ex.args[0] == errno.ETIMEDOUT:
    1.48                      pass
    1.49                  else:
    1.50                      raise
    1.51 +            except:
    1.52 +                t.abort()
    1.53 +                raise
    1.54  
    1.55      Write = classmethod(Write)
    1.56  
    1.57 @@ -145,10 +170,14 @@ class xstransact:
    1.58                  t.commit()
    1.59                  return
    1.60              except RuntimeError, ex:
    1.61 +                t.abort()
    1.62                  if ex.args[0] == errno.ETIMEDOUT:
    1.63                      pass
    1.64                  else:
    1.65                      raise
    1.66 +            except:
    1.67 +                t.abort()
    1.68 +                raise
    1.69  
    1.70      Remove = classmethod(Remove)
    1.71  
    1.72 @@ -160,9 +189,32 @@ class xstransact:
    1.73                  t.commit()
    1.74                  return v
    1.75              except RuntimeError, ex:
    1.76 +                t.abort()
    1.77                  if ex.args[0] == errno.ETIMEDOUT:
    1.78                      pass
    1.79                  else:
    1.80                      raise
    1.81 +            except:
    1.82 +                t.abort()
    1.83 +                raise
    1.84  
    1.85      List = classmethod(List)
    1.86 +
    1.87 +    def Gather(cls, path, *args):
    1.88 +        while True:
    1.89 +            try:
    1.90 +                t = cls(path)
    1.91 +                v = t.gather(*args)
    1.92 +                t.commit()
    1.93 +                return v
    1.94 +            except RuntimeError, ex:
    1.95 +                t.abort()
    1.96 +                if ex.args[0] == errno.ETIMEDOUT:
    1.97 +                    pass
    1.98 +                else:
    1.99 +                    raise
   1.100 +            except:
   1.101 +                t.abort()
   1.102 +                raise
   1.103 +
   1.104 +    Gather = classmethod(Gather)