OpenStack Client Configuration Library

2.3.0 · maintenance · verified Thu Apr 16

os-client-config is a Python library designed for standardizing OpenStack client configuration. It aggregates configuration data from environment variables (prefixed with `OS_`) and `clouds.yaml` files, providing a consistent interface for OpenStack applications. The current version is 2.3.0. While still maintained, it is largely superseded by `openstacksdk` for new development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `OpenStackConfig` and retrieve the configuration for a named OpenStack cloud. The library automatically looks for configuration in environment variables (`OS_*`) or `clouds.yaml` files located in the current directory, `~/.config/openstack`, or `/etc/openstack`.

import os
from os_client_config import OpenStackConfig

# Configure a cloud either via environment variables (OS_CLOUD, OS_AUTH_URL, etc.)
# or a clouds.yaml file (e.g., in ~/.config/openstack/clouds.yaml)

# Example: Get configuration for a cloud named 'mycloud'
# Ensure OS_CLOUD is set or 'mycloud' is defined in clouds.yaml
cloud_name = os.environ.get('OS_CLOUD', 'mycloud')

try:
    # Initialize the config object
    config = OpenStackConfig()

    # Get the configuration for a specific cloud
    cloud = config.get_one_cloud(cloud_name)

    # Access configuration details
    print(f"Cloud name: {cloud.name}")
    print(f"Region: {cloud.region_name}")
    print(f"Auth URL: {cloud.auth['auth_url']}")

    # Example: Print a few more details (be cautious with sensitive info)
    if 'username' in cloud.auth:
        print(f"Username: {cloud.auth['username']}")
    
except Exception as e:
    print(f"Error getting OpenStack cloud config: {e}")
    print("Please ensure 'OS_CLOUD' environment variable is set or 'clouds.yaml' is configured correctly.")

view raw JSON →