{"id":10167,"library":"python-octaviaclient","title":"Octavia Client for OpenStack Load Balancing","description":"The `python-octaviaclient` library provides a client for interacting with the OpenStack Octavia Load Balancing service API (primarily v2). It allows users to programmatically manage load balancers, listeners, pools, members, and health monitors within an OpenStack environment. The current version is 3.13.0, and releases generally follow OpenStack development cycles, with patch releases occurring as needed.","status":"active","version":"3.13.0","language":"en","source_language":"en","source_url":"https://opendev.org/openstack/python-octaviaclient","tags":["openstack","octavia","load-balancing","cloud","api-client","keystone"],"install":[{"cmd":"pip install python-octaviaclient","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for authentication with OpenStack Keystone.","package":"keystoneauth1","optional":false}],"imports":[{"note":"The client class is specific to API version 2, so it's located under the `v2` module.","wrong":"from octaviaclient.client import Client","symbol":"Client","correct":"from octaviaclient.v2.client import Client"},{"note":"Required for authentication; not directly part of octaviaclient but essential for its usage.","symbol":"Session","correct":"from keystoneauth1.session import Session"},{"note":"Required for authenticating API requests with Keystone; not directly part of octaviaclient but essential for its usage.","symbol":"Adapter","correct":"from keystoneauth1.adapter import Adapter"}],"quickstart":{"code":"import os\nfrom keystoneauth1.identity import v3\nfrom keystoneauth1.session import Session\nfrom keystoneauth1.adapter import Adapter\nfrom octaviaclient.v2.client import Client\n\n# Set OpenStack authentication environment variables (e.g., OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, etc.)\n# Or directly provide credentials\n\nauth = v3.Password(\n    auth_url=os.environ.get('OS_AUTH_URL', 'http://localhost:5000/v3'),\n    username=os.environ.get('OS_USERNAME', 'admin'),\n    password=os.environ.get('OS_PASSWORD', 'password'),\n    project_name=os.environ.get('OS_PROJECT_NAME', 'admin'),\n    user_domain_name=os.environ.get('OS_USER_DOMAIN_NAME', 'Default'),\n    project_domain_name=os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')\n)\nsess = Session(auth=auth)\n\n# Create an Octavia client adapter\noctavia_client = Client(\n    session=sess,\n    region_name=os.environ.get('OS_REGION_NAME', None),\n    service_type='load-balancer',\n    interface='public'\n)\n\ntry:\n    # Example: List all load balancers\n    load_balancers = octavia_client.loadbalancer.list()\n    print(f\"Found {len(load_balancers)} load balancers:\")\n    for lb in load_balancers:\n        print(f\"  - ID: {lb['id']}, Name: {lb['name']}, Provisioning Status: {lb['provisioning_status']}\")\nexcept Exception as e:\n    print(f\"Error connecting to Octavia or listing load balancers: {e}\")\n    print(\"Please ensure your OpenStack environment variables are correctly set.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the Octavia client using Keystone v3 authentication, retrieve an authenticated session, and then list existing load balancers. It relies on standard OpenStack environment variables for credentials. Ensure these are set or replace `os.environ.get` calls with your specific values."},"warnings":[{"fix":"Ensure `pip install keystoneauth1` is run and that OpenStack environment variables (e.g., `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, `OS_PROJECT_NAME`, etc.) are correctly set or provided programmatically.","message":"Authentication requires `keystoneauth1`. Users commonly forget to install it or configure it correctly, leading to authentication errors or `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the Octavia service endpoint configured in your OpenStack environment (or passed to the client) corresponds to API v2, typically `/v2.0` suffix. The client's imports explicitly use `v2`.","message":"The client is designed for Octavia API v2. Direct support for any hypothetical Octavia API v1 is not present in this client. Attempting to use older API versions or endpoints will result in errors.","severity":"breaking","affected_versions":"All 3.x versions"},{"fix":"Always access resource properties using dictionary syntax, e.g., `load_balancer['id']` or `load_balancer['name']`. If you prefer object-like access, consider wrapping the dictionaries in a custom class or using `openstacksdk` which provides object abstractions.","message":"The client methods return dictionaries (or lists of dictionaries) representing API resources, not custom object classes. This means direct attribute access (e.g., `lb.name`) will not work; dictionary key access (e.g., `lb['name']`) is required.","severity":"gotcha","affected_versions":"All 3.x versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"The `Client` class is specific to API v2. Use `from octaviaclient.v2.client import Client`.","cause":"Attempting to import the client from an incorrect or non-existent path.","error":"ImportError: cannot import name 'Client' from 'octaviaclient.client'"},{"fix":"Verify that `OS_AUTH_URL`, `OS_USERNAME`, `OS_PASSWORD`, `OS_PROJECT_NAME`, `OS_USER_DOMAIN_NAME`, and `OS_PROJECT_DOMAIN_NAME` are correctly set as environment variables or passed directly to the `keystoneauth1.identity.v3.Password` constructor.","cause":"Incorrect or missing OpenStack authentication credentials (e.g., environment variables) or an unreachable Keystone endpoint.","error":"HTTP 401 Unauthorized: The request you have made requires authentication."},{"fix":"Check your OpenStack service catalog (`openstack catalog show`) to confirm the availability of 'load-balancer' service in your target `region_name`. Ensure `service_type` is 'load-balancer' and `interface` is appropriate (e.g., 'public', 'admin', 'internal').","cause":"The Octavia (load-balancer) service is not available in the specified region, or the service type/interface is incorrect.","error":"keystoneauth1.exceptions.catalog.EndpointNotFound: Could not find service endpoint for type 'load-balancer' in region 'RegionOne'."}]}