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/wsgi.py | |
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/wsgi.py')
-rw-r--r-- | nova/wsgi.py | 54 |
1 files changed, 52 insertions, 2 deletions
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 |