The Session is the class that maintains session 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.
The following examples use the example authenticator which takes the token and endpoint as arguments.
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)
Making a basic HTTP GET call:
containers = sess.get('/').json()
The containers variable will contain a list of dict describing the containers.
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)
Create a new object with a transport and authenticator.
Session layer which uses the transport for communication. The authenticator also uses the transport to keep authenticated.
Parameters: |
|
---|
All the other methods of the session accept the following parameters:
Parameters: |
|
---|
Perform an HTTP HEAD request.
Perform an HTTP GET request.
Perform an HTTP POST request.
Perform an HTTP PUT request.
Perform an HTTP DELETE request.
Perform an HTTP PATCH request.
Get list of services from preferences.