SDK for the Azimuth API
Project description
azimuth-sdk
An SDK for interacting with Azimuth resources using Python.
Both synchronous use and asynchronous use, using the async/await
syntax from
asyncio, are supported.
Installation
The Azimuth SDK can be installed from PyPI:
pip install azimuth-sdk
Usage
To begin using the Azimuth SDK, you must first create a configuration object that defines how to authenticate with Azimuth.
Currently, authentication with Azimuth uses OpenStack credentials. Azimuth supports two user-facing authentication methods:
- Username + Password
- Keystone federation
The Keystone federation flow requires a browser, so is not supported by the Azimuth SDK.
Azimuth also supports authenticating with an application credential. This authentication method is usually hidden from browser-based users, but is available for use by the SDK. This is the recommended authentication method.
The SDK Configuration
object can be initialised either using known credentials or from a
clouds.yaml file.
The Azimuth SDK respects the OS_CLOUD
and OS_CLIENT_CONFIG_FILE
environment variables that
the OpenStack CLI supports.
from azimuth_sdk import Configuration
AZIMUTH_URL = "https://portal.azimuth.example.org"
# Initialise from variables
config = Configuration.create(
AZIMUTH_URL,
authenticator = "appcred",
auth_data = {
"application_credential_id": "<application credential id>",
"application_credential_secret": "<application credential secret>",
},
# Optionally set a default tenancy
default_tenancy_id = "<tenancy id>"
)
# Initialise from a specific clouds.yaml file
config = Configuration.from_openstack_cloud_config(
AZIMUTH_URL,
"/path/to/openstack/clouds.yaml"
)
# Initialise from environment variables
config = Configuration.from_environment(AZIMUTH_URL)
Once you have a configuration, it can be used to create a synchronous or an asynchronous client with which you can list the available tenancies:
# Synchronous client
with config.sync_client() as client:
for tenancy in client.tenancies().list():
print(tenancy.name)
# Asynchronous client
async with config.async_client() as client:
async for tenancy in client.tenancies().list():
print(tenancy.name)
You can then interact with resources for a tenancy. For each of these methods, the tenancy_id
is optional - if it is not given, a default tenancy ID will be used. The default tenancy ID
can be set as follows:
- Explicitly when the
Configuration
is created - From
clouds.{cloud}.auth.project_id
in theclouds.yaml
, if present - As the first available tenancy in the tenancy list (may not be deterministic)
The following resources are available:
# Interact with the images for a tenancy
client.images(tenancy_id = None)
# Interact with the sizes for a tenancy
client.sizes(tenancy_id = None)
# Interact with the volumes for a tenancy
client.volumes(tenancy_id = None)
# Interact with the external IPs for a tenancy
client.external_ips(tenancy_id = None)
# Interact with the machines for a tenancy
client.machines(tenancy_id = None)
# Interact with the CaaS cluster types for a tenancy
client.cluster_types(tenancy_id = None)
# Interact with the CaaS clusters for a tenancy
client.clusters(tenancy_id = None)
# Interact with the Kubernetes templates for a tenancy
client.kubernetes_cluster_templates(tenancy_id = None)
# Interact with the Kubernetes clusters for a tenancy
client.kubernetes_clusters(tenancy_id = None)
# Interact with the Kubernetes app templates for a tenancy
client.kubernetes_app_templates(tenancy_id = None)
# Interact with the Kubernetes apps for a tenancy
client.kubernetes_apps(tenancy_id = None)
Each of these returns a Resource
object, which can be interacted with as follows.
NOTE
The sync methods are available on resources produced by synchronous clients (i.e. created using
config.sync_client
), and the async methods on resources produced by asynchronous clients (i.e. created usingconfig.async_client
).
# List instances
# sync
for instance in resource.list():
print(instance)
# async
async for instance in resource.list():
print(instance)
# Get the first instance from a list response
# sync
instance = resource.first()
# async
instance = await resource.first()
# Fetch an instance by ID
# sync
instance = resource.fetch("<id>")
# async
instance = await resource.fetch("<id>")
# Create a new instance
# sync
instance = resource.create({"name": "my-instance", "<prop>": "<value>"})
# async
instance = await resource.create({ "name": "my-instance", "<prop>": "<value>"})
# Replace an instance by ID (PUT request)
# sync
instance = resource.replace("<id>", {"name": "my-instance", "<prop>": "<value>"})
# async
instance = await resource.replace("<id>", {"name": "my-instance", "<prop>": "<value>"})
# Patch an instance by ID (PATCH request)
# sync
instance = resource.patch("<id>", {"<prop>": "<value>"})
# async
instance = await resource.patch("<id>", {"<prop>": "<value>"})
# Replace an instance by ID, or create it (using the same data) if it doesn't exist
# sync
instance = resource.create_or_replace("<id>", {"name": "my-instance", "<prop>": "<value>"})
# async
instance = await resource.create_or_replace("<id>", {"name": "my-instance", "<prop>": "<value>"})
# Patch an instance by ID, or create it (using the same data) if it doesn't exist
# sync
instance = resource.create_or_patch("<id>", {"<prop>": "<value>"})
# async
instance = await resource.create_or_patch("<id>", {"<prop>": "<value>"})
# Delete an instance by ID
# sync
instance = resource.delete("<id>")
# async
instance = await resource.delete("<id>")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for azimuth_sdk-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc9d8852a3b9a7e3fc343883bb043e48798117401355c71f61cf706becf8d6b3 |
|
MD5 | 1d2f1201b76dba94e6c94b9bbcc79e0a |
|
BLAKE2b-256 | 5dcb9c0ea3beb65e3d11799a0f749f627f6b29e47016dd503d3d3bbe29193fcc |