In order to work with an OpenStack cloud you first need to create a
Connection
to it using your credentials. A
Connection
can be
created in 3 ways, using the class itself, a file, or environment variables.
If this is your first time using the SDK, we recommend simply using the
class itself as illustrated below.
To create a connection you need a Profile
and a
Connection
.
def create_connection(auth_url, region, project_name, username, password):
prof = profile.Profile()
prof.set_region(profile.Profile.ALL, region)
return connection.Connection(
profile=prof,
user_agent='examples',
auth_url=auth_url,
project_name=project_name,
username=username,
password=password
)
The Profile
sets your preferences for each
service. You will pass it the region of the OpenStack cloud that this
connection will use.
The Connection
is a context for a connection
to an OpenStack cloud. You will primarily use it to set the
Profile
and authentication information. You can
also set the user_agent
to something that describes your application
(e.g. my-web-app/1.3.4
).
Full example at connect.py
Note
To enable logging, see the Logging user guide.
Now that you can create a connection, continue with the User Guides to work with an OpenStack service.
As an alternative to creating a Connection
using the class itself, you can connect using a file or environment
variables. See the Connect From Config user guide.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.