VEXXHOSTDocumentation
Guides

Use the Python client

Install the Budgets Python client, create it from an OpenStack SDK connection, and handle the errors it raises.

The vexxhost-budgetclient package is the Python client for Budgets. It signs in with the same session as the OpenStack SDK, so it works with your existing clouds.yaml.

Before you begin

Set up a clouds.yaml entry or an application credential. See Use OpenStack from Python.

1. Install the client

pip install vexxhost-budgetclient

2. Create the client

import openstack
from budgetclient import Client

conn = openstack.connect(cloud="vexxhost")
budgets = Client("1", session=conn.session)

The client finds Budgets in the service catalog. The other Budgets guides call it budgets.

3. Make a call

Methods take and return dictionaries with the same fields as the API's JSON, so the API reference also describes each call. budgets.budgets manages budgets and budgets.notification_channels manages channels.

for budget in budgets.budgets.list():
    print(budget["name"], budget["amount"], budget["currency"])

4. Handle errors

A failed request raises an exception from budgetclient.exceptions, such as Conflict, TooManyRequests or Unauthorized. The exceptions are also keystoneauth1.exceptions HTTP errors.

AttributeContents
status_codeThe HTTP status.
problemThe API's error document, with title, detail and any field errors.
request_idThe X-Request-ID of the request, for support.
retry_afterSeconds to wait before retrying, on 429 Too Many Requests.
from budgetclient import exceptions

try:
    budgets.budgets.get("c7e1a5b3-9d2f-4e8c-a6b4-1f3d5e7c9a2b")
except exceptions.ClientException as error:
    print(error.status_code, error.request_id, error.problem["detail"])
    raise

Next steps

  • Use budgets in the Python examples of the other Budgets guides.

On this page