The interface is a mostly RESTful API. REST stands for Representational State Transfer and provides an architecture “style” for distributed systems using HTTP for transport. Figure out a way to express your request and response in terms of resources that are being created, modified, read, or destroyed.
To map URLs to controllers+actions, OpenStack uses the Routes package, a clone of Rails routes for Python implementations. See http://routes.groovie.org/ for more information.
URLs are mapped to “action” methods on “controller” classes in manila/api/v1/router.py.
Controllers live in manila/api/v1 and manila/api/contrib.
See manila/api/v1/shares.py for an example.
Action methods take parameters that are sucked out of the URL by mapper.connect() or .resource(). The first two parameters are self and the WebOb request, from which you can get the req.environ, req.body, req.headers, etc.
Actions return a dictionary, and wsgi.Controller serializes that to JSON or XML based on the request’s content-type.
If you define a new controller, you’ll need to define a _serialization_metadata attribute on the class, to tell wsgi.Controller how to convert your dictionary to XML. It needs to know the singular form of any list tag (e.g. <shares> list contains <share> tags) and which dictionary keys are to be XML attributes as opposed to subtags (e.g. <share id="4"/> instead of <share><id>4</id></share>).
See manila/api/v1/shares.py for an example.
If you need to return a non-200, you should return faults.Fault(webob.exc.HTTPNotFound()) replacing the exception as appropriate.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.