heat.common.wsgi module

Utility methods for working with WSGI servers.

class heat.common.wsgi.AppFactory(conf)[source]

Bases: heat.common.wsgi.BasePasteFactory

A Generic paste.deploy app factory.

This requires heat.app_factory to be set to a callable which returns a WSGI app when invoked. The format of the name is <module>:<callable> e.g.

[app:apiv1app] paste.app_factory = heat.common.wsgi:app_factory heat.app_factory = heat.api.cfn.v1:API

The WSGI app constructor must accept a ConfigOpts object and a local config dict as its two arguments.

KEY = 'heat.app_factory'
class heat.common.wsgi.BasePasteFactory(conf)[source]

Bases: object

A base class for paste app and filter factories.

Sub-classes must override the KEY class attribute and provide a __call__ method.

KEY = None
class heat.common.wsgi.Debug(application)[source]

Bases: heat.common.wsgi.Middleware

Helper class to get information about the request and response.

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

static print_generator(app_iter)[source]

Prints the contents of a wrapper string iterator when iterated.

class heat.common.wsgi.DefaultMethodController[source]

Bases: object

Controller that handles the OPTIONS request method.

This controller handles the OPTIONS request method and any of the HTTP methods that are not explicitly implemented by the application.

options(req, allowed_methods, *args, **kwargs)[source]

Return a response that includes the ‘Allow’ header.

Return a response that includes the ‘Allow’ header listing the methods that are implemented. A 204 status code is used for this response.

reject(req, allowed_methods, *args, **kwargs)[source]

Return a 405 method not allowed error.

As a convenience, the ‘Allow’ header with the list of implemented methods is included in the response as well.

class heat.common.wsgi.FilterFactory(conf)[source]

Bases: heat.common.wsgi.AppFactory

A Generic paste.deploy filter factory.

This requires heat.filter_factory to be set to a callable which returns a WSGI filter when invoked. The format is <module>:<callable> e.g.

[filter:cache] paste.filter_factory = heat.common.wsgi:filter_factory heat.filter_factory = heat.api.middleware.cache:CacheFilter

The WSGI filter constructor must accept a WSGI app, a ConfigOpts object and a local config dict as its three arguments.

KEY = 'heat.filter_factory'
class heat.common.wsgi.JSONRequestDeserializer[source]

Bases: object

default(request)[source]
from_json(datastring)[source]
has_body(request)[source]

Returns whether a Webob.Request object will possess an entity body.

Parameters

request – Webob.Request object

class heat.common.wsgi.Middleware(application)[source]

Bases: object

Base WSGI middleware wrapper.

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.

process_request(req)[source]

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)[source]

Do whatever you’d like to the response.

class heat.common.wsgi.Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)[source]

Bases: webob.request.Request

Add some OpenStack API-specific logic to the base webob.Request.

best_match_content_type()[source]

Determine the requested response content-type.

best_match_language()[source]

Determines best available locale from the Accept-Language header.

Returns

the best language match or None if the ‘Accept-Language’ header was not available in the request.

get_content_type(allowed_content_types)[source]

Determine content type of the request body.

class heat.common.wsgi.Resource(controller, deserializer, serializer=None)[source]

Bases: object

WSGI app that handles (de)serialization and controller dispatch.

Reads routing information supplied by RoutesMiddleware and calls the requested action method upon its deserializer, controller, and serializer. Those three objects may implement any of the basic controller action methods (create, update, show, index, delete) along with any that may be specified in the api router. A ‘default’ method may also be implemented to be used in place of any non-implemented actions. Deserializer methods must accept a request argument and return a dictionary. Controller methods must accept a request argument. Additionally, they must also accept keyword arguments that represent the keys returned by the Deserializer. They may raise a webob.exc exception or return a dict, which will be serialized by requested content type.

dispatch(obj, action, *args, **kwargs)[source]

Find action-specific method on self and call it.

get_action_args(request_environment)[source]

Parse dictionary created by routes library.

class heat.common.wsgi.Router(mapper)[source]

Bases: object

WSGI middleware that maps incoming requests to WSGI apps.

class heat.common.wsgi.Server(name, conf, threads=1000)[source]

Bases: object

Server class to manage multiple WSGI sockets and applications.

configure_socket(old_conf=None, has_changed=None)[source]

Ensure a socket exists and is appropriately configured.

This function is called on start up, and can also be called in the event of a configuration reload.

When called for the first time a new socket is created. If reloading and either bind_host or bind port have been changed the existing socket must be closed and a new socket opened (laws of physics).

In all other cases (bind_host/bind_port have not changed) the existing socket is reused.

Parameters
  • old_conf – Cached old configuration settings (if any)

  • changed (has) – callable to determine if a parameter has changed

hup(*args)[source]

Reloads configuration files with zero down time.

kill_children(*args)[source]

Kills the entire process group.

reload()[source]

Reload and re-apply configuration settings.

Existing child processes are sent a SIGHUP signal and will exit after completing existing requests. New child processes, which will have the updated configuration, are spawned. This allows preventing interruption to the service.

run_child()[source]
run_server()[source]

Run a WSGI server.

start(application, default_port)[source]

Run a WSGI server with the given application.

Parameters
  • application – The application to run in the WSGI server

  • default_port – Port to bind to if none is specified in conf

start_wsgi()[source]
stash_conf_values()[source]

Make a copy of some of the current global CONF’s settings.

Allows determining if any of these values have changed when the config is reloaded.

wait()[source]

Wait until all servers have completed running.

wait_on_children()[source]
heat.common.wsgi.debug_filter(app, conf, **local_conf)[source]
heat.common.wsgi.get_bind_addr(conf, default_port=None)[source]

Return the host and port to bind to.

heat.common.wsgi.get_socket(conf, default_port)[source]

Bind socket to bind ip:port in conf.

Note: Mostly comes from Swift with a few small changes…

Parameters
  • conf – a cfg.ConfigOpts object

  • default_port – port to bind to if none is specified in conf

Returns

a socket object as returned from socket.listen or ssl.wrap_socket if conf specifies cert_file

heat.common.wsgi.is_json_content_type(request)[source]
heat.common.wsgi.list_opts()[source]
heat.common.wsgi.log_exception(err, exc_info)[source]
heat.common.wsgi.paste_deploy_app(paste_config_file, app_name, conf)[source]

Load a WSGI app from a PasteDeploy configuration.

Use deploy.loadapp() to load the app from the PasteDeploy configuration, ensuring that the supplied ConfigOpts object is passed to the app and filter constructors.

Parameters
  • paste_config_file – a PasteDeploy config file

  • app_name – the name of the app/pipeline to load from the file

  • conf – a ConfigOpts object to supply to the app and its filters

Returns

the WSGI app

heat.common.wsgi.setup_paste_factories(conf)[source]

Set up the generic paste app and filter factories.

Set things up so that:

paste.app_factory = heat.common.wsgi:app_factory

and

paste.filter_factory = heat.common.wsgi:filter_factory

work correctly while loading PasteDeploy configuration.

The app factories are constructed at runtime to allow us to pass a ConfigOpts object to the WSGI classes.

Parameters

conf – a ConfigOpts object

heat.common.wsgi.teardown_paste_factories()[source]

Reverse the effect of setup_paste_factories().

heat.common.wsgi.translate_exception(exc, locale)[source]

Translates all translatable elements of the given exception.