OpenStack Heat Orchestration API Client Library

5.1.0 · active · verified Thu Apr 16

The `python-heatclient` library provides a Python API and a command-line interface for interacting with the OpenStack Heat orchestration service. It allows users to programmatically manage Heat stacks, which orchestrate complex cloud applications using templates. The library is actively maintained as part of the OpenStack project, with its current version being 5.1.0, requiring Python >=3.10.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with OpenStack Keystone and then initialize the Heat client to list existing Heat stacks. It uses the `keystoneauth1` library for robust authentication, which is essential for interacting with OpenStack services. Replace placeholder credentials with your actual OpenStack environment details.

import os
from keystoneauth1 import loading
from keystoneauth1.session import Session
from heatclient import client as heat_client

# --- Authentication --- (replace with your OpenStack credentials or environment variables)
# For production, consider using environment variables (OS_AUTH_URL, OS_USERNAME, etc.)
# and 'keystoneauth1.loading.load_auth_from_options' or 'load_from_env'.
# For simplicity, using hardcoded values for quickstart, but highly discouraged in production.

AUTH_URL = os.environ.get('OS_AUTH_URL', 'http://your-openstack-ip/identity/v3')
USERNAME = os.environ.get('OS_USERNAME', 'admin')
PASSWORD = os.environ.get('OS_PASSWORD', 'your-password')
PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'admin')
USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'Default')
PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')

# Load the password authentication plugin
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(
    auth_url=AUTH_URL,
    username=USERNAME,
    password=PASSWORD,
    project_name=PROJECT_NAME,
    user_domain_name=USER_DOMAIN_NAME,
    project_domain_name=PROJECT_DOMAIN_NAME
)

# Create a Keystone session
sess = Session(auth=auth)

# Create a Heat client
# API version '1' is commonly used. 'public' endpoint type is standard.
heat_client_instance = heat_client.Client(
    '1', 
    session=sess, 
    endpoint_type='public',
    service_type='orchestration'
)

# --- Example Usage: List Stacks ---
try:
    print('Listing Heat stacks:')
    for stack in heat_client_instance.stacks.list():
        print(f"  - Name: {stack.stack_name}, Status: {stack.stack_status}, ID: {stack.id}")
except Exception as e:
    print(f"Error listing stacks: {e}")

view raw JSON →