python-watcherclient
raw JSON → 4.10.0 verified Fri May 01 auth: no python
Python client library for the OpenStack Watcher (optimization) API. Current version: 4.10.0. Release cadence follows OpenStack releases (approx. every 6 months).
pip install python-watcherclient Common errors
error ModuleNotFoundError: No module named 'watcherclient' ↓
cause Package not installed or wrong import name.
fix
Install with 'pip install python-watcherclient' and import as 'from watcherclient import client'.
error watcherclient.exceptions.Unauthorized: Unauthorized ↓
cause Invalid or missing authentication credentials.
fix
Verify environment variables OS_AUTH_URL, OS_USERNAME, OS_PASSWORD are set correctly.
error TypeError: Client() missing 1 required positional argument: 'version' ↓
cause API version argument omitted.
fix
Call client.Client(1, session=sess) (API version is the first argument).
error ValueError: API version x is not supported ↓
cause Using unsupported API version.
fix
Use version 1 (the only stable version).
Warnings
breaking Version 4.0.0 dropped support for Python < 3.8. Version 4.10.0 requires Python >= 3.10. ↓
fix Upgrade to Python >= 3.10.
deprecated The 'watcherclient.commands' module is deprecated and will be removed in a future release. Use the openstacksdk-based osc-lib plugin instead. ↓
fix Migrate to 'openstack watcher' CLI or use osc-lib plugin.
gotcha Session object must be passed to client constructor; omitting it causes authentication errors. ↓
fix Always create a keystoneauth1 session and pass it to client.Client().
gotcha The API version (e.g., 1) is required as first argument to client.Client(). Missing version raises TypeError. ↓
fix Pass the API version: client.Client(1, session=sess).
Imports
- client wrong
from python_watcherclient import clientcorrectfrom watcherclient import client
Quickstart
from watcherclient import client
from keystoneauth1 import session
from keystoneauth1.identity import v3
auth = v3.Password(auth_url=os.environ.get('OS_AUTH_URL', 'http://localhost:5000/v3'),
username=os.environ.get('OS_USERNAME', 'admin'),
password=os.environ.get('OS_PASSWORD', 'password'),
project_name=os.environ.get('OS_PROJECT_NAME', 'admin'),
user_domain_name=os.environ.get('OS_USER_DOMAIN_NAME', 'Default'))
sess = session.Session(auth=auth)
wc = client.Client(1, session=sess)
print(list(wc.audit.list()))