OpenStack Ironic Client Library
python-ironicclient is the official Python client library for the OpenStack Ironic API, which provides bare metal provisioning services. It offers a Python API for programmatic interaction and integrates with the `openstack baremetal` command-line interface. The current stable version is 6.0.0, actively maintained within the OpenStack project, with releases generally aligned with the OpenStack release cycle (typically every six months).
Common errors
-
ironicclient.exc.HTTPClientError: Error contacting Ironic server: Connection refused
cause The Ironic API endpoint specified in `ironic_url` is unreachable, either due to an incorrect URL/port, network configuration (firewall), or the Ironic API service not running.fixVerify the `ironic_url` (default port is 6385) is correct and that the Ironic API service is running and accessible from where the client is executed. Check firewall rules and network routes. -
keystoneauth1.exceptions.catalog.EndpointNotFound: Could not find endpoint for service 'baremetal' in region 'RegionOne'.
cause The OpenStack service catalog, usually retrieved via Keystone, does not contain an entry for the Ironic (baremetal) service, or the specified region is incorrect.fixEnsure the Ironic service is registered in Keystone and its endpoint is correctly configured. Verify the `region_name` if explicitly provided, or ensure the default region is correct for your OpenStack deployment. -
AttributeError: 'ClientManager' object has no attribute 'node'
cause This usually indicates an issue with the API version or an internal client error where the expected resource manager (e.g., `node`) is not available or has changed its access path.fixEnsure you are initializing the client with a supported API version, e.g., `client.get_client(1, **kwargs)`. Consult Ironic API documentation for the correct microversion usage if needed.
Warnings
- deprecated The standalone `ironic` command-line interface (CLI) is largely superseded by the unified `openstack baremetal` commands available through `python-openstackclient`.
- gotcha The `python-ironic-inspector-client` library is no longer maintained. Its functionality for hardware introspection has been integrated directly into Ironic itself.
- gotcha Ironic client initialization requires both `os_auth_token` and `ironic_url`. Forgetting either, or providing incorrect values, will lead to authentication or connection errors.
Install
-
pip install python-ironicclient -
pip install python-ironicclient[cli]
Imports
- client
from ironicclient.v1 import client
from ironicclient import client
Quickstart
import os
from ironicclient import client
# Configure with actual Ironic API endpoint and Keystone authentication token
IRONIC_URL = os.environ.get('IRONIC_URL', 'http://localhost:6385/')
OS_AUTH_TOKEN = os.environ.get('OS_AUTH_TOKEN', 'YOUR_AUTH_TOKEN_HERE')
if not OS_AUTH_TOKEN or 'YOUR_AUTH_TOKEN_HERE' in OS_AUTH_TOKEN:
print("Warning: OS_AUTH_TOKEN not set or is a placeholder. API calls may fail.")
kwargs = {
'os_auth_token': OS_AUTH_TOKEN,
'ironic_url': IRONIC_URL
}
try:
# API version 1 is common, newer microversions can be specified if needed
ironic = client.get_client(1, **kwargs)
nodes = ironic.node.list()
print(f"Successfully connected to Ironic. Found {len(nodes)} nodes.")
for node in nodes:
print(f" - Node UUID: {node.uuid}, Name: {node.name}")
except Exception as e:
print(f"Error connecting to Ironic or listing nodes: {e}")
print("Please ensure IRONIC_URL and OS_AUTH_TOKEN are correctly configured and Ironic API is reachable.")