From 65bff9b98471bfd09cee2c24aba7f2e5d0f0cacd Mon Sep 17 00:00:00 2001 From: Martin Packman Date: Thu, 21 Jun 2012 01:29:20 +0100 Subject: Tidy up exception handling in contrib api consoles Removes redundant exception handling from VNC consoles extension api module. Both NotAuthorized and Invalid subclasses are already handled at the wsgi application layer. Also gives a better message, including the id, when an instance is not found. Includes tweaks suggested by Vish in review. Change-Id: Iefa4deeb46e4a12d012e7abe3c73d7d9c18afeff --- nova/api/openstack/compute/contrib/consoles.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/consoles.py b/nova/api/openstack/compute/contrib/consoles.py index 712cda87b..915ca5c87 100644 --- a/nova/api/openstack/compute/contrib/consoles.py +++ b/nova/api/openstack/compute/contrib/consoles.py @@ -38,26 +38,16 @@ class ConsolesController(wsgi.Controller): context = req.environ['nova.context'] authorize(context) + # If type is not supplied or unknown, get_vnc_console below will cope console_type = body['os-getVNCConsole'].get('type') - if not console_type: - raise webob.exc.HTTPBadRequest(_('Missing type specification')) - try: instance = self.compute_api.get(context, id) - except exception.NotFound: - raise webob.exc.HTTPNotFound(_('Instance not found')) - - try: output = self.compute_api.get_vnc_console(context, instance, console_type) - except exception.ConsoleTypeInvalid, e: - raise webob.exc.HTTPBadRequest(_('Invalid type specification')) - except exception.NotAuthorized: - raise webob.exc.HTTPUnauthorized() - except exception.NotFound: - raise webob.exc.HTTPNotFound(_('Instance not found')) + except exception.InstanceNotFound as e: + raise webob.exc.HTTPNotFound(explanation=unicode(e)) return {'console': {'type': console_type, 'url': output['url']}} -- cgit