Moved functionality into wsgi.Controller.

* Found that classes from multiple modules were inheriting from reddwarf.instances.service.BaseController or InstanceController directly (the later of which wass probably adding bugs) and so moved all the common functionality into wsgi controller.
* Moved exceptions from other exception maps into wsgi.Controller's exception_map.
This commit is contained in:
Tim Simpson 2012-06-26 08:44:24 -05:00
parent 55eb6d1e59
commit bed395ed74
5 changed files with 55 additions and 119 deletions

View File

@ -227,7 +227,45 @@ class Resource(openstack_wsgi.Resource):
class Controller(object):
"""Base controller that creates a Resource with default serializers."""
exception_map = {}
exclude_attr = []
exception_map = {
webob.exc.HTTPUnprocessableEntity: [
exception.UnprocessableEntity,
],
webob.exc.HTTPUnauthorized: [
exception.Forbidden,
],
webob.exc.HTTPBadRequest: [
exception.InvalidModelError,
exception.BadRequest,
exception.CannotResizeToSameSize,
exception.BadValue,
exception.DatabaseAlreadyExists,
exception.UserAlreadyExists,
],
webob.exc.HTTPNotFound: [
exception.NotFound,
exception.ComputeInstanceNotFound,
exception.ModelNotFoundError,
],
webob.exc.HTTPConflict: [
],
webob.exc.HTTPRequestEntityTooLarge: [
exception.OverLimit,
exception.QuotaExceeded,
exception.VolumeQuotaExceeded,
],
webob.exc.HTTPServerError: [
exception.VolumeCreationFailure
],
}
def __init__(self):
self.add_addresses = utils.bool_from_string(
config.Config.get('add_addresses', 'False'))
self.add_volumes = utils.bool_from_string(
config.Config.get('reddwarf_volume_support', 'False'))
def create_resource(self):
serializer = ReddwarfResponseSerializer(
@ -237,6 +275,16 @@ class Controller(object):
serializer,
self.exception_map)
def _extract_limits(self, params):
return dict([(key, params[key]) for key in params.keys()
if key in ["limit", "marker"]])
def _extract_required_params(self, params, model_name):
params = params or {}
model_params = params.get(model_name, {})
return utils.stringify_keys(utils.exclude(model_params,
*self.exclude_attr))
class ReddwarfRequestDeserializer(RequestDeserializer):
"""Break up a Request object into more useful pieces."""

View File

@ -30,42 +30,7 @@ from reddwarf.extensions.mysql import views
LOG = logging.getLogger(__name__)
class BaseController(wsgi.Controller):
"""Base controller class."""
exclude_attr = []
exception_map = {
webob.exc.HTTPUnprocessableEntity: [
exception.UnprocessableEntity,
],
webob.exc.HTTPBadRequest: [
exception.BadRequest,
exception.DatabaseAlreadyExists,
exception.UserAlreadyExists
],
webob.exc.HTTPNotFound: [
exception.NotFound,
exception.ModelNotFoundError,
],
webob.exc.HTTPConflict: [
],
}
def __init__(self):
pass
def _extract_required_params(self, params, model_name):
params = params or {}
model_params = params.get(model_name, {})
return utils.stringify_keys(utils.exclude(model_params,
*self.exclude_attr))
def _extract_limits(self, params):
return dict([(key, params[key]) for key in params.keys()
if key in ["limit", "marker"]])
class RootController(BaseController):
class RootController(wsgi.Controller):
"""Controller for instance functionality"""
def index(self, req, tenant_id, instance_id):
@ -87,7 +52,7 @@ class RootController(BaseController):
return wsgi.Result(views.RootCreatedView(root).data(), 200)
class UserController(BaseController):
class UserController(wsgi.Controller):
"""Controller for instance functionality"""
@classmethod
@ -142,8 +107,7 @@ class UserController(BaseController):
def show(self, req, tenant_id, instance_id, id):
raise webob.exc.HTTPNotImplemented()
class SchemaController(BaseController):
class SchemaController(wsgi.Controller):
"""Controller for instance functionality"""
@classmethod

View File

@ -25,34 +25,7 @@ from reddwarf.flavor import models
from reddwarf.flavor import views
class BaseController(wsgi.Controller):
"""Base controller class."""
exclude_attr = []
exception_map = {
webob.exc.HTTPUnprocessableEntity: [
],
webob.exc.HTTPBadRequest: [
exception.BadRequest,
],
webob.exc.HTTPNotFound: [
exception.NotFound,
],
webob.exc.HTTPConflict: [
],
}
def __init__(self):
pass
def _extract_required_params(self, params, model_name):
params = params or {}
model_params = params.get(model_name, {})
return utils.stringify_keys(utils.exclude(model_params,
*self.exclude_attr))
class FlavorController(BaseController):
class FlavorController(wsgi.Controller):
"""Controller for flavor functionality"""
def show(self, req, tenant_id, id):

View File

@ -557,7 +557,7 @@ class DBInstance(dbmodels.DatabaseModelBase):
_data_fields = ['name', 'created', 'compute_instance_id',
'task_id', 'task_description', 'task_start_time',
'volume_id', 'deleted']
'volume_id', 'deleted', 'tenant_id']
def __init__(self, task_status=None, **kwargs):
kwargs["task_id"] = task_status.code

View File

@ -33,55 +33,6 @@ CONFIG = config.Config
LOG = logging.getLogger(__name__)
class BaseController(wsgi.Controller):
"""Base controller class."""
exclude_attr = []
exception_map = {
webob.exc.HTTPUnprocessableEntity: [
exception.UnprocessableEntity,
],
webob.exc.HTTPBadRequest: [
exception.InvalidModelError,
exception.BadRequest,
exception.CannotResizeToSameSize,
exception.BadValue
],
webob.exc.HTTPNotFound: [
exception.NotFound,
exception.ComputeInstanceNotFound,
exception.ModelNotFoundError,
],
webob.exc.HTTPConflict: [
],
webob.exc.HTTPRequestEntityTooLarge: [
exception.OverLimit,
exception.QuotaExceeded,
exception.VolumeQuotaExceeded,
],
webob.exc.HTTPServerError: [
exception.VolumeCreationFailure
]
}
def __init__(self):
self.add_addresses = utils.bool_from_string(
config.Config.get('add_addresses', 'False'))
self.add_volumes = utils.bool_from_string(
config.Config.get('reddwarf_volume_support', 'False'))
pass
def _extract_limits(self, params):
return dict([(key, params[key]) for key in params.keys()
if key in ["limit", "marker"]])
def _extract_required_params(self, params, model_name):
params = params or {}
model_params = params.get(model_name, {})
return utils.stringify_keys(utils.exclude(model_params,
*self.exclude_attr))
class api_validation:
""" api validation wrapper """
def __init__(self, action=None):
@ -99,7 +50,7 @@ class api_validation:
return wrapper
class InstanceController(BaseController):
class InstanceController(wsgi.Controller):
"""Controller for instance functionality"""
def action(self, req, body, tenant_id, id):