Connect From Config

Connect From Config

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 (see Connect), a file, or environment variables as illustrated below. The SDK uses os-client-config to handle the configuration.

Create Connection From A File

Default Location

To create a connection from a file you need a YAML file to contain the configuration.

    region_name: RegionOne
      username: demo
      password: secrete
      project_name: demo
      image_name: fedora-20.x86_64
      flavor_name: m1.small
      network_name: private
    cloud: rackspace
      username: joe
      password: joes-password
      project_name: 123123
    region_name: IAD

To use a configuration file called clouds.yaml in one of the default locations:

  • Current Directory
  • ~/.config/openstack
  • /etc/openstack

call from_config(). The from_config function takes three optional arguments:

  • cloud_name allows you to specify a cloud from your clouds.yaml file.
  • cloud_config allows you to pass in an existing os_client_config.config.OpenStackConfig` object.
  • options allows you to specify a namespace object with options to be added to the cloud config.
class Opts(object):
    def __init__(self, cloud_name='devstack-admin', debug=False): = cloud_name
        self.debug = debug
        # Use identity v3 API for examples.
        self.identity_api_version = '3'
def create_connection_from_config():
    opts = Opts(cloud_name=TEST_CLOUD)
    occ = os_client_config.OpenStackConfig()
    cloud = occ.get_one_cloud(
    return connection.from_config(cloud_config=cloud, options=opts)
def create_connection_from_args():
    parser = argparse.ArgumentParser()
    config = os_client_config.OpenStackConfig()
    config.register_argparse_arguments(parser, sys.argv[1:])
    args = parser.parse_args()
    return connection.from_config(options=args)


To enable logging, set debug=True in the options 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 from_config() with the cloud_name of the cloud configuration to use, .

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.