summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2011-10-10 17:58:56 -0500
committerRick Harris <rconradharris@gmail.com>2011-10-13 18:46:38 -0500
commit46d04831f5c290a40c14da415169749e2ef41383 (patch)
treef3d20cf687ff074e719b861ab871bdc73c204e3f /nova/utils.py
parent56be39aedb195576179e73c859db2271a9585496 (diff)
downloadnova-46d04831f5c290a40c14da415169749e2ef41383.tar.gz
nova-46d04831f5c290a40c14da415169749e2ef41383.tar.xz
nova-46d04831f5c290a40c14da415169749e2ef41383.zip
Xenapi driver can now generate swap from instance_type
Change-Id: I50268a85ccd62b019436a207c2b52b1901597564
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 1d2063798..2477349cb 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -19,6 +19,7 @@
"""Utilities and helper functions."""
+import contextlib
import datetime
import functools
import inspect
@@ -931,3 +932,36 @@ def generate_glance_url():
# TODO(jk0): This will eventually need to take SSL into consideration
# when supported in glance.
return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
+
+
+@contextlib.contextmanager
+def original_exception_raised():
+ """Run some code, then re-raise the original exception.
+
+ This is needed because when Eventlet switches greenthreads, it clears the
+ exception context. This means if exception handler code blocks, we'll lose
+ the helpful exception traceback information.
+
+ To work around this, we save the exception state, run handler code, and
+ then re-raise the original exception.
+ """
+ type_, value, traceback = sys.exc_info()
+ try:
+ yield
+ finally:
+ raise type_, value, traceback
+
+
+def make_dev_path(dev, partition=None, base='/dev'):
+ """Return a path to a particular device.
+
+ >>> make_dev_path('xvdc')
+ /dev/xvdc
+
+ >>> make_dev_path('xvdc', 1)
+ /dev/xvdc1
+ """
+ path = os.path.join(base, dev)
+ if partition:
+ path += str(partition)
+ return path