This Page

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

The nova.api.direct Module

Public HTTP interface that allows services to self-register.

The general flow of a request is:
  • Request is parsed into WSGI bits.
  • Some middleware checks authentication.
  • Routing takes place based on the URL to find a controller. (/controller/method)
  • Parameters are parsed from the request and passed to a method on the controller as keyword arguments. - Optionally ‘json’ is decoded to provide all the parameters.
  • Actual work is done and a result is returned.
  • That result is turned into json and returned.
class nova.api.direct.DelegatedAuthMiddleware(application)

Bases: nova.wsgi.Middleware

A simple and naive authentication middleware.

Designed mostly to provide basic support for alternative authentication schemes, this middleware only desires the identity of the user and will generate the appropriate nova.context.RequestContext for the rest of the application. This allows any middleware above it in the stack to authenticate however it would like while only needing to conform to a minimal interface.

Expects two headers to determine identity:
  • X-OpenStack-User
  • X-OpenStack-Project

This middleware is tied to identity management and will need to be kept in sync with any changes to the way identity is dealt with internally.

process_request(request)
class nova.api.direct.JsonParamsMiddleware(application)

Bases: nova.wsgi.Middleware

Middleware to allow method arguments to be passed as serialized JSON.

Accepting arguments as JSON is useful for accepting data that may be more complex than simple primitives.

In this case we accept it as urlencoded data under the key ‘json’ as in json=<urlencoded_json> but this could be extended to accept raw JSON in the POST body.

Filters out the parameters self, context and anything beginning with an underscore.

process_request(request)
class nova.api.direct.Limited(proxy)

Bases: object

class nova.api.direct.PostParamsMiddleware(application)

Bases: nova.wsgi.Middleware

Middleware to allow method arguments to be passed as POST parameters.

Filters out the parameters self, context and anything beginning with an underscore.

process_request(request)
class nova.api.direct.Proxy(app, prefix=None)

Bases: object

Pretend a Direct API endpoint is an object.

This is mostly useful in testing at the moment though it should be easily extendable to provide a basic API library functionality.

In testing we use this to stub out internal objects to verify that results from the API are serializable.

class nova.api.direct.Reflection

Bases: object

Reflection methods to list available methods.

This is an object that expects to be registered via register_service. These methods allow the endpoint to be self-describing. They introspect the exposed methods and provide call signatures and documentation for them allowing quick experimentation.

get_controllers(context)

List available controllers.

get_method_info(context, method)

Get detailed information about a method.

get_methods(context)

List available methods.

class nova.api.direct.Router(mapper=None)

Bases: nova.wsgi.Router

A simple WSGI router configured via register_service.

This is a quick way to attach multiple services to a given endpoint. It will automatically load the routes registered in the ROUTES global.

TODO(termie): provide a paste-deploy version of this.

class nova.api.direct.ServiceWrapper(service_handle)

Bases: object

Wrapper to dynamically povide a WSGI controller for arbitrary objects.

With lightweight introspection allows public methods on the object to be accesed via simple WSGI routing and parameters and serializes the return values.

Automatically used be nova.api.direct.Router to wrap registered instances.

nova.api.direct.register_service(path, handle)

Register a service handle at a given path.

Services registered in this way will be made available to any instances of nova.api.direct.Router.

Parameters:
  • pathroutes path, can be a basic string like “/path”
  • handle – an object whose methods will be made available via the api