Files
training-guides/sources/cinder/addmethod.openstackapi.xml
Sean Roberts e7a49d397d changes the trunk location for the training guides
was incorrectly placed in trunk/training-guide non-plural, now trunk/training-guides.
also add redirect from trunk/openstack-training and trunk/training-guide to the
new location.

Change-Id: I0648a9604dc6a1d6c7480a90c07871608a8752ca
Closes-Bug: #1255684
2013-11-27 14:41:18 -08:00

65 lines
3.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<section xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="5.0"
xml:id="addmethod.openstackapi">
<title>Addmethod.Openstackapi</title>
<section xml:id="header">
<title>Header</title>
<para>
..
Copyright 2010-2011 OpenStack Foundation
All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
</para>
</section>
<section xml:id="Adding-a-Method-to-the-OpenStack-API">
<title>Adding-A-Method-To-The-Openstack-Api</title>
<para>
====================================
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.
</para>
</section>
<section xml:id="Routing">
<title>Routing</title>
<para>
-------
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 ``cinder/api/openstack/__init__/ApiRouter.__init__`` .
See http://routes.groovie.org/manual.html for all syntax, but you'll probably just need these two:
- mapper.connect() lets you map a single URL to a single action on a controller.
- mapper.resource() connects many standard URLs to actions on a controller.
</para>
</section>
<section xml:id="Controllers-and-actions">
<title>Controllers-And-Actions</title>
<para>
-----------------------
Controllers live in ``cinder/api/openstack``, and inherit from cinder.wsgi.Controller.
See ``cinder/api/openstack/servers.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.
</para>
</section>
<section xml:id="Serialization">
<title>Serialization</title>
<para>
-------------
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. ``[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]``).
See `cinder/api/openstack/servers.py` for an example.
Faults
------
If you need to return a non-200, you should
return faults.Fault(webob.exc.HTTPNotFound())
</para>
</section>
</section>