summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2011-01-17 19:19:15 +0000
committerTarmac <>2011-01-17 19:19:15 +0000
commit8e6684a58eea3ecacdde99e1940d2ae351b8465c (patch)
tree11ce1d8116abce7a062294e9375259eae8817c6b
parent3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba (diff)
parentb156f7d9593135a0ab3de83c25643bb0201e2747 (diff)
downloadnova-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.
-rw-r--r--etc/nova-api.conf28
-rw-r--r--nova/api/ec2/__init__.py42
-rw-r--r--nova/api/ec2/metadatarequesthandler.py7
-rw-r--r--nova/api/openstack/__init__.py19
-rw-r--r--nova/api/openstack/auth.py6
-rw-r--r--nova/api/openstack/ratelimiting/__init__.py6
-rw-r--r--nova/wsgi.py54
7 files changed, 75 insertions, 87 deletions
diff --git a/etc/nova-api.conf b/etc/nova-api.conf
index b68471ece..4873e465d 100644
--- a/etc/nova-api.conf
+++ b/etc/nova-api.conf
@@ -28,33 +28,33 @@ pipeline = logrequest ec2md
pipeline = logrequest ec2ver
[filter:logrequest]
-paste.filter_factory = nova.api.ec2:request_logging_factory
+paste.filter_factory = nova.api.ec2:RequestLogging.factory
[filter:ec2lockout]
-paste.filter_factory = nova.api.ec2:lockout_factory
+paste.filter_factory = nova.api.ec2:Lockout.factory
[filter:authenticate]
-paste.filter_factory = nova.api.ec2:authenticate_factory
+paste.filter_factory = nova.api.ec2:Authenticate.factory
[filter:cloudrequest]
controller = nova.api.ec2.cloud.CloudController
-paste.filter_factory = nova.api.ec2:requestify_factory
+paste.filter_factory = nova.api.ec2:Requestify.factory
[filter:adminrequest]
controller = nova.api.ec2.admin.AdminController
-paste.filter_factory = nova.api.ec2:requestify_factory
+paste.filter_factory = nova.api.ec2:Requestify.factory
[filter:authorizer]
-paste.filter_factory = nova.api.ec2:authorizer_factory
+paste.filter_factory = nova.api.ec2:Authorizer.factory
[app:ec2executor]
-paste.app_factory = nova.api.ec2:executor_factory
+paste.app_factory = nova.api.ec2:Executor.factory
[app:ec2ver]
-paste.app_factory = nova.api.ec2:versions_factory
+paste.app_factory = nova.api.ec2:Versions.factory
[app:ec2md]
-paste.app_factory = nova.api.ec2.metadatarequesthandler:metadata_factory
+paste.app_factory = nova.api.ec2.metadatarequesthandler:MetadataRequestHandler.factory
#############
# Openstack #
@@ -69,19 +69,19 @@ use = egg:Paste#urlmap
pipeline = faultwrap auth ratelimit osapiapp
[filter:faultwrap]
-paste.filter_factory = nova.api.openstack:fault_wrapper_factory
+paste.filter_factory = nova.api.openstack:FaultWrapper.factory
[filter:auth]
-paste.filter_factory = nova.api.openstack.auth:auth_factory
+paste.filter_factory = nova.api.openstack.auth:AuthMiddleware.factory
[filter:ratelimit]
-paste.filter_factory = nova.api.openstack.ratelimiting:ratelimit_factory
+paste.filter_factory = nova.api.openstack.ratelimiting:RateLimitingMiddleware.factory
[app:osapiapp]
-paste.app_factory = nova.api.openstack:router_factory
+paste.app_factory = nova.api.openstack:APIRouter.factory
[pipeline:osversions]
pipeline = faultwrap osversionapp
[app:osversionapp]
-paste.app_factory = nova.api.openstack:versions_factory
+paste.app_factory = nova.api.openstack:Versions.factory
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