This change allows the from_config factory function to better support two angles from which it will most commonly be used. 1. When SDK is being used from within OSC, OSC will have obtained configuration data from OCC and is better served by passing it directly into SDK rather than SDK additionally accessing that data. 2. Direct users of the SDK, such as customer applications, are less likely to have dealt directly with OCC and are better served by just passing in the name of the configuration they want to run with. Closes-Bug:1513920 Change-Id: I06f871b822e4b8b0cc8cc8db9e7ccff91f918e5a
2.3 KiB
Connect From Config
In order to work with an OpenStack cloud you first need to create a
~openstack.connection.Connection to it using your
credentials. A ~openstack.connection.Connection can be created in 3
ways, using the class itself (see connect), a file, or environment variables as
illustrated below. The SDK uses os-client-config
to handle the configuration.
Note
To get your credentials Download the OpenStack RC file.
Create Connection From A File
Default Location
To create a connection from a file you need a YAML file to contain the configuration.
../../contributors/clouds.yaml
To use a configuration file called clouds.yaml in one of
the default locations:
- Current Directory
- ~/.config/openstack
- /etc/openstack
call :py~openstack.connection.from_config. The
from_config function takes three optional arguments, such
as cloud_name, which allows you to specify one set of
cloud credentials in your clouds.yaml file. Additionally,
cloud_config and options allow you to
pass in configiration data you may have already received from
os-client-config, as well as additional options that the
os-client-config library may need.
../examples/connect.py
../examples/connect.py
Note
To enable logging, set debug=True in the
Opts object.
User Defined Location
To use a configuration file in a user defined location set the
environment variable OS_CLIENT_CONFIG_FILE to the absolute
path of a file.:
export OS_CLIENT_CONFIG_FILE=/path/to/my/config/my-clouds.yaml
and call :py~openstack.connection.from_config with the
cloud_name of the cloud configuration to use, .
Next
Now that you can create a connection, continue with the user_guides for an OpenStack
service.