Licensed under the Apache License, Version 2.0 (the "License"); you may
24
24
25
25
To map URLs to controllers+actions, OpenStack uses the Routes package, a clone of Rails routes for Python implementations. See http://routes.groovie.org/ fore more information.
26
26
27
URLs are mapped to "action" methods on "controller" classes in nova/api/openstack/__init__/ApiRouter.__init__ .
27
URLs are mapped to "action" methods on "controller" classes in `nova/api/openstack/__init__/ApiRouter.__init__` .
28
28
29
29
See http://routes.groovie.org/manual.html for all syntax, but you'll probably just need these two:
30
30
- mapper.connect() lets you map a single URL to a single action on a controller.
33
33
Controllers and actions
34
34
-----------------------
35
35
36
Controllers live in nova/api/openstack, and inherit from nova.wsgi.Controller.
36
Controllers live in `nova/api/openstack`, and inherit from nova.wsgi.Controller.
37
37
38
See nova/api/openstack/servers.py for an example.
38
See `nova/api/openstack/servers.py` for an example.
39
39
40
40
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.
41
41
46
46
47
47
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. <servers> list contains <server> tags) and which dictionary keys are to be XML attributes as opposed to subtags (e.g. <server id="4"/> instead of <server><id>4</id></server>).
48
48
49
See nova/api/openstack/servers.py for an example.
49
See `nova/api/openstack/servers.py` for an example.