Session

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.

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)

Session Object

class openstack.session.Session(transport, authenticator, preference=None)

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:
  • transport (Transport) – A transport that provides an HTTP request method. The transport is also to be used by the authenticator, if needed.
  • authenticator (BaseAuthPlugin) – An authenticator that provides get_token and get_endpoint methods for the session.
  • preference (UserPreference) – If the user has any special preferences such as the service name, region, version or visibility, they may be provided in the preference object. If no preferences are provided, the services that appear first in the service catalog will be used.

All the other methods of the session accept the following parameters:

Parameters:
  • path (str) – Path relative to service base url.
  • service (ServiceFilter) – a service filter for the authenticator to determine the correct endpoint to use.
  • authenticate (bool) – A flag that indicates if a token should be attached to the request. This parameter defaults to true.
  • kwargs – The remaining arguments are passed to the transport request method.
head(path, **kwargs)

Perform an HTTP HEAD request.

get(path, **kwargs)

Perform an HTTP GET request.

post(path, **kwargs)

Perform an HTTP POST request.

put(path, **kwargs)

Perform an HTTP PUT request.

delete(path, **kwargs)

Perform an HTTP DELETE request.

patch(path, **kwargs)

Perform an HTTP PATCH request.

get_services()

Get list of services from preferences.

Table Of Contents

Previous topic

openstack.object_store.v1.obj

Next topic

Transport

This Page