summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-03-16 19:04:27 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-03-16 19:04:27 -0700
commitc9158dfcf4efd2cf22df9aed7b1bb01e037e8eb2 (patch)
tree70525af2ba2c0e3139849566f2eb3774958e1de4 /nova/db
parent4d057c9c2df77816ead6f30fa2795148aa8148d3 (diff)
downloadnova-c9158dfcf4efd2cf22df9aed7b1bb01e037e8eb2.tar.gz
nova-c9158dfcf4efd2cf22df9aed7b1bb01e037e8eb2.tar.xz
nova-c9158dfcf4efd2cf22df9aed7b1bb01e037e8eb2.zip
moved scheduler API check into db.api decorator
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 2ecfc0211..6298e16ad 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -34,6 +34,7 @@ The underlying driver is loaded as a :class:`LazyPluggable`.
from nova import exception
from nova import flags
+from nova import log as logging
from nova import utils
@@ -52,6 +53,9 @@ IMPL = utils.LazyPluggable(FLAGS['db_backend'],
sqlalchemy='nova.db.sqlalchemy.api')
+LOG = logging.getLogger('server')
+
+
class NoMoreAddresses(exception.Error):
"""No more available addresses."""
pass
@@ -71,6 +75,34 @@ class NoMoreTargets(exception.Error):
"""No more available blades"""
pass
+
+###################
+
+
+def reroute_if_not_found(key_args_index=None):
+ """Decorator used to indicate that the method should throw
+ a RouteRedirectException if the query can't find anything.
+ """
+ def wrap(f):
+ def wrapped_f(*args, **kwargs):
+ try:
+ return f(*args, **kwargs)
+ except exception.InstanceNotFound, e:
+ context = args[0]
+ key = None
+ if key_args_index:
+ key = args[key_args_index]
+ LOG.debug(_("Instance %(key)s not found locally: '%(e)s'" %
+ locals()))
+
+ # Throw a reroute Exception for the middleware to pick up.
+ LOG.debug("Firing ZoneRouteException")
+ zones = zone_get_all(context)
+ raise exception.ZoneRouteException(zones, e)
+ return wrapped_f
+ return wrap
+
+
###################
@@ -367,7 +399,8 @@ def instance_destroy(context, instance_id):
return IMPL.instance_destroy(context, instance_id)
-def instance_get(context, instance_id):
+@reroute_if_not_found(key_args_index=1)
+def instance_get(context, instance_id, reroute=True):
"""Get an instance or raise if it does not exist."""
return IMPL.instance_get(context, instance_id)