~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to doc/source/devref/addmethod.openstackapi.rst

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-01-21 11:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110121114806-v8fvnnl6az4m4ohv
Tags: upstream-2011.1~bzr597
ImportĀ upstreamĀ versionĀ 2011.1~bzr597

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
..
2
 
      Copyright 2010 OpenStack LLC 
 
2
      Copyright 2010-2011 OpenStack LLC 
3
3
      All Rights Reserved.
4
4
 
5
5
      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.
50
50
 
51
51
Faults
52
52
------