Assisted Service Client
The `assisted-service-client` is the official Python client library for interacting with the OpenShift Assisted Installer service. It provides a programmatic interface to deploy and manage OpenShift clusters using the Assisted Service API. The library is actively maintained and frequently updated, with versions typically aligning with the development cycle of the Assisted Service itself, meaning it receives regular, often patch-like, releases to keep pace with API evolution. The current version is `2.52.0.post11`.
Common errors
-
assisted_service_client.ApiException: (401) Reason: Unauthorized
cause The API request was made without a valid or unexpired authentication token, or the provided token does not have sufficient permissions.fixEnsure the `Configuration` object's `access_token` parameter is set with a valid, active authentication token (e.g., an OpenShift pull secret or a generated API key). Example: `Configuration(access_token='your_actual_token')`. -
requests.exceptions.ConnectionError: HTTPSConnectionPool(...) Max retries exceeded with url: ...
cause The Python client could not establish a connection to the specified `host` URL, often due to an incorrect URL, network issues, DNS problems, or the Assisted Service being down/inaccessible.fixVerify that the `host` parameter in `assisted_service_client.Configuration` points to the correct and reachable URL of the Assisted Service. Check network connectivity from your client to the service endpoint and ensure no firewalls are blocking access. -
AttributeError: 'Cluster' object has no attribute 'new_field'
cause Your `assisted-service-client` library version is older than the Assisted Service instance it's interacting with. The service API has introduced new fields or methods that your client's data models or API classes do not yet recognize.fixUpgrade your `assisted-service-client` package to the latest available version using `pip install --upgrade assisted-service-client`. This ensures your client models and API definitions are synchronized with the most recent service API.
Warnings
- breaking As a generated client, API method signatures and data models can change significantly between `assisted-service-client` versions, especially following updates to the underlying Assisted Service API. Mismatches between client and service versions can lead to `AttributeError` for missing fields/methods or `ApiException` due to invalid requests/responses.
- gotcha The client requires proper authentication, typically via an `access_token`. Incorrect, expired, or missing tokens will result in `ApiException` with a 401 Unauthorized status.
- gotcha Providing an incorrect `host` URL in the `Configuration` can lead to connection errors (`requests.exceptions.ConnectionError`) if the service is unreachable, or `ApiException` (e.g., 404 Not Found) if the base path is wrong or the endpoint does not exist.
Install
-
pip install assisted-service-client
Imports
- ApiClient
from assisted_service_client import ApiClient
- Configuration
from assisted_service_client import Configuration
- InstallerApi
from assisted_service_client.api.installer_api import InstallerApi
- ApiException
from assisted_service_client import ApiException
Quickstart
import assisted_service_client
import os
# Configure API client with host and authentication token
# In a production environment, these should come from secure sources (e.g., environment variables, secrets manager)
configuration = assisted_service_client.Configuration(
host=os.environ.get("ASSISTED_SERVICE_URL", "http://localhost:8090/api/assisted-install/v2"),
access_token=os.environ.get("ASSISTED_SERVICE_TOKEN", "") # Replace with your actual token
)
# Create an API client instance
api_client = assisted_service_client.ApiClient(configuration)
try:
# Instantiate a specific API (e.g., InstallerApi for cluster management)
installer_api = assisted_service_client.api.installer_api.InstallerApi(api_client)
# Example: List all clusters
clusters = installer_api.list_clusters()
print(f"Successfully retrieved {len(clusters)} clusters.")
for cluster in clusters:
print(f"- Cluster ID: {cluster.id}, Name: {cluster.name}, Status: {cluster.status}")
except assisted_service_client.ApiException as e:
print(f"API Error: {e.status} - {e.reason}\nBody: {e.body}")
if e.status == 401:
print("Authentication failed. Please check your ASSISTED_SERVICE_TOKEN.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
# Close the API client when done to release resources
api_client.close()