Connection

The Connection class is the primary interface to the Python SDK it maintains a context for a connection to a cloud provider. The connection has an attribute to access each supported service. The service attributes are created dynamically based on user preferences and the service catalog.

Examples

At a minimum, the Connection class needs to be created with an authenticator or the parameters to build one.

Create a connection

The following example constructor uses the identity authenticator using username and password. The default settings for the transport are used by this connection.:

from openstack import connection
auth_args = {
    'auth_url': 'http://172.20.1.108:5000/v3',
    'project_name': 'admin',
    'user_name': 'admin',
    'password': 'admin',
}
conn = connection.Connection(**auth_args)

List

Services are accessed through an attribute named after the service. A list of all the projects is retrieved in this manner:

projects = conn.identity.list_projects()

Find or create

If you wanted to make sure you had a network named ‘jenkins’, you would first try to find it and if that fails, you would create it:

network = conn.network.find_network("jenkins")
if network is None:
    network = conn.network.create_network({"name": "jenkins"})

Connection Object

class openstack.connection.Connection(transport=None, authenticator=None, preference=None, verify=True, user_agent=None, auth_plugin=None, **auth_args)

Create a context for a connection to a cloud provider.

A connection needs a transport and an authenticator. The user may pass in a transport and authenticator they want to use or they may pass in the parameters to create a transport and authenticator. The connection creates a Session which uses the transport and authenticator to perform HTTP requests.

Parameters:
  • transport (Transport) – A transport object such as that was previously created. If this parameter is not passed in, the connection will create a transport.
  • authenticator (BaseAuthPlugin) – An authenticator derived from the base authenticator plugin that was previously created. Two common authentication identity plugins are identity_v2 and identity_v3. If this parameter is not passed in, the connection will create an authenticator.
  • 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.
  • verify (bool) – If a transport is not provided to the connection, this parameter will be used to create a transport. If verify is set to true, which is the default, the SSL cert will be verified. It can also be set to a CA_BUNDLE path.
  • user_agent (str) – If a transport is not provided to the connection, this parameter will be used when creating a transport. The value given here will be prepended to the default, which is specified in USER_AGENT. The resulting user_agent value is used for the User-Agent HTTP header.
  • auth_plugin (str) – The name of authentication plugin to use. If the authentication plugin name is not provided, the connection will try to guess what plugin to use based on the auth_url in the auth_args. Two common values for the plugin would be identity_v2 and identity_v3.
  • auth_args – The rest of the parameters provided are assumed to be authentication arguments that are used by the authentication plugin.
create(obj)

Create an object.

Parameters:obj – A resource object.
get(obj, include_headers=False)

Get an object.

Parameters:
  • obj – A resource object.
  • include_headers (bool) – Read object headers.
head(obj)

Get an object.

Parameters:obj – A resource object.
update(obj)

Update an object.

Parameters:obj – A resource object.
delete(obj)

Delete an object.

Parameters:obj – A resource object.

Table Of Contents

Previous topic

Using the OpenStack Object Store API

Next topic

UserPreference

This Page