This Page

Psst... hey. You're reading the latest content, but it might be out of sync with code. You can read Nova 2011.1 docs or all OpenStack docs too.

The nova.wsgi Module

Utility methods for working with WSGI servers

class nova.wsgi.Application

Bases: object

Base WSGI application wrapper. Subclasses need to implement __call__.

classmethod factory(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.

class nova.wsgi.Controller

Bases: object

WSGI app that reads routing information supplied by RoutesMiddleware and calls the requested action method upon itself. All action methods must, in addition to their normal parameters, accept a ‘req’ argument which is the incoming wsgi.Request. They raise a webob.exc exception, or return a dict which will be serialized by requested content type.

get_default_xmlns(req)

Provide the XML namespace to use if none is otherwise specified.

class nova.wsgi.Debug(application)

Bases: nova.wsgi.Middleware

Helper class that can be inserted into any WSGI application chain to get information about the request and response.

static print_generator(app_iter)

Iterator that prints the contents of a wrapper string iterator when iterated.

class nova.wsgi.Middleware(application)

Bases: nova.wsgi.Application

Base WSGI middleware.

These classes require an application to be initialized that will be called next. By default the middleware will simply call its wrapped app, or you can override __call__ to customize its behavior.

classmethod factory(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.

process_request(req)

Called on each request.

If this returns None, the next application down the stack will be executed. If it returns a response then that response will be returned and execution will stop here.

process_response(response)

Do whatever you’d like to the response.

class nova.wsgi.Request(environ=None, environ_getter=None, charset=(No Default), unicode_errors=(No Default), decode_param_names=(No Default), **kw)

Bases: webob.request.Request

best_match_content_type()

Determine the most acceptable content-type based on the query extension then the Accept header

get_content_type()
class nova.wsgi.Router(mapper)

Bases: object

WSGI middleware that maps incoming requests to WSGI apps.

class nova.wsgi.Serializer(metadata=None, default_xmlns=None)

Bases: object

Serializes and deserializes dictionaries to certain MIME types.

deserialize(datastring, content_type)

Deserialize a string to a dictionary.

The string must be in the format of a supported MIME type.

get_deserialize_handler(content_type)
serialize(data, content_type)

Serialize a dictionary into a string of the specified content type.

class nova.wsgi.Server(threads=1000)

Bases: object

Server class to manage multiple WSGI sockets and applications.

start(application, port, host='0.0.0.0', backlog=128)

Run a WSGI server with the given application.

wait()

Wait until all servers have completed running.

class nova.wsgi.WritableLogger(logger, level=10)

Bases: object

A thin wrapper that responds to write and logs.

write(msg)
nova.wsgi.load_paste_app(filename, appname)

Builds a wsgi app from a paste config, None if app not configured.

nova.wsgi.load_paste_configuration(filename, appname)

Returns a paste configuration dict, or None.

nova.wsgi.paste_config_file(basename)

Find the best location in the system for a paste config file.

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