{"id":6209,"library":"python-novaclient","title":"OpenStack Compute (Nova) Client","description":"python-novaclient is a client library for the OpenStack Compute (Nova) API, enabling Python applications to programmatically interact with OpenStack's compute resources. It provides a comprehensive Python API (the `novaclient` module) to manage virtual servers, images, flavors, and other Nova-related services. This library is actively developed as part of the OpenStack ecosystem, with releases typically synchronized with OpenStack major versions, and the current version is 18.12.0.","status":"active","version":"18.12.0","language":"en","source_language":"en","source_url":"https://github.com/openstack/python-novaclient","tags":["openstack","nova","cloud","compute","api-client","infrastructure"],"install":[{"cmd":"pip install python-novaclient","lang":"bash","label":"Latest stable version"}],"dependencies":[{"reason":"Recommended for robust authentication against OpenStack Identity (Keystone) services, especially with Keystone v3. While not a direct `install_requires` for `python-novaclient`, it's a critical operational dependency for most real-world usage.","package":"keystoneauth1"}],"imports":[{"note":"The recommended top-level entry point is `novaclient.client.Client`. Directly importing from `novaclient.v2.client` is discouraged by documentation, as the main `client.Client` handles versioning.","wrong":"from novaclient.v2.client import Client","symbol":"Client","correct":"from novaclient import client\nnova_client = client.Client(api_version='2.latest', ...)"}],"quickstart":{"code":"import os\nfrom novaclient import client\n\n# OpenStack credentials (often sourced from an 'openrc' file)\nOS_USERNAME = os.environ.get('OS_USERNAME', 'your_username')\nOS_PASSWORD = os.environ.get('OS_PASSWORD', 'your_password')\nOS_PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'your_project_name')\nOS_AUTH_URL = os.environ.get('OS_AUTH_URL', 'http://your_keystone_ip:5000/v3')\nOS_REGION_NAME = os.environ.get('OS_REGION_NAME', 'RegionOne')\nOS_USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'Default')\nOS_PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')\n\n# Initialize the Nova client\n# For robust authentication, consider using keystoneauth1.session.Session\n# and passing it to the client for 'session' parameter.\n# Example: from keystoneauth1.identity import v3; from keystoneauth1 import session\n# auth = v3.Password(auth_url=OS_AUTH_URL, username=OS_USERNAME, ...)\n# sess = session.Session(auth=auth)\n# nova = client.Client(api_version='2.latest', session=sess, region_name=OS_REGION_NAME)\n\n# Using direct parameters for simplicity in quickstart, but keystoneauth1 is better for production\nnova = client.Client(\n    api_version='2.latest',\n    username=OS_USERNAME,\n    password=OS_PASSWORD,\n    project_name=OS_PROJECT_NAME,\n    auth_url=OS_AUTH_URL,\n    region_name=OS_REGION_NAME,\n    user_domain_name=OS_USER_DOMAIN_NAME,\n    project_domain_name=OS_PROJECT_DOMAIN_NAME\n)\n\n# List available flavors (instance types)\ntry:\n    flavors = nova.flavors.list()\n    print(f\"Available Flavors ({len(flavors)}):\")\n    for flavor in flavors:\n        print(f\"  - {flavor.name} (ID: {flavor.id}, RAM: {flavor.ram}MB, VCPUs: {flavor.vcpus})\")\n\n    # List available servers\n    servers = nova.servers.list()\n    print(f\"\\nRunning Servers ({len(servers)}):\")\n    if not servers:\n        print(\"  No servers found.\")\n    for server in servers:\n        print(f\"  - {server.name} (ID: {server.id}, Status: {server.status})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your OpenStack credentials (environment variables) are correctly set.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the Nova client and perform basic operations like listing available compute flavors and running servers. It uses environment variables for authentication, which is a common practice in OpenStack CLI tools and scripts. For production applications, using `keystoneauth1.session.Session` is the recommended and more robust authentication method."},"warnings":[{"fix":"Migrate command-line usage to `openstackclient` or write Python scripts using the `novaclient` API.","message":"The `nova` command-line script, which is installed alongside `python-novaclient`, is deprecated. Users are encouraged to use the Python API directly or the unified `openstackclient` for command-line interactions.","severity":"deprecated","affected_versions":"All recent versions"},{"fix":"Utilize the `keystoneauth1` library to manage authentication sessions (`keystoneauth1.identity.v3.Password` or similar) and pass the `session` object to `novaclient.client.Client`. This provides a more robust and flexible authentication mechanism.","message":"OpenStack authentication, especially with Keystone v3, can be complex due to varying required parameters (e.g., domain IDs/names). Directly passing credentials to `novaclient.client.Client` can be brittle.","severity":"gotcha","affected_versions":"All versions supporting Keystone v3 (typically Nova API v2.0 and newer)."},{"fix":"Be explicit about the `api_version` when initializing the client (e.g., `api_version='2.latest'` or a specific version like `'2.94'`). Consult the Nova API Reference for microversion-specific changes and capabilities. Code should ideally handle expected microversion ranges or capabilities.","message":"OpenStack Nova API extensively uses microversions to introduce new features and changes without incrementing the major API version (e.g., API v2.0 has many microversions like 2.53, 2.94). Client behavior can differ significantly based on the microversion negotiated or specified.","severity":"gotcha","affected_versions":"All versions supporting Nova API v2.0+."},{"fix":"Avoid using these x509 certificate management features within the Nova client. Look for alternative OpenStack services or direct API interactions if certificate management is required.","message":"The `nova x509-create-cert` and `nova x509-get-root-cert` commands and the `novaclient.v2.certs` API binding are deprecated and scheduled for removal in future major releases after Nova server 16.0.","severity":"deprecated","affected_versions":"Pike series (9.x) onwards."}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}