summaryrefslogtreecommitdiffstats
path: root/nova/wsgi.py
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2011-01-17 18:49:11 +0000
committerTarmac <>2011-01-17 18:49:11 +0000
commit3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba (patch)
tree170ef113ef53cae8d24012ac9db92d03d067fdd9 /nova/wsgi.py
parent93deb2e9a375a18300eff258f2353e597932c47b (diff)
parent6906137b99181925f091ca547d019499c3bc1701 (diff)
downloadnova-3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba.tar.gz
nova-3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba.tar.xz
nova-3b94033b06ccc2d503d899e9fd7a3c8c6e2a7cba.zip
Further decouple api routing decisions and move into paste.deploy configuration. This makes paste back the nova-api binary.
Diffstat (limited to 'nova/wsgi.py')
-rw-r--r--nova/wsgi.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/nova/wsgi.py b/nova/wsgi.py
index 00b351253..f31618547 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -21,6 +21,7 @@
Utility methods for working with WSGI servers
"""
+import os
import sys
from xml.dom import minidom
@@ -33,10 +34,16 @@ import webob
import webob.dec
import webob.exc
+from paste import deploy
+
+from nova import flags
from nova import log as logging
from nova import utils
+FLAGS = flags.FLAGS
+
+
class WritableLogger(object):
"""A thin wrapper that responds to `write` and logs."""
@@ -403,3 +410,64 @@ class Serializer(object):
node = doc.createTextNode(str(data))
result.appendChild(node)
return result
+
+
+def paste_config_file(basename):
+ """Find the best location in the system for a paste config file.
+
+ Search Order
+ ------------
+
+ The search for a paste config file honors `FLAGS.state_path`, which in a
+ version checked out from bzr will be the `nova` directory in the top level
+ of the checkout, and in an installation for a package for your distribution
+ will likely point to someplace like /etc/nova.
+
+ This method tries to load places likely to be used in development or
+ experimentation before falling back to the system-wide configuration
+ in `/etc/nova/`.
+
+ * Current working directory
+ * the `etc` directory under state_path, because when working on a checkout
+ from bzr this will point to the default
+ * top level of FLAGS.state_path, for distributions
+ * /etc/nova, which may not be diffrerent from state_path on your distro
+
+ """
+
+ configfiles = [basename,
+ os.path.join(FLAGS.state_path, 'etc', basename),
+ os.path.join(FLAGS.state_path, basename),
+ '/etc/nova/%s' % basename]
+ for configfile in configfiles:
+ if os.path.exists(configfile):
+ return configfile
+
+
+def load_paste_configuration(filename, appname):
+ """Returns a paste configuration dict, or None."""
+ filename = os.path.abspath(filename)
+ config = None
+ try:
+ config = deploy.appconfig("config:%s" % filename, name=appname)
+ except LookupError:
+ pass
+ return config
+
+
+def load_paste_app(filename, appname):
+ """Builds a wsgi app from a paste config, None if app not configured."""
+ filename = os.path.abspath(filename)
+ app = None
+ try:
+ app = deploy.loadapp("config:%s" % filename, name=appname)
+ except LookupError:
+ pass
+ return app
+
+
+def paste_config_to_flags(config, mixins):
+ for k, v in mixins.iteritems():
+ value = config.get(k, v)
+ converted_value = FLAGS[k].parser.Parse(value)
+ setattr(FLAGS, k, converted_value)