summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-09-15 13:00:21 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-09-15 13:00:21 -0700
commit97f28ec95ce1c6a1d3cb9c896b4ac2b4b51589e2 (patch)
tree29348f30ad84e666a6e4a8de602817be33f835a6 /nova/api
parent65e3f8201d88f231dfbd7934f5b920ae3b1d8e31 (diff)
downloadnova-97f28ec95ce1c6a1d3cb9c896b4ac2b4b51589e2.tar.gz
nova-97f28ec95ce1c6a1d3cb9c896b4ac2b4b51589e2.tar.xz
nova-97f28ec95ce1c6a1d3cb9c896b4ac2b4b51589e2.zip
exceptions properly passed around now
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/servers.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 5affd1f33..6dc168203 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -17,6 +17,7 @@ import base64
import os
import traceback
+from novaclient import exceptions as novaclient_exceptions
from lxml import etree
from webob import exc
import webob
@@ -45,6 +46,29 @@ LOG = logging.getLogger('nova.api.openstack.servers')
FLAGS = flags.FLAGS
+class ConvertedException(exc.WSGIHTTPException):
+ def __init__(self, code, title, explaination):
+ self.code = code
+ self.title = title
+ self.explaination = explaination
+ super(ConvertedException, self).__init__()
+
+
+def novaclient_exception_converter(f):
+ """Convert novaclient ClientException HTTP codes to webob exceptions.
+ """
+ def new_f(*args, **kwargs):
+ try:
+ LOG.debug("**** NOVACLIENT EXCEPTION CONVERTER >>>>")
+ ret = f(*args, **kwargs)
+ LOG.debug("**** NOVACLIENT EXCEPTION CONVERTER <<<<")
+ return ret
+ except novaclient_exceptions.ClientException, e:
+ LOG.debug("**** NOVACLIENT EXCEPTION CONVERTER- RERAISING")
+ raise ConvertedException(e.code, e.message, e.details)
+ return new_f
+
+
class Controller(object):
""" The Server API base controller class for the OpenStack API """
@@ -135,6 +159,7 @@ class Controller(object):
return dict(servers=servers)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def show(self, req, id):
""" Returns server details by server id """
@@ -169,6 +194,7 @@ class Controller(object):
server['server']['adminPass'] = extra_values['password']
return server
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def update(self, req, id, body):
"""Update server then pass on to version-specific controller"""
@@ -204,6 +230,7 @@ class Controller(object):
def _update(self, context, req, id, inst_dict):
return exc.HTTPNotImplemented()
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def action(self, req, id, body):
"""Multi-purpose method used to take actions on a server"""
@@ -342,6 +369,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def lock(self, req, id):
"""
@@ -358,6 +386,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def unlock(self, req, id):
"""
@@ -374,6 +403,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def get_lock(self, req, id):
"""
@@ -389,6 +419,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def reset_network(self, req, id):
"""
@@ -404,6 +435,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def inject_network_info(self, req, id):
"""
@@ -419,6 +451,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def pause(self, req, id):
""" Permit Admins to Pause the server. """
@@ -431,6 +464,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def unpause(self, req, id):
""" Permit Admins to Unpause the server. """
@@ -443,6 +477,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def suspend(self, req, id):
"""permit admins to suspend the server"""
@@ -455,6 +490,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def resume(self, req, id):
"""permit admins to resume the server from suspend"""
@@ -467,6 +503,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def migrate(self, req, id):
try:
@@ -476,6 +513,7 @@ class Controller(object):
raise exc.HTTPBadRequest()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def rescue(self, req, id):
"""Permit users to rescue the server."""
@@ -488,6 +526,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def unrescue(self, req, id):
"""Permit users to unrescue the server."""
@@ -500,6 +539,7 @@ class Controller(object):
raise exc.HTTPUnprocessableEntity()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def get_ajax_console(self, req, id):
"""Returns a url to an instance's ajaxterm console."""
@@ -510,6 +550,7 @@ class Controller(object):
raise exc.HTTPNotFound()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def get_vnc_console(self, req, id):
"""Returns a url to an instance's ajaxterm console."""
@@ -520,6 +561,7 @@ class Controller(object):
raise exc.HTTPNotFound()
return webob.Response(status_int=202)
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def diagnostics(self, req, id):
"""Permit Admins to retrieve server diagnostics."""
@@ -562,6 +604,7 @@ class Controller(object):
class ControllerV10(Controller):
"""v1.0 OpenStack API controller"""
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def delete(self, req, id):
""" Destroys a server """
@@ -640,6 +683,7 @@ class ControllerV10(Controller):
class ControllerV11(Controller):
"""v1.1 OpenStack API controller"""
+ @novaclient_exception_converter
@scheduler_api.redirect_handler
def delete(self, req, id):
""" Destroys a server """