diff options
| author | Todd Willey <todd@ansolabs.com> | 2011-01-17 19:19:15 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-01-17 19:19:15 +0000 |
| commit | 8e6684a58eea3ecacdde99e1940d2ae351b8465c (patch) | |
| tree | 11ce1d8116abce7a062294e9375259eae8817c6b /nova | |
| parent | 3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba (diff) | |
| parent | b156f7d9593135a0ab3de83c25643bb0201e2747 (diff) | |
| download | nova-8e6684a58eea3ecacdde99e1940d2ae351b8465c.tar.gz nova-8e6684a58eea3ecacdde99e1940d2ae351b8465c.tar.xz nova-8e6684a58eea3ecacdde99e1940d2ae351b8465c.zip | |
Change where paste.deploy factories live and how they are called. They are now in the nova.wsgi.Application/Middleware classes, and call the __init__ method of their class with kwargs of the local configuration of the paste file.
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/ec2/__init__.py | 42 | ||||
| -rw-r--r-- | nova/api/ec2/metadatarequesthandler.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/__init__.py | 19 | ||||
| -rw-r--r-- | nova/api/openstack/auth.py | 6 | ||||
| -rw-r--r-- | nova/api/openstack/ratelimiting/__init__.py | 6 | ||||
| -rw-r--r-- | nova/wsgi.py | 54 |
6 files changed, 61 insertions, 73 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index d0adf5e21..238cb0f38 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -186,9 +186,9 @@ class Authenticate(wsgi.Middleware): class Requestify(wsgi.Middleware): - def __init__(self, app, controller_name): + def __init__(self, app, controller): super(Requestify, self).__init__(app) - self.controller = utils.import_class(controller_name)() + self.controller = utils.import_class(controller)() @webob.dec.wsgify def __call__(self, req): @@ -365,41 +365,3 @@ class Versions(wsgi.Application): '2009-04-04', ] return ''.join('%s\n' % v for v in versions) - - -def request_logging_factory(global_args, **local_args): - def logger(app): - return RequestLogging(app) - return logger - - -def authenticate_factory(global_args, **local_args): - def authenticator(app): - return Authenticate(app) - return authenticator - - -def authorizer_factory(global_args, **local_args): - def authorizer(app): - return Authorizer(app) - return authorizer - - -def executor_factory(global_args, **local_args): - return Executor() - - -def versions_factory(global_args, **local_args): - return Versions() - - -def requestify_factory(global_args, **local_args): - def requestifier(app): - return Requestify(app, local_args['controller']) - return requestifier - - -def lockout_factory(global_args, **local_args): - def locksmith(app): - return Lockout(app) - return locksmith diff --git a/nova/api/ec2/metadatarequesthandler.py b/nova/api/ec2/metadatarequesthandler.py index 848f0b034..6fb441656 100644 --- a/nova/api/ec2/metadatarequesthandler.py +++ b/nova/api/ec2/metadatarequesthandler.py @@ -23,6 +23,7 @@ import webob.exc from nova import log as logging from nova import flags +from nova import wsgi from nova.api.ec2 import cloud @@ -30,7 +31,7 @@ LOG = logging.getLogger('nova.api.ec2.metadata') FLAGS = flags.FLAGS -class MetadataRequestHandler(object): +class MetadataRequestHandler(wsgi.Application): """Serve metadata from the EC2 API.""" def print_data(self, data): @@ -78,7 +79,3 @@ class MetadataRequestHandler(object): if data is None: raise webob.exc.HTTPNotFound() return self.print_data(data) - - -def metadata_factory(global_args, **local_args): - return MetadataRequestHandler() diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 302d50ac8..f2caac483 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -65,6 +65,11 @@ class APIRouter(wsgi.Router): and method. """ + @classmethod + def factory(cls, global_config, **local_config): + """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one""" + return cls() + def __init__(self): mapper = routes.Mapper() @@ -114,17 +119,3 @@ class Versions(wsgi.Application): "application/xml": { "attributes": dict(version=["status", "id"])}} return wsgi.Serializer(req.environ, metadata).to_content_type(response) - - -def router_factory(global_cof, **local_conf): - return APIRouter() - - -def versions_factory(global_conf, **local_conf): - return Versions() - - -def fault_wrapper_factory(global_conf, **local_conf): - def fwrap(app): - return FaultWrapper(app) - return fwrap diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/auth.py index 00e817c8d..1dfdd5318 100644 --- a/nova/api/openstack/auth.py +++ b/nova/api/openstack/auth.py @@ -134,9 +134,3 @@ class AuthMiddleware(wsgi.Middleware): token = self.db.auth_create_token(ctxt, token_dict) return token, user return None, None - - -def auth_factory(global_conf, **local_conf): - def auth(app): - return AuthMiddleware(app) - return auth diff --git a/nova/api/openstack/ratelimiting/__init__.py b/nova/api/openstack/ratelimiting/__init__.py index 81b83142f..cbb4b897e 100644 --- a/nova/api/openstack/ratelimiting/__init__.py +++ b/nova/api/openstack/ratelimiting/__init__.py @@ -219,9 +219,3 @@ class WSGIAppProxy(object): # No delay return None return float(resp.getheader('X-Wait-Seconds')) - - -def ratelimit_factory(global_conf, **local_conf): - def rl(app): - return RateLimitingMiddleware(app) - return rl diff --git a/nova/wsgi.py b/nova/wsgi.py index f31618547..4f5307d80 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -83,10 +83,33 @@ class Server(object): class Application(object): -# TODO(gundlach): I think we should toss this class, now that it has no -# purpose. """Base WSGI application wrapper. Subclasses need to implement __call__.""" + @classmethod + def factory(cls, global_config, **local_config): + """Used for paste app factories in paste.deploy config fles. + + Any local configuration (that is, values under the [app:APPNAME] + section of the paste config) will be passed into the `__init__` method + as kwargs. + + A hypothetical configuration would look like: + + [app:wadl] + latest_version = 1.3 + paste.app_factory = nova.api.fancy_api:Wadl.factory + + which would result in a call to the `Wadl` class as + + import nova.api.fancy_api + fancy_api.Wadl(latest_version='1.3') + + You could of course re-implement the `factory` method in subclasses, + but using the kwarg passing it shouldn't be necessary. + + """ + return cls(**local_config) + def __call__(self, environ, start_response): r"""Subclasses will probably want to implement __call__ like this: @@ -132,6 +155,33 @@ class Middleware(Application): behavior. """ + @classmethod + def factory(cls, global_config, **local_config): + """Used for paste app factories in paste.deploy config fles. + + Any local configuration (that is, values under the [filter:APPNAME] + section of the paste config) will be passed into the `__init__` method + as kwargs. + + A hypothetical configuration would look like: + + [filter:analytics] + redis_host = 127.0.0.1 + paste.filter_factory = nova.api.analytics:Analytics.factory + + which would result in a call to the `Analytics` class as + + import nova.api.analytics + analytics.Analytics(app_from_paste, redis_host='127.0.0.1') + + You could of course re-implement the `factory` method in subclasses, + but using the kwarg passing it shouldn't be necessary. + + """ + def _factory(app): + return cls(app, **local_config) + return _factory + def __init__(self, application): self.application = application |
