Move examples to code session docs

Change-Id: If4dcbe6f9cee01dee6d091841f7a1b24b9694e61
This commit is contained in:
Terry Howe
2014-11-01 08:46:04 -06:00
parent 94e83e34a3
commit c00bcf9dc7
2 changed files with 39 additions and 39 deletions

View File

@@ -8,42 +8,3 @@ Session Object
.. autoclass:: openstack.session.Session
:members:
Examples
--------
The following examples use the example authenticator which takes the token
and endpoint as arguments.
Create a session
~~~~~~~~~~~~~~~~
Constructor::
from examples import authenticator
from openstack import session
from openstack import transport
xport = transport.Transport()
token = 'SecretToken'
endpoint = 'http://cloud.example.com:3333'
auther = authenticator.TestAuthenticator(token, endpoint)
sess = session.Session(xport, auther)
HTTP GET
~~~~~~~~
Making a basic HTTP GET call::
containers = sess.get('/').json()
The containers variable will contain a list of dict describing the containers.
HTTP PUT
~~~~~~~~
Creating a new object::
objay_data = 'roland garros'
objay_len = len(objay_data)
headers = {"Content-Length": objay_len, "Content-Type": "text/plain"}
resp = sess.put('/pilots/french.txt', headers=headers, data=objay_data)

View File

@@ -16,6 +16,45 @@ layer similar to the OSI model session layer. The session has a transport
and an authenticator. The transport is used by the session and authenticator
for HTTP layer transport. The authenticator is responsible for providing an
authentication token and an endpoint to communicate with.
Examples
--------
The following examples use the example authenticator which takes the token
and endpoint as arguments.
Create a session
~~~~~~~~~~~~~~~~
Constructor::
from examples import authenticator
from openstack import session
from openstack import transport
xport = transport.Transport()
token = 'SecretToken'
endpoint = 'http://cloud.example.com:3333'
auther = authenticator.TestAuthenticator(token, endpoint)
sess = session.Session(xport, auther)
HTTP GET
~~~~~~~~
Making a basic HTTP GET call::
containers = sess.get('/').json()
The containers variable will contain a list of dict describing the containers.
HTTP PUT
~~~~~~~~
Creating a new object::
objay_data = 'roland garros'
objay_len = len(objay_data)
headers = {"Content-Length": objay_len, "Content-Type": "text/plain"}
resp = sess.put('/pilots/french.txt', headers=headers, data=objay_data)
"""
import logging