# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID eb6fbb3d0a7b1bde4546957314b12ed3557b1d71
# Parent 9c9a3bb878c2c1c9cc932cbc90335ad701b0e009
Add gather function and robustify class methods' failure handling.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
diff -r 9c9a3bb878c2 -r eb6fbb3d0a7b
tools/python/xen/xend/xenstore/xstransact.py
--- a/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 14 17:06:37 2005
+++ b/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 14 18:24:25 2005
@@ -106,6 +106,23 @@
ret.extend(self._list(key))
return ret
+ def gather(self, *args):
+ ret = []
+ for tup in args:
+ if len(tup) == 2:
+ (key, fn) = tup
+ defval = None
+ else:
+ (key, fn, defval) = tup
+ try:
+ val = fn(self.read(key))
+ except TypeError:
+ val = defval
+ ret.append(val)
+ if len(ret) == 1:
+ return ret[0]
+ return ret
+
def Read(cls, path, *args):
while True:
@@ -115,10 +132,14 @@
t.commit()
return v
except RuntimeError, ex:
- if ex.args[0] == errno.ETIMEDOUT:
- pass
- else:
- raise
+ t.abort()
+ if ex.args[0] == errno.ETIMEDOUT:
+ pass
+ else:
+ raise
+ except:
+ t.abort()
+ raise
Read = classmethod(Read)
@@ -130,10 +151,14 @@
t.commit()
return
except RuntimeError, ex:
- if ex.args[0] == errno.ETIMEDOUT:
- pass
- else:
- raise
+ t.abort()
+ if ex.args[0] == errno.ETIMEDOUT:
+ pass
+ else:
+ raise
+ except:
+ t.abort()
+ raise
Write = classmethod(Write)
@@ -145,10 +170,14 @@
t.commit()
return
except RuntimeError, ex:
- if ex.args[0] == errno.ETIMEDOUT:
- pass
- else:
- raise
+ t.abort()
+ if ex.args[0] == errno.ETIMEDOUT:
+ pass
+ else:
+ raise
+ except:
+ t.abort()
+ raise
Remove = classmethod(Remove)
@@ -160,9 +189,32 @@
t.commit()
return v
except RuntimeError, ex:
- if ex.args[0] == errno.ETIMEDOUT:
- pass
- else:
- raise
+ t.abort()
+ if ex.args[0] == errno.ETIMEDOUT:
+ pass
+ else:
+ raise
+ except:
+ t.abort()
+ raise
List = classmethod(List)
+
+ def Gather(cls, path, *args):
+ while True:
+ try:
+ t = cls(path)
+ v = t.gather(*args)
+ t.commit()
+ return v
+ except RuntimeError, ex:
+ t.abort()
+ if ex.args[0] == errno.ETIMEDOUT:
+ pass
+ else:
+ raise
+ except:
+ t.abort()
+ raise
+
+ Gather = classmethod(Gather)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|